Fix Teams, Events, Cromos & Scans

This commit is contained in:
José Valdiviesso 2019-03-16 19:17:19 +00:00
parent bc576de930
commit c3c3aeca45
15 changed files with 197 additions and 221 deletions

View File

@ -29,11 +29,12 @@ namespace api.Controllers
// GET api/cromos/QR // GET api/cromos/QR
// GET cromos do user QR // GET cromos do user QR
[HttpGet] [HttpGet("{QR}")]
public async Task<List<Cromos>> GetCromos(string QR) public async Task<List<Cromos>> GetCromos(string QR)
{ {
var usr = await context.Users.FirstOrDefaultAsync(u=>u.QRcode == QR); var usr = await context.Users.FirstOrDefaultAsync(u=>u.QRcode == QR);
var usrCromos = usr.cromos.Split(","); string[] usrCromos = usr.cromos.Substring(1).Split(",");
Console.WriteLine(usrCromos[0]);
var allCromos = await context.Cromos.ToListAsync(); var allCromos = await context.Cromos.ToListAsync();
List<Cromos> rList = new List<Cromos>(); List<Cromos> rList = new List<Cromos>();

View File

@ -50,7 +50,7 @@ namespace api.Controllers
return Ok(Teams); return Ok(Teams);
} }
// GET api/EventLocs/[id] // GET api/EventLocs/e/[id]
[HttpGet("e/{id}")] [HttpGet("e/{id}")]
public async Task<IActionResult> GetEventLocEvent(int id) public async Task<IActionResult> GetEventLocEvent(int id)
{ {

View File

@ -67,7 +67,7 @@ namespace api.Controllers
public async Task<IActionResult> AddEventLoc(EventLocVisitedAdd EventLocVisitedData) public async Task<IActionResult> AddEventLoc(EventLocVisitedAdd EventLocVisitedData)
{ {
EventLoc Loc = await context.EventLocs.FirstOrDefaultAsync(a=>a.Id == EventLocVisitedData.EventLocID); EventLoc Loc = await context.EventLocs.FirstOrDefaultAsync(a=>a.Id == EventLocVisitedData.EventLocID);
var userT = await context.Users.FirstOrDefaultAsync(u=>u.QRcode==EventLocVisitedData.USerQR); var userT = await context.Users.Include(a=>a.team).FirstOrDefaultAsync(u=>u.QRcode==EventLocVisitedData.UserQR);
if(userT.team == null){ if(userT.team == null){
return StatusCode(403); return StatusCode(403);

View File

@ -41,7 +41,9 @@ namespace api.Controllers
ScanReturn toReturn = new ScanReturn{tipo = -1}; ScanReturn toReturn = new ScanReturn{tipo = -1};
if(userAProcurar != null){ if(userAProcurar != null){
_mapper.Map(toReturn.user,userAProcurar); UserForListDto ru = new UserForListDto();
_mapper.Map(userAProcurar,ru);
toReturn.user = ru;
toReturn.tipo=1; toReturn.tipo=1;
return toReturn; return toReturn;
}else{ }else{
@ -59,7 +61,7 @@ namespace api.Controllers
return toReturn; return toReturn;
} }
return toReturn; //return toReturn;
} }
} }

View File

@ -36,28 +36,67 @@ namespace api.Controllers
// GET api/teams // GET api/teams
// GET all teams // GET all teams
[HttpGet] [HttpGet]
public async Task<IActionResult> GetTeams() public async Task<List<TeamToReturn>> GetTeams()
{ {
var Teams = await _repo.GetTeams(); List<Team> allTeams = await context.Teams.ToListAsync();
return Ok(Teams); List<TeamToReturn> rTeams = new List<TeamToReturn>();
for(var i = 0; i < allTeams.Count;i++){
TeamToReturn tR = new TeamToReturn();
_mapper.Map(allTeams[i],tR);
var usr = await context.Users.FirstOrDefaultAsync(a=>a.QRcode == allTeams[i].CapQR);
UserForListDto uT = new UserForListDto();
_mapper.Map(usr,uT);
tR.Cap = uT;
rTeams.Add(tR);
}
return rTeams;
} }
// GET api/teams/e/[id] // GET api/teams/e/[id]
// GET all teams for event id // GET all teams for event id
[HttpGet("e/{id}")] [HttpGet("e/{id}")]
public async Task<IActionResult> GetTeamsEvent(int id) public async Task<List<TeamToReturn>> GetTeamsEvent(int id)
{ {
var Teams = await _repo.GetEventTeam(id); List<Team> allTeams = await context.Teams.ToListAsync();
return Ok(Teams); List<TeamToReturn> rTeam = new List<TeamToReturn>();
TeamToReturn tR = new TeamToReturn();
for(var i = 0; i < allTeams.Count;i++){
if(allTeams[i].EventId == id){
_mapper.Map(allTeams[i],tR);
var usr = await context.Users.FirstOrDefaultAsync(a=>a.QRcode == allTeams[i].CapQR);
UserForListDto uT = new UserForListDto();
_mapper.Map(usr,uT);
tR.Cap = uT;
rTeam.Add(tR);
}
}
return rTeam;
} }
// GET api/teams/e/[id] // GET api/teams/u/[id]
// GET all teams for event id // GET all teams for user id
[HttpGet("u/{QR}")] [HttpGet("u/{QR}")]
public async Task<IActionResult> GetTeamsUser(String QR) public async Task<TeamToReturn> GetTeamsUser(String QR)
{ {
var Teams = await _repo.GetUserTeam(QR); var rUsr = await context.Users.Include(b=>b.team).FirstOrDefaultAsync(a=>a.QRcode == QR);
return Ok(Teams); List<Team> allTeams = await context.Teams.ToListAsync();
TeamToReturn rTeam = new TeamToReturn();
for(var i = 0; i < allTeams.Count;i++){
if(allTeams[i].Id == rUsr.team.Id){
_mapper.Map(allTeams[i],rTeam);
var usr = await context.Users.FirstOrDefaultAsync(a=>a.QRcode == allTeams[i].CapQR);
UserForListDto uT = new UserForListDto();
_mapper.Map(usr,uT);
rTeam.Cap = uT;
}
}
return rTeam;
} }
// POST api/teams/add // POST api/teams/add
@ -66,10 +105,10 @@ namespace api.Controllers
public async Task<IActionResult> CreateTeam(TeamForAdd TeamAddDetails) public async Task<IActionResult> CreateTeam(TeamForAdd TeamAddDetails)
{ {
User tCap = await context.Users.FirstOrDefaultAsync(u=>u.QRcode == TeamAddDetails.capQR); User tCap = await context.Users.Include(a=>a.team).FirstOrDefaultAsync(u=>u.QRcode == TeamAddDetails.capQR);
if(tCap.team == null){ if(tCap.team == null){
Team tAdd = new Team{EventId = TeamAddDetails.EventId, Nome = TeamAddDetails.Nome, Cap = tCap, NMembros = 1, Pontos = 0}; Team tAdd = new Team{EventId = TeamAddDetails.EventId, Nome = TeamAddDetails.Nome, CapQR = tCap.QRcode, NMembros = 1, Pontos = 0};
tCap.team = tAdd; tCap.team = tAdd;
@ -122,11 +161,11 @@ namespace api.Controllers
public async Task<IActionResult> ChangeName(TeamChangeName NameChange) public async Task<IActionResult> ChangeName(TeamChangeName NameChange)
{ {
Team tEdit = await context.Teams.Include(t=>t.Cap).FirstOrDefaultAsync(t=>t.Id == NameChange.TeamID); Team tEdit = await context.Teams.FirstOrDefaultAsync(t=>t.Id == NameChange.TeamID);
User cap = await context.Users.FirstOrDefaultAsync(u=>u.QRcode == NameChange.UserQR); User cap = await context.Users.FirstOrDefaultAsync(u=>u.QRcode == NameChange.UserQR);
if(cap == tEdit.Cap){ if(cap.QRcode == tEdit.CapQR){
tEdit.Nome = NameChange.nome; tEdit.Nome = NameChange.nome;
} }
@ -144,11 +183,11 @@ namespace api.Controllers
public async Task<IActionResult> DeleteTeam(TeamDelete DeleteData) public async Task<IActionResult> DeleteTeam(TeamDelete DeleteData)
{ {
Team tEdit = await context.Teams.Include(t=>t.Cap).FirstOrDefaultAsync(t=>t.Id == DeleteData.TeamID); Team tEdit = await context.Teams.FirstOrDefaultAsync(t=>t.Id == DeleteData.TeamID);
User cap = await context.Users.FirstOrDefaultAsync(u=>u.QRcode == DeleteData.UserQR); User cap = await context.Users.FirstOrDefaultAsync(u=>u.QRcode == DeleteData.UserQR);
if(cap == tEdit.Cap){ if(cap.QRcode == tEdit.CapQR){
context.Teams.Remove(tEdit); context.Teams.Remove(tEdit);
cap.team = null; cap.team = null;
context.Users.Update(cap); context.Users.Update(cap);
@ -167,9 +206,9 @@ namespace api.Controllers
User rmMember = await context.Users.FirstOrDefaultAsync(u=>u.QRcode == MemberToRemove.UserToRemoveQR); User rmMember = await context.Users.FirstOrDefaultAsync(u=>u.QRcode == MemberToRemove.UserToRemoveQR);
Team tEdit = await context.Teams.Include(t=>t.Cap).FirstOrDefaultAsync(t=>t.Id == MemberToRemove.TeamID); Team tEdit = await context.Teams.FirstOrDefaultAsync(t=>t.Id == MemberToRemove.TeamID);
if(rmMember == tEdit.Cap){ if(rmMember.QRcode == tEdit.CapQR){
return StatusCode(403); return StatusCode(403);
} }

View File

@ -39,7 +39,7 @@ namespace api.Data
public async Task<IEnumerable<EventLoc>> GetEventLocs() public async Task<IEnumerable<EventLoc>> GetEventLocs()
{ {
var rEventLocs = await _context.EventLocs.ToListAsync(); var rEventLocs = await _context.EventLocs.Include(a=>a.Img).ToListAsync();
return rEventLocs; return rEventLocs;
} }

View File

@ -7,11 +7,5 @@ namespace api.Data
{ {
public interface ITeamsRepository public interface ITeamsRepository
{ {
Task<IEnumerable<Team>> GetTeams();
Task<List<Team>> GetEventTeam(int id);
Task<Team> GetUserTeam(String QR);
} }
} }

View File

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

View File

@ -8,7 +8,7 @@ namespace api.Dtos
public class EventLocVisitedAdd public class EventLocVisitedAdd
{ {
[Required] [Required]
public String USerQR{get;set;} //User ID public String UserQR{get;set;} //User ID
[Required] [Required]
public int EventLocID{get;set;} //Loc id public int EventLocID{get;set;} //Loc id

17
api/Dtos/TeamToReturn.cs Normal file
View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using api.Models;
namespace api.Dtos
{
public class TeamToReturn
{
public int Id{get;set;} //id
public int EventId{get;set;} //equipa para o evento ID
public string Nome{get;set;} //Nome da equipa
public UserForListDto Cap{get;set;} //Capitao da equipa
public int NMembros {get;set;} //Numero de Membros na equipa
public int Pontos {get;set;} //Postos da equipa
}
}

View File

@ -13,6 +13,7 @@ namespace api.Helpers
CreateMap<User, UserForDetailedDto>(); CreateMap<User, UserForDetailedDto>();
CreateMap<Photo,PhotosForDetailedDto>(); CreateMap<Photo,PhotosForDetailedDto>();
CreateMap<UserForUpdateDto,User>(); CreateMap<UserForUpdateDto,User>();
CreateMap<Team,TeamToReturn>();
} }

View File

@ -9,8 +9,8 @@ using api.Data;
namespace api.Migrations namespace api.Migrations
{ {
[DbContext(typeof(DataContext))] [DbContext(typeof(DataContext))]
[Migration("20190316162716_cromos")] [Migration("20190316174616_TeamsV3")]
partial class cromos partial class TeamsV3
{ {
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
{ {
@ -267,7 +267,7 @@ namespace api.Migrations
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd(); .ValueGeneratedOnAdd();
b.Property<int?>("CapID"); b.Property<string>("CapQR");
b.Property<int>("EventId"); b.Property<int>("EventId");
@ -279,8 +279,6 @@ namespace api.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("CapID");
b.ToTable("Teams"); b.ToTable("Teams");
}); });
@ -451,13 +449,6 @@ namespace api.Migrations
.OnDelete(DeleteBehavior.Cascade); .OnDelete(DeleteBehavior.Cascade);
}); });
modelBuilder.Entity("api.Models.Team", b =>
{
b.HasOne("api.Models.User", "Cap")
.WithMany()
.HasForeignKey("CapID");
});
modelBuilder.Entity("api.Models.User", b => modelBuilder.Entity("api.Models.User", b =>
{ {
b.HasOne("api.Models.Team", "team") b.HasOne("api.Models.Team", "team")

View File

@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace api.Migrations namespace api.Migrations
{ {
public partial class cromos : Migration public partial class TeamsV3 : Migration
{ {
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)
{ {
@ -53,6 +53,23 @@ namespace api.Migrations
table.PrimaryKey("PK_Products", x => x.Id); table.PrimaryKey("PK_Products", x => x.Id);
}); });
migrationBuilder.CreateTable(
name: "Teams",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
EventId = table.Column<int>(nullable: false),
Nome = table.Column<string>(nullable: true),
CapQR = table.Column<string>(nullable: true),
NMembros = table.Column<int>(nullable: false),
Pontos = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Teams", x => x.Id);
});
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "Values", name: "Values",
columns: table => new columns: table => new
@ -88,21 +105,40 @@ namespace api.Migrations
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "AspNetUserRoles", name: "AspNetUsers",
columns: table => new columns: table => new
{ {
UserId = table.Column<int>(nullable: false), Id = table.Column<int>(nullable: false)
RoleId = table.Column<int>(nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
UserName = table.Column<string>(maxLength: 256, nullable: true),
NormalizedUserName = table.Column<string>(maxLength: 256, nullable: true),
Email = table.Column<string>(maxLength: 256, nullable: true),
NormalizedEmail = table.Column<string>(maxLength: 256, nullable: true),
EmailConfirmed = table.Column<bool>(nullable: false),
PasswordHash = table.Column<string>(nullable: true),
SecurityStamp = table.Column<string>(nullable: true),
ConcurrencyStamp = table.Column<string>(nullable: true),
PhoneNumber = table.Column<string>(nullable: true),
PhoneNumberConfirmed = table.Column<bool>(nullable: false),
TwoFactorEnabled = table.Column<bool>(nullable: false),
LockoutEnd = table.Column<DateTimeOffset>(nullable: true),
LockoutEnabled = table.Column<bool>(nullable: false),
AccessFailedCount = table.Column<int>(nullable: false),
QRcode = table.Column<string>(nullable: true),
drinks = table.Column<int>(nullable: false),
food = table.Column<int>(nullable: false),
teamID = table.Column<int>(nullable: true),
cromos = table.Column<string>(nullable: true)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); table.PrimaryKey("PK_AspNetUsers", x => x.Id);
table.ForeignKey( table.ForeignKey(
name: "FK_AspNetUserRoles_AspNetRoles_RoleId", name: "FK_AspNetUsers_Teams_teamID",
column: x => x.RoleId, column: x => x.teamID,
principalTable: "AspNetRoles", principalTable: "Teams",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Restrict);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
@ -118,6 +154,12 @@ namespace api.Migrations
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); table.PrimaryKey("PK_AspNetUserClaims", x => x.Id);
table.ForeignKey(
name: "FK_AspNetUserClaims_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
@ -132,6 +174,36 @@ namespace api.Migrations
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey });
table.ForeignKey(
name: "FK_AspNetUserLogins_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserRoles",
columns: table => new
{
UserId = table.Column<int>(nullable: false),
RoleId = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId });
table.ForeignKey(
name: "FK_AspNetUserRoles_AspNetRoles_RoleId",
column: x => x.RoleId,
principalTable: "AspNetRoles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_AspNetUserRoles_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
@ -146,6 +218,12 @@ namespace api.Migrations
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name });
table.ForeignKey(
name: "FK_AspNetUserTokens_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
@ -165,6 +243,18 @@ namespace api.Migrations
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_Logs", x => x.Id); table.PrimaryKey("PK_Logs", x => x.Id);
table.ForeignKey(
name: "FK_Logs_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Logs_AspNetUsers_UserId1",
column: x => x.UserId1,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey( table.ForeignKey(
name: "FK_Logs_Products_productId", name: "FK_Logs_Products_productId",
column: x => x.productId, column: x => x.productId,
@ -188,6 +278,12 @@ namespace api.Migrations
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_Photos", x => x.Id); table.PrimaryKey("PK_Photos", x => x.Id);
table.ForeignKey(
name: "FK_Photos_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
@ -238,60 +334,6 @@ namespace api.Migrations
onDelete: ReferentialAction.Restrict); onDelete: ReferentialAction.Restrict);
}); });
migrationBuilder.CreateTable(
name: "Teams",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
EventId = table.Column<int>(nullable: false),
Nome = table.Column<string>(nullable: true),
CapID = table.Column<int>(nullable: true),
NMembros = table.Column<int>(nullable: false),
Pontos = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Teams", x => x.Id);
});
migrationBuilder.CreateTable(
name: "AspNetUsers",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
UserName = table.Column<string>(maxLength: 256, nullable: true),
NormalizedUserName = table.Column<string>(maxLength: 256, nullable: true),
Email = table.Column<string>(maxLength: 256, nullable: true),
NormalizedEmail = table.Column<string>(maxLength: 256, nullable: true),
EmailConfirmed = table.Column<bool>(nullable: false),
PasswordHash = table.Column<string>(nullable: true),
SecurityStamp = table.Column<string>(nullable: true),
ConcurrencyStamp = table.Column<string>(nullable: true),
PhoneNumber = table.Column<string>(nullable: true),
PhoneNumberConfirmed = table.Column<bool>(nullable: false),
TwoFactorEnabled = table.Column<bool>(nullable: false),
LockoutEnd = table.Column<DateTimeOffset>(nullable: true),
LockoutEnabled = table.Column<bool>(nullable: false),
AccessFailedCount = table.Column<int>(nullable: false),
QRcode = table.Column<string>(nullable: true),
drinks = table.Column<int>(nullable: false),
food = table.Column<int>(nullable: false),
teamID = table.Column<int>(nullable: true),
cromos = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUsers", x => x.Id);
table.ForeignKey(
name: "FK_AspNetUsers_Teams_teamID",
column: x => x.teamID,
principalTable: "Teams",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "EventLocsVisited", name: "EventLocsVisited",
columns: table => new columns: table => new
@ -400,83 +442,10 @@ namespace api.Migrations
name: "IX_Photos_UserId", name: "IX_Photos_UserId",
table: "Photos", table: "Photos",
column: "UserId"); column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_Teams_CapID",
table: "Teams",
column: "CapID");
migrationBuilder.AddForeignKey(
name: "FK_AspNetUserRoles_AspNetUsers_UserId",
table: "AspNetUserRoles",
column: "UserId",
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_AspNetUserClaims_AspNetUsers_UserId",
table: "AspNetUserClaims",
column: "UserId",
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_AspNetUserLogins_AspNetUsers_UserId",
table: "AspNetUserLogins",
column: "UserId",
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_AspNetUserTokens_AspNetUsers_UserId",
table: "AspNetUserTokens",
column: "UserId",
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_Logs_AspNetUsers_UserId",
table: "Logs",
column: "UserId",
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_Logs_AspNetUsers_UserId1",
table: "Logs",
column: "UserId1",
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_Photos_AspNetUsers_UserId",
table: "Photos",
column: "UserId",
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_Teams_AspNetUsers_CapID",
table: "Teams",
column: "CapID",
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
} }
protected override void Down(MigrationBuilder migrationBuilder) protected override void Down(MigrationBuilder migrationBuilder)
{ {
migrationBuilder.DropForeignKey(
name: "FK_Teams_AspNetUsers_CapID",
table: "Teams");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "AspNetRoleClaims"); name: "AspNetRoleClaims");

View File

@ -265,7 +265,7 @@ namespace api.Migrations
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd(); .ValueGeneratedOnAdd();
b.Property<int?>("CapID"); b.Property<string>("CapQR");
b.Property<int>("EventId"); b.Property<int>("EventId");
@ -277,8 +277,6 @@ namespace api.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("CapID");
b.ToTable("Teams"); b.ToTable("Teams");
}); });
@ -449,13 +447,6 @@ namespace api.Migrations
.OnDelete(DeleteBehavior.Cascade); .OnDelete(DeleteBehavior.Cascade);
}); });
modelBuilder.Entity("api.Models.Team", b =>
{
b.HasOne("api.Models.User", "Cap")
.WithMany()
.HasForeignKey("CapID");
});
modelBuilder.Entity("api.Models.User", b => modelBuilder.Entity("api.Models.User", b =>
{ {
b.HasOne("api.Models.Team", "team") b.HasOne("api.Models.Team", "team")

View File

@ -10,9 +10,7 @@ namespace api.Models
public int Id{get;set;} //id public int Id{get;set;} //id
public int EventId{get;set;} //equipa para o evento ID public int EventId{get;set;} //equipa para o evento ID
public string Nome{get;set;} //Nome da equipa public string Nome{get;set;} //Nome da equipa
public string CapQR{get;set;} //Capitao da equipa
[ForeignKey("CapID")]
public User Cap{get;set;} //Capitao da equipa
public int NMembros {get;set;} //Numero de Membros na equipa public int NMembros {get;set;} //Numero de Membros na equipa
public int Pontos {get;set;} //Postos da equipa public int Pontos {get;set;} //Postos da equipa
} }