fix cromos
This commit is contained in:
parent
89d8bb5585
commit
a6eed722c7
|
@ -32,21 +32,22 @@ namespace api.Controllers
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<List<Cromos>> GetCromos(string QR)
|
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();
|
var allCromos = await context.Cromos.ToListAsync();
|
||||||
|
|
||||||
List<Cromos> rList = new List<Cromos>();
|
List<Cromos> rList = new List<Cromos>();
|
||||||
|
|
||||||
allCromos.ForEach(delegate(Cromos c){
|
allCromos.ForEach(delegate(Cromos c){
|
||||||
usr.cromos.ForEach(delegate(int cid){
|
for(int i=0;i<usrCromos.Length;i++){
|
||||||
if(c.Id == cid){ //user tem o cromo
|
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};
|
Cromos toAdd = new Cromos{Id = c.Id,Nome=c.Nome,DescMostrar=c.DescUnlocked,QRCode=c.QRCode,img=c.img};
|
||||||
rList.Add(toAdd);
|
rList.Add(toAdd);
|
||||||
}else{ //user NAO tem o cromo
|
}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};
|
Cromos toAdd = new Cromos{Id = c.Id,Nome=c.Nome,DescMostrar=c.DescLocked,QRCode=c.QRCode,img=c.img};
|
||||||
rList.Add(toAdd);
|
rList.Add(toAdd);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
return rList;
|
return rList;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,13 +32,13 @@ namespace api.Controllers
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<ScanReturn> doScan(QRToScan ScanData)
|
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 allUsers = await context.Users.ToListAsync();
|
||||||
var allCromos = await context.Cromos.ToListAsync();
|
var allCromos = await context.Cromos.ToListAsync();
|
||||||
|
|
||||||
var userAProcurar = await context.Users.FirstOrDefaultAsync(c=>c.QRcode == ScanData.ScanQR);
|
var userAProcurar = await context.Users.FirstOrDefaultAsync(c=>c.QRcode == ScanData.ScanQR);
|
||||||
|
|
||||||
ScanReturn toReturn = new ScanReturn();
|
ScanReturn toReturn = new ScanReturn{tipo = -1};
|
||||||
|
|
||||||
if(userAProcurar != null){
|
if(userAProcurar != null){
|
||||||
_mapper.Map(toReturn.user,userAProcurar);
|
_mapper.Map(toReturn.user,userAProcurar);
|
||||||
|
@ -48,7 +48,7 @@ namespace api.Controllers
|
||||||
allCromos.ForEach(delegate(Cromos c){
|
allCromos.ForEach(delegate(Cromos c){
|
||||||
if(c.QRCode == ScanData.ScanQR){
|
if(c.QRCode == ScanData.ScanQR){
|
||||||
toReturn.tipo=0;
|
toReturn.tipo=0;
|
||||||
usr.cromos.Add(c.Id);
|
usr.cromos = usr.cromos + "," + c.Id;
|
||||||
context.Users.Update(usr);
|
context.Users.Update(usr);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
|
|
||||||
|
@ -59,8 +59,6 @@ namespace api.Controllers
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
toReturn.tipo = -1;
|
|
||||||
|
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,8 @@ using api.Data;
|
||||||
namespace api.Migrations
|
namespace api.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(DataContext))]
|
[DbContext(typeof(DataContext))]
|
||||||
[Migration("20190309183026_TeamsV2")]
|
[Migration("20190316162716_cromos")]
|
||||||
partial class TeamsV2
|
partial class cromos
|
||||||
{
|
{
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
|
@ -87,6 +87,30 @@ namespace api.Migrations
|
||||||
b.ToTable("AspNetUserTokens");
|
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 =>
|
modelBuilder.Entity("api.Models.Event", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
|
@ -300,6 +324,8 @@ namespace api.Migrations
|
||||||
b.Property<string>("UserName")
|
b.Property<string>("UserName")
|
||||||
.HasMaxLength(256);
|
.HasMaxLength(256);
|
||||||
|
|
||||||
|
b.Property<string>("cromos");
|
||||||
|
|
||||||
b.Property<int>("drinks");
|
b.Property<int>("drinks");
|
||||||
|
|
||||||
b.Property<int>("food");
|
b.Property<int>("food");
|
||||||
|
@ -377,6 +403,13 @@ namespace api.Migrations
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("api.Models.Cromos", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("api.Models.Photo", "img")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("imgId");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("api.Models.EventLoc", b =>
|
modelBuilder.Entity("api.Models.EventLoc", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("api.Models.Photo", "Img")
|
b.HasOne("api.Models.Photo", "Img")
|
|
@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
namespace api.Migrations
|
namespace api.Migrations
|
||||||
{
|
{
|
||||||
public partial class TeamsV2 : Migration
|
public partial class cromos : Migration
|
||||||
{
|
{
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
{
|
{
|
||||||
|
@ -190,6 +190,30 @@ namespace api.Migrations
|
||||||
table.PrimaryKey("PK_Photos", x => x.Id);
|
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(
|
migrationBuilder.CreateTable(
|
||||||
name: "EventLocs",
|
name: "EventLocs",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
|
@ -254,7 +278,8 @@ namespace api.Migrations
|
||||||
QRcode = table.Column<string>(nullable: true),
|
QRcode = table.Column<string>(nullable: true),
|
||||||
drinks = table.Column<int>(nullable: false),
|
drinks = table.Column<int>(nullable: false),
|
||||||
food = 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 =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
|
@ -336,6 +361,11 @@ namespace api.Migrations
|
||||||
table: "AspNetUsers",
|
table: "AspNetUsers",
|
||||||
column: "teamID");
|
column: "teamID");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Cromos_imgId",
|
||||||
|
table: "Cromos",
|
||||||
|
column: "imgId");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_EventLocs_ImgId",
|
name: "IX_EventLocs_ImgId",
|
||||||
table: "EventLocs",
|
table: "EventLocs",
|
||||||
|
@ -462,6 +492,9 @@ namespace api.Migrations
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "AspNetUserTokens");
|
name: "AspNetUserTokens");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Cromos");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "EventLocsVisited");
|
name: "EventLocsVisited");
|
||||||
|
|
|
@ -85,6 +85,30 @@ namespace api.Migrations
|
||||||
b.ToTable("AspNetUserTokens");
|
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 =>
|
modelBuilder.Entity("api.Models.Event", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
|
@ -298,6 +322,8 @@ namespace api.Migrations
|
||||||
b.Property<string>("UserName")
|
b.Property<string>("UserName")
|
||||||
.HasMaxLength(256);
|
.HasMaxLength(256);
|
||||||
|
|
||||||
|
b.Property<string>("cromos");
|
||||||
|
|
||||||
b.Property<int>("drinks");
|
b.Property<int>("drinks");
|
||||||
|
|
||||||
b.Property<int>("food");
|
b.Property<int>("food");
|
||||||
|
@ -375,6 +401,13 @@ namespace api.Migrations
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("api.Models.Cromos", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("api.Models.Photo", "img")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("imgId");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("api.Models.EventLoc", b =>
|
modelBuilder.Entity("api.Models.EventLoc", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("api.Models.Photo", "Img")
|
b.HasOne("api.Models.Photo", "Img")
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace api.Models
|
||||||
[ForeignKey("teamID")]
|
[ForeignKey("teamID")]
|
||||||
public Team team{get;set;}
|
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",
|
"TargetFramework": "netcoreapp2.1",
|
||||||
"TagHelpers": [],
|
"TagHelpers": [],
|
||||||
"Configuration": {
|
"Configuration": {
|
||||||
|
|
Loading…
Reference in New Issue