fix cromos
This commit is contained in:
parent
89d8bb5585
commit
a6eed722c7
|
@ -32,21 +32,22 @@ namespace api.Controllers
|
|||
[HttpGet]
|
||||
public async Task<List<Cromos>> 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<Cromos> rList = new List<Cromos>();
|
||||
|
||||
allCromos.ForEach(delegate(Cromos c){
|
||||
usr.cromos.ForEach(delegate(int cid){
|
||||
if(c.Id == cid){ //user tem o cromo
|
||||
for(int i=0;i<usrCromos.Length;i++){
|
||||
if(Int32.Parse(usrCromos[i])==c.Id){
|
||||
Cromos toAdd = new Cromos{Id = c.Id,Nome=c.Nome,DescMostrar=c.DescUnlocked,QRCode=c.QRCode,img=c.img};
|
||||
rList.Add(toAdd);
|
||||
}else{ //user NAO tem o cromo
|
||||
Cromos toAdd = new Cromos{Id = c.Id,Nome=c.Nome,DescMostrar=c.DescLocked,QRCode=c.QRCode,img=c.img};
|
||||
rList.Add(toAdd);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
return rList;
|
||||
}
|
||||
|
|
|
@ -32,13 +32,13 @@ namespace api.Controllers
|
|||
[HttpPost]
|
||||
public async Task<ScanReturn> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<string>("DescLocked");
|
||||
|
||||
b.Property<string>("DescMostrar");
|
||||
|
||||
b.Property<string>("DescUnlocked");
|
||||
|
||||
b.Property<string>("Nome");
|
||||
|
||||
b.Property<string>("QRCode");
|
||||
|
||||
b.Property<int?>("imgId");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("imgId");
|
||||
|
||||
b.ToTable("Cromos");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("api.Models.Event", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
|
@ -300,6 +324,8 @@ namespace api.Migrations
|
|||
b.Property<string>("UserName")
|
||||
.HasMaxLength(256);
|
||||
|
||||
b.Property<string>("cromos");
|
||||
|
||||
b.Property<int>("drinks");
|
||||
|
||||
b.Property<int>("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")
|
|
@ -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<int>(nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
QRCode = table.Column<string>(nullable: true),
|
||||
Nome = table.Column<string>(nullable: true),
|
||||
DescLocked = table.Column<string>(nullable: true),
|
||||
DescUnlocked = table.Column<string>(nullable: true),
|
||||
DescMostrar = table.Column<string>(nullable: true),
|
||||
imgId = table.Column<int>(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<string>(nullable: true),
|
||||
drinks = table.Column<int>(nullable: false),
|
||||
food = table.Column<int>(nullable: false),
|
||||
teamID = table.Column<int>(nullable: true)
|
||||
teamID = table.Column<int>(nullable: true),
|
||||
cromos = table.Column<string>(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");
|
||||
|
|
@ -85,6 +85,30 @@ namespace api.Migrations
|
|||
b.ToTable("AspNetUserTokens");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("api.Models.Cromos", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<string>("DescLocked");
|
||||
|
||||
b.Property<string>("DescMostrar");
|
||||
|
||||
b.Property<string>("DescUnlocked");
|
||||
|
||||
b.Property<string>("Nome");
|
||||
|
||||
b.Property<string>("QRCode");
|
||||
|
||||
b.Property<int?>("imgId");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("imgId");
|
||||
|
||||
b.ToTable("Cromos");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("api.Models.Event", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
|
@ -298,6 +322,8 @@ namespace api.Migrations
|
|||
b.Property<string>("UserName")
|
||||
.HasMaxLength(256);
|
||||
|
||||
b.Property<string>("cromos");
|
||||
|
||||
b.Property<int>("drinks");
|
||||
|
||||
b.Property<int>("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")
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace api.Models
|
|||
[ForeignKey("teamID")]
|
||||
public Team team{get;set;}
|
||||
|
||||
public List<int> cromos {get;set;}
|
||||
public string cromos {get;set;}
|
||||
|
||||
}
|
||||
}
|
|
@ -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": {
|
||||
|
|
Loading…
Reference in New Issue