From a6eed722c78fbfdd4c687a04347598ba6e42977a Mon Sep 17 00:00:00 2001 From: ZMiguel Alves Date: Sat, 16 Mar 2019 16:32:37 +0000 Subject: [PATCH] fix cromos --- api/Controllers/CromosController.cs | 9 +++-- api/Controllers/ScanController.cs | 8 ++-- ...r.cs => 20190316162716_cromos.Designer.cs} | 37 ++++++++++++++++++- ...26_TeamsV2.cs => 20190316162716_cromos.cs} | 37 ++++++++++++++++++- api/Migrations/DataContextModelSnapshot.cs | 33 +++++++++++++++++ api/Models/User.cs | 2 +- .../Debug/netcoreapp2.1/project.razor.json | 2 +- 7 files changed, 113 insertions(+), 15 deletions(-) rename api/Migrations/{20190309183026_TeamsV2.Designer.cs => 20190316162716_cromos.Designer.cs} (93%) rename api/Migrations/{20190309183026_TeamsV2.cs => 20190316162716_cromos.cs} (92%) diff --git a/api/Controllers/CromosController.cs b/api/Controllers/CromosController.cs index 29211657..6e479c8e 100644 --- a/api/Controllers/CromosController.cs +++ b/api/Controllers/CromosController.cs @@ -32,21 +32,22 @@ namespace api.Controllers [HttpGet] public async Task> GetCromos(string QR) { - var usr = await context.Users.Include(a=>a.cromos).FirstOrDefaultAsync(u=>u.QRcode == QR); + var usr = await context.Users.FirstOrDefaultAsync(u=>u.QRcode == QR); + var usrCromos = usr.cromos.Split(","); var allCromos = await context.Cromos.ToListAsync(); List rList = new List(); allCromos.ForEach(delegate(Cromos c){ - usr.cromos.ForEach(delegate(int cid){ - if(c.Id == cid){ //user tem o cromo + for(int i=0;i doScan(QRToScan ScanData) { - User usr = await context.Users.Include(a=>a.cromos).FirstOrDefaultAsync(b=>b.QRcode == ScanData.UserQR); + User usr = await context.Users.FirstOrDefaultAsync(b=>b.QRcode == ScanData.UserQR); var allUsers = await context.Users.ToListAsync(); var allCromos = await context.Cromos.ToListAsync(); var userAProcurar = await context.Users.FirstOrDefaultAsync(c=>c.QRcode == ScanData.ScanQR); - ScanReturn toReturn = new ScanReturn(); + ScanReturn toReturn = new ScanReturn{tipo = -1}; if(userAProcurar != null){ _mapper.Map(toReturn.user,userAProcurar); @@ -48,7 +48,7 @@ namespace api.Controllers allCromos.ForEach(delegate(Cromos c){ if(c.QRCode == ScanData.ScanQR){ toReturn.tipo=0; - usr.cromos.Add(c.Id); + usr.cromos = usr.cromos + "," + c.Id; context.Users.Update(usr); context.SaveChanges(); @@ -59,8 +59,6 @@ namespace api.Controllers return toReturn; } - toReturn.tipo = -1; - return toReturn; } diff --git a/api/Migrations/20190309183026_TeamsV2.Designer.cs b/api/Migrations/20190316162716_cromos.Designer.cs similarity index 93% rename from api/Migrations/20190309183026_TeamsV2.Designer.cs rename to api/Migrations/20190316162716_cromos.Designer.cs index 68ef50d4..d41ea209 100644 --- a/api/Migrations/20190309183026_TeamsV2.Designer.cs +++ b/api/Migrations/20190316162716_cromos.Designer.cs @@ -9,8 +9,8 @@ using api.Data; namespace api.Migrations { [DbContext(typeof(DataContext))] - [Migration("20190309183026_TeamsV2")] - partial class TeamsV2 + [Migration("20190316162716_cromos")] + partial class cromos { protected override void BuildTargetModel(ModelBuilder modelBuilder) { @@ -87,6 +87,30 @@ namespace api.Migrations b.ToTable("AspNetUserTokens"); }); + modelBuilder.Entity("api.Models.Cromos", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("DescLocked"); + + b.Property("DescMostrar"); + + b.Property("DescUnlocked"); + + b.Property("Nome"); + + b.Property("QRCode"); + + b.Property("imgId"); + + b.HasKey("Id"); + + b.HasIndex("imgId"); + + b.ToTable("Cromos"); + }); + modelBuilder.Entity("api.Models.Event", b => { b.Property("Id") @@ -300,6 +324,8 @@ namespace api.Migrations b.Property("UserName") .HasMaxLength(256); + b.Property("cromos"); + b.Property("drinks"); b.Property("food"); @@ -377,6 +403,13 @@ namespace api.Migrations .OnDelete(DeleteBehavior.Cascade); }); + modelBuilder.Entity("api.Models.Cromos", b => + { + b.HasOne("api.Models.Photo", "img") + .WithMany() + .HasForeignKey("imgId"); + }); + modelBuilder.Entity("api.Models.EventLoc", b => { b.HasOne("api.Models.Photo", "Img") diff --git a/api/Migrations/20190309183026_TeamsV2.cs b/api/Migrations/20190316162716_cromos.cs similarity index 92% rename from api/Migrations/20190309183026_TeamsV2.cs rename to api/Migrations/20190316162716_cromos.cs index 9cd33c02..7698353a 100644 --- a/api/Migrations/20190309183026_TeamsV2.cs +++ b/api/Migrations/20190316162716_cromos.cs @@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace api.Migrations { - public partial class TeamsV2 : Migration + public partial class cromos : Migration { protected override void Up(MigrationBuilder migrationBuilder) { @@ -190,6 +190,30 @@ namespace api.Migrations table.PrimaryKey("PK_Photos", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Cromos", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + QRCode = table.Column(nullable: true), + Nome = table.Column(nullable: true), + DescLocked = table.Column(nullable: true), + DescUnlocked = table.Column(nullable: true), + DescMostrar = table.Column(nullable: true), + imgId = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Cromos", x => x.Id); + table.ForeignKey( + name: "FK_Cromos_Photos_imgId", + column: x => x.imgId, + principalTable: "Photos", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + migrationBuilder.CreateTable( name: "EventLocs", columns: table => new @@ -254,7 +278,8 @@ namespace api.Migrations QRcode = table.Column(nullable: true), drinks = table.Column(nullable: false), food = table.Column(nullable: false), - teamID = table.Column(nullable: true) + teamID = table.Column(nullable: true), + cromos = table.Column(nullable: true) }, constraints: table => { @@ -336,6 +361,11 @@ namespace api.Migrations table: "AspNetUsers", column: "teamID"); + migrationBuilder.CreateIndex( + name: "IX_Cromos_imgId", + table: "Cromos", + column: "imgId"); + migrationBuilder.CreateIndex( name: "IX_EventLocs_ImgId", table: "EventLocs", @@ -462,6 +492,9 @@ namespace api.Migrations migrationBuilder.DropTable( name: "AspNetUserTokens"); + migrationBuilder.DropTable( + name: "Cromos"); + migrationBuilder.DropTable( name: "EventLocsVisited"); diff --git a/api/Migrations/DataContextModelSnapshot.cs b/api/Migrations/DataContextModelSnapshot.cs index 7b8d9f5b..c727da13 100644 --- a/api/Migrations/DataContextModelSnapshot.cs +++ b/api/Migrations/DataContextModelSnapshot.cs @@ -85,6 +85,30 @@ namespace api.Migrations b.ToTable("AspNetUserTokens"); }); + modelBuilder.Entity("api.Models.Cromos", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("DescLocked"); + + b.Property("DescMostrar"); + + b.Property("DescUnlocked"); + + b.Property("Nome"); + + b.Property("QRCode"); + + b.Property("imgId"); + + b.HasKey("Id"); + + b.HasIndex("imgId"); + + b.ToTable("Cromos"); + }); + modelBuilder.Entity("api.Models.Event", b => { b.Property("Id") @@ -298,6 +322,8 @@ namespace api.Migrations b.Property("UserName") .HasMaxLength(256); + b.Property("cromos"); + b.Property("drinks"); b.Property("food"); @@ -375,6 +401,13 @@ namespace api.Migrations .OnDelete(DeleteBehavior.Cascade); }); + modelBuilder.Entity("api.Models.Cromos", b => + { + b.HasOne("api.Models.Photo", "img") + .WithMany() + .HasForeignKey("imgId"); + }); + modelBuilder.Entity("api.Models.EventLoc", b => { b.HasOne("api.Models.Photo", "Img") diff --git a/api/Models/User.cs b/api/Models/User.cs index b798efb9..3351d075 100755 --- a/api/Models/User.cs +++ b/api/Models/User.cs @@ -21,7 +21,7 @@ namespace api.Models [ForeignKey("teamID")] public Team team{get;set;} - public List cromos {get;set;} + public string cromos {get;set;} } } \ No newline at end of file diff --git a/api/obj/Debug/netcoreapp2.1/project.razor.json b/api/obj/Debug/netcoreapp2.1/project.razor.json index d0f0bc73..04482418 100644 --- a/api/obj/Debug/netcoreapp2.1/project.razor.json +++ b/api/obj/Debug/netcoreapp2.1/project.razor.json @@ -1,5 +1,5 @@ { - "ProjectFilePath": "/Users/henrique/ENEI2019/api/api.csproj", + "ProjectFilePath": "c:\\Users\\ZMiguel\\Desktop\\ENEI2019\\api\\api.csproj", "TargetFramework": "netcoreapp2.1", "TagHelpers": [], "Configuration": {