public async Task <IHttpActionResult> PutPlayerGroup(int id, PlayerGroup playerGroup) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != playerGroup.ID) { return(BadRequest()); } db.Entry(playerGroup).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PlayerGroupExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutGame(int id, Game game) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != game.ID_Game) { return(BadRequest()); } db.Entry(game).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!GameExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> PutFilter(int id, Filter filter) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != filter.ID_Filter) { return(BadRequest()); } db.Entry(filter).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FilterExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> PutClassification_Game(int id, Classification_Player classification_Game) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != classification_Game.ID) { return(BadRequest()); } db.Entry(classification_Game).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!Classification_GameExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> PutMessageHall(int id, MessageHall messageHall) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != messageHall.ID) { return(BadRequest()); } db.Entry(messageHall).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MessageHallExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> PutMatch(int id, Match match) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != match.ID) { return(BadRequest()); } match.AlteredAt = DateTime.UtcNow; Player p1 = await db.Gamers.FindAsync(match.IdPlayer1); Player p2 = await db.Gamers.FindAsync(match.IdPlayer2); match.Weight = (5.0f - Math.Abs(p1.MPoints - p2.MPoints)); db.Entry(match).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MatchExists(id)) { return(NotFound()); } else { throw; } } return(Ok()); }
public async Task <IHttpActionResult> PutRequestedGroup(int id, RequestedGroup requestedGroup) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Group group = db.Groups.Find(requestedGroup.IdGroup); group.TotalComponentes++; if (group == null) { return(NotFound()); } var integrantes = db.PlayerGroups.Where(x => x.IdGroup == requestedGroup.IdGroup).Select(x => x.Player).AsEnumerable().ToArray(); // Checar se o grupo está em sua capacidade máxima if (integrantes.Length >= group.Capacity) { return(BadRequest(message: "O grupo está em sua capacidade máxima")); } // Checar se o player já está naquele grupo Player p1 = integrantes.FirstOrDefault(x => x.ID == requestedGroup.IdPlayer); if (p1 != null) { requestedGroup.Status = "F"; db.Entry(requestedGroup).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (Exception e) { Console.WriteLine(e.Message); } return(BadRequest(message: "O jogador já se encontra nesse grupo. Removendo solicitação...")); } PlayerGroup pg = null; if (requestedGroup.Status == "T") { pg = new PlayerGroup() { CreateAt = DateTime.UtcNow, AlteredAt = DateTime.UtcNow, IdGroup = group.ID, IdPlayer = requestedGroup.IdPlayer }; } requestedGroup.Status = "F"; db.PlayerGroups.Add(pg); try { await db.SaveChangesAsync(); } catch (Exception e) { Console.Write(e.Message); } db.Entry(requestedGroup).State = EntityState.Modified; db.Entry(group).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RequestedGroupExists(id)) { return(NotFound()); } else { throw; } } catch (Exception e) { Console.WriteLine(e.Message); } return(Ok(requestedGroup)); }
public async Task <IHttpActionResult> PutRequestedMatch(RequestedMatch requestedMatch) { int id; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var req2 = db.Set <RequestedMatch>().FirstOrDefault(req => req.IdPlayer1 == requestedMatch.IdPlayer1 && req.IdPlayer2 == requestedMatch.IdPlayer2); if (req2 == null) { return(BadRequest()); } id = req2.ID; requestedMatch.ID = id; if (id != requestedMatch.ID) { return(BadRequest()); } if (requestedMatch.Status != "A") { bool deuMatch = requestedMatch.Status == "M" ? true : false; Match match = new Match() { ID = 0, IdPlayer1 = requestedMatch.IdPlayer1, IdPlayer2 = requestedMatch.IdPlayer2, Status = deuMatch, Weight = 0, CreateAt = DateTime.UtcNow, AlteredAt = DateTime.UtcNow }; db.Matches.Add(match); } db.Entry(req2).State = EntityState.Detached; db.Entry(requestedMatch).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RequestedMatchExists(id)) { return(NotFound()); } else { throw; } } return(Ok()); }