almost there

zmiguel
José Valdiviesso 3 years ago
parent 5c7498b3ec
commit afaed51e6d
  1. 9
      api/Controllers/EventLocsVisitedController.cs
  2. 56
      api/Controllers/TeamsController.cs
  3. 21
      api/Data/EventLocsVisitedRepository.cs
  4. 3
      api/Data/IEventLocsVisitedRepository.cs
  5. 4
      api/Data/ITeamsRepository.cs
  6. 27
      api/Data/TeamsReposiroty.cs
  7. 16
      api/Dtos/TeamAddMember.cs
  8. 19
      api/Dtos/TeamForAdd.cs
  9. 450
      api/Migrations/20190306210633_team_fix.Designer.cs
  10. 22
      api/Migrations/20190306210633_team_fix.cs
  11. 2
      api/Migrations/DataContextModelSnapshot.cs
  12. 2
      api/Models/Team.cs

@ -51,5 +51,14 @@ namespace api.Controllers
return Ok(Locs);
}
// GET api/EventLocsVisited/e/[id]
//All locs visited by event id
[HttpGet("e/{id}")]
public async Task<IActionResult> GetEventLocsVisitedEvent(int id)
{
var Locs = await _repo.GetEventLocsVisitedEvent(id);
return Ok(Locs);
}
}
}

@ -50,5 +50,61 @@ namespace api.Controllers
var Teams = await _repo.GetEventTeam(id);
return Ok(Teams);
}
// GET api/teams/e/[id]
// GET all teams for event id
[HttpGet("u/{QR}")]
public async Task<IActionResult> GetTeamsUser(String QR)
{
var Teams = await _repo.GetUserTeam(QR);
return Ok(Teams);
}
// POST api/teams/add
// create team
[HttpPost("add")]
public async Task<IActionResult> CreateTeam(TeamForAdd TeamAddDetails)
{
User tCap = await context.Users.FirstOrDefaultAsync(u=>u.QRcode == TeamAddDetails.capQR);
List<User> memb = new List<User>();
memb.Add(tCap);
Team tAdd = new Team{EventId = TeamAddDetails.EventId, Nome = TeamAddDetails.Nome, Cap = tCap, Membros = memb, NMembros = 1, Pontos = 0};
await context.Teams.AddAsync(tAdd);
var result = context.SaveChanges();
if (result == 1)
{
return StatusCode(201);
}
return BadRequest();
}
// POST api/teams/add/member
// create team
[HttpPost("add/member")]
public async Task<IActionResult> AddTeamMember(TeamAddMember MemberToAdd)
{
User newMember = await context.Users.FirstOrDefaultAsync(u=>u.QRcode == MemberToAdd.newQR);
Team tEdit = await context.Teams.Include(t=>t.Membros).FirstOrDefaultAsync(t=>t.Id == MemberToAdd.id);
tEdit.NMembros++;
tEdit.Membros.Add(newMember);
context.Update(tEdit);
var result = context.SaveChanges();
return StatusCode(201);
}
}
}

@ -18,23 +18,32 @@ namespace api.Data
public async Task<IEnumerable<EventLocVisited>> GetEventLocsVisited()
{
var rEventLocsVisitedList = await _context.EventLocsVisited.ToListAsync();
var rEventLocsVisitedList = await _context.EventLocsVisited.Include(e=>e.Team).Include(e=>e.Location).ToListAsync();
return rEventLocsVisitedList;
}
public Task<IEnumerable<EventLocVisited>> GetEventLocsVisitedTeam(int id)
public async Task<List<EventLocVisited>> GetEventLocsVisitedTeam(int id)
{
List<EventLocVisited> allLocs = _context.EventLocsVisited.ToList();
allLocs.ForEach(i=>Console.Write("{0}\t", i));
Console.WriteLine("teste");
List<EventLocVisited> allLocs = await _context.EventLocsVisited.Include(e=>e.Team).Include(e=>e.Location).ToListAsync();
List<EventLocVisited> rList = new List<EventLocVisited>();
for(var i=0;i<allLocs.Count;i++){
if(allLocs[i].Team.Id == id){
rList.Add(allLocs[i]);
}
}
return rList;
}
public async Task<List<EventLocVisited>> GetEventLocsVisitedEvent(int id)
{
List<EventLocVisited> allLocs = await _context.EventLocsVisited.Include(e=>e.Team).Include(e=>e.Location).ToListAsync();
List<EventLocVisited> rList = new List<EventLocVisited>();
for(var i=0;i<allLocs.Count;i++){
if(allLocs[i].Location.EventId == id){
rList.Add(allLocs[i]);
}
}
return rList;
}

@ -9,7 +9,8 @@ namespace api.Data
{
Task<IEnumerable<EventLocVisited>> GetEventLocsVisited();
Task<IEnumerable<EventLocVisited>> GetEventLocsVisitedTeam(int id);
Task<List<EventLocVisited>> GetEventLocsVisitedTeam(int id);
Task<List<EventLocVisited>> GetEventLocsVisitedEvent(int id);
}

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using api.Models;
@ -8,7 +9,8 @@ namespace api.Data
{
Task<IEnumerable<Team>> GetTeams();
Task<Team> GetEventTeam(int id);
Task<List<Team>> GetEventTeam(int id);
Task<List<Team>> GetUserTeam(String QR);
}

@ -16,16 +16,37 @@ namespace api.Data
public DataContext _context { get; }
public async Task<Team> GetEventTeam(int id)
public async Task<List<Team>> GetEventTeam(int id)
{
var rTeam = await _context.Teams.FirstOrDefaultAsync(e=>e.EventId == id);
List<Team> allTeams = await _context.Teams.Include(a=>a.Cap).Include(a=>a.Membros).ToListAsync();
List<Team> rTeam = new List<Team>();
allTeams.ForEach(delegate(Team t){
if(t.EventId == id){
rTeam.Add(t);
}
});
return rTeam;
}
public async Task<List<Team>> GetUserTeam(String QR)
{
List<Team> allTeams = await _context.Teams.Include(a=>a.Cap).Include(a=>a.Membros).ToListAsync();
List<Team> rTeam = new List<Team>();
allTeams.ForEach(delegate(Team t){
foreach (User u in t.Membros){
if(u.QRcode == QR){
rTeam.Add(t);
}
}
});
return rTeam;
}
public async Task<IEnumerable<Team>> GetTeams()
{
var rTeams = await _context.Teams.ToListAsync();
var rTeams = await _context.Teams.Include(a=>a.Cap).Include(a=>a.Membros).ToListAsync();
return rTeams;
}

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using api.Models;
namespace api.Dtos
{
public class TeamAddMember
{
[Required]
public int id{get;set;} //equipa id
[Required]
public string newQR{get;set;} //novo membro
}
}

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using api.Models;
namespace api.Dtos
{
public class TeamForAdd
{
[Required]
public int EventId{get;set;} //equipa para o evento ID
[Required]
public string Nome{get;set;} //Nome da equipa
[Required]
public string capQR{get;set;} //Capitao da equipa
}
}

@ -0,0 +1,450 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using api.Data;
namespace api.Migrations
{
[DbContext(typeof(DataContext))]
[Migration("20190306210633_team_fix")]
partial class team_fix
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.2.0-rtm-35687")
.HasAnnotation("Relational:MaxIdentifierLength", 64);
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<int>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("ClaimType");
b.Property<string>("ClaimValue");
b.Property<int>("RoleId");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("ClaimType");
b.Property<string>("ClaimValue");
b.Property<int>("UserId");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>
{
b.Property<string>("LoginProvider");
b.Property<string>("ProviderKey");
b.Property<string>("ProviderDisplayName");
b.Property<int>("UserId");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>
{
b.Property<int>("UserId");
b.Property<string>("LoginProvider");
b.Property<string>("Name");
b.Property<string>("Value");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens");
});
modelBuilder.Entity("api.Models.Event", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("Desc");
b.Property<string>("Nome");
b.HasKey("Id");
b.ToTable("Events");
});
modelBuilder.Entity("api.Models.EventLoc", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("Desc");
b.Property<int>("EventId");
b.Property<int?>("ImgId");
b.Property<float>("Lat");
b.Property<float>("Long");
b.Property<string>("Nome");
b.HasKey("Id");
b.HasIndex("ImgId");
b.ToTable("EventLocs");
});
modelBuilder.Entity("api.Models.EventLocVisited", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<int?>("LocationId");
b.Property<int?>("TeamId");
b.Property<DateTime>("timestamp");
b.HasKey("Id");
b.HasIndex("LocationId");
b.HasIndex("TeamId");
b.ToTable("EventLocsVisited");
});
modelBuilder.Entity("api.Models.Log", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<int?>("UserId");
b.Property<int?>("UserId1");
b.Property<int>("amount");
b.Property<int>("available");
b.Property<string>("logType");
b.Property<int?>("productId");
b.Property<string>("transactionId");
b.HasKey("Id");
b.HasIndex("UserId");
b.HasIndex("UserId1");
b.HasIndex("productId");
b.ToTable("Logs");
});
modelBuilder.Entity("api.Models.Photo", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<DateTime>("DateAdded");
b.Property<string>("Description");
b.Property<bool>("IsMain");
b.Property<string>("Url");
b.Property<int>("UserId");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Photos");
});
modelBuilder.Entity("api.Models.Product", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<int>("basePrice");
b.Property<string>("name");
b.Property<float>("revenue");
b.Property<int>("sold");
b.HasKey("Id");
b.ToTable("Products");
});
modelBuilder.Entity("api.Models.Role", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken();
b.Property<string>("Name")
.HasMaxLength(256);
b.Property<string>("NormalizedName")
.HasMaxLength(256);
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasName("RoleNameIndex");
b.ToTable("AspNetRoles");
});
modelBuilder.Entity("api.Models.Team", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<int?>("CapId");
b.Property<int>("EventId");
b.Property<int>("NMembros");
b.Property<string>("Nome");
b.Property<int>("Pontos");
b.HasKey("Id");
b.HasIndex("CapId");
b.ToTable("Teams");
});
modelBuilder.Entity("api.Models.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<int>("AccessFailedCount");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken();
b.Property<string>("Email")
.HasMaxLength(256);
b.Property<bool>("EmailConfirmed");
b.Property<bool>("LockoutEnabled");
b.Property<DateTimeOffset?>("LockoutEnd");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256);
b.Property<string>("NormalizedUserName")
.HasMaxLength(256);
b.Property<string>("PasswordHash");
b.Property<string>("PhoneNumber");
b.Property<bool>("PhoneNumberConfirmed");
b.Property<string>("QRcode");
b.Property<string>("SecurityStamp");
b.Property<int?>("TeamId");
b.Property<bool>("TwoFactorEnabled");
b.Property<string>("UserName")
.HasMaxLength(256);
b.Property<int>("drinks");
b.Property<int>("food");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasName("UserNameIndex");
b.HasIndex("TeamId");
b.ToTable("AspNetUsers");
});
modelBuilder.Entity("api.Models.UserRole", b =>
{
b.Property<int>("UserId");
b.Property<int>("RoleId");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles");
});
modelBuilder.Entity("api.Models.Value", b =>
{
b.Property<int>("id")
.ValueGeneratedOnAdd();
b.Property<string>("Name");
b.HasKey("id");
b.ToTable("Values");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<int>", b =>
{
b.HasOne("api.Models.Role")
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>
{
b.HasOne("api.Models.User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>
{
b.HasOne("api.Models.User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>
{
b.HasOne("api.Models.User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("api.Models.EventLoc", b =>
{
b.HasOne("api.Models.Photo", "Img")
.WithMany()
.HasForeignKey("ImgId");
});
modelBuilder.Entity("api.Models.EventLocVisited", b =>
{
b.HasOne("api.Models.EventLoc", "Location")
.WithMany()
.HasForeignKey("LocationId");
b.HasOne("api.Models.Team", "Team")
.WithMany()
.HasForeignKey("TeamId");
});
modelBuilder.Entity("api.Models.Log", b =>
{
b.HasOne("api.Models.User")
.WithMany("logsFebrada")
.HasForeignKey("UserId");
b.HasOne("api.Models.User")
.WithMany("logsFestarola")
.HasForeignKey("UserId1");
b.HasOne("api.Models.Product", "product")
.WithMany()
.HasForeignKey("productId");
});
modelBuilder.Entity("api.Models.Photo", b =>
{
b.HasOne("api.Models.User", "User")
.WithMany("Photos")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("api.Models.Team", b =>
{
b.HasOne("api.Models.User", "Cap")
.WithMany()
.HasForeignKey("CapId");
});
modelBuilder.Entity("api.Models.User", b =>
{
b.HasOne("api.Models.Team")
.WithMany("Membros")
.HasForeignKey("TeamId");
});
modelBuilder.Entity("api.Models.UserRole", b =>
{
b.HasOne("api.Models.Role", "Role")
.WithMany("UserRoles")
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("api.Models.User", "User")
.WithMany("UserRoles")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace api.Migrations
{
public partial class team_fix : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "QRcode",
table: "Teams");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "QRcode",
table: "Teams",
nullable: true);
}
}
}

@ -251,8 +251,6 @@ namespace api.Migrations
b.Property<int>("Pontos");
b.Property<string>("QRcode");
b.HasKey("Id");
b.HasIndex("CapId");

@ -10,7 +10,7 @@ namespace api.Models
public int EventId{get;set;} //equipa para o evento ID
public string Nome{get;set;} //Nome da equipa
public User Cap{get;set;} //Capitao da equipa
public ICollection<User> Membros {get;set;} //Membros da equipa
public List<User> Membros {get;set;} //Membros da equipa
public int NMembros {get;set;} //Numero de Membros na equipa
public int Pontos {get;set;} //Postos da equipa
}

Loading…
Cancel
Save