public async Task <IActionResult> PutGame(int id, [FromBody] Exam.Data.Game game) { if (id != game.Id) { return(BadRequest()); } _context.Entry(game).State = EntityState.Modified; if (game.GameStatus != null) { game.GameStatus = _context.GameStatuses.Where(u => u.Name == game.GameStatus.Name).FirstOrDefault(); } for (int i = 0; i < game.Maps.Count; ++i) { game.Maps[i].Owner = _context.Users.Find(game.Maps[i].Owner.Id); game.Maps[i].Game = game; } await _context.Maps.AddRangeAsync(game.Maps); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GameExist(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Exam.Data.Game> > PostGame(Exam.Data.Game game) { if (game == null) { return(BadRequest()); } _context.Games.Add(game); await _context.SaveChangesAsync(); return(CreatedAtAction("GetGame", new { id = game.Id }, game)); }
public async Task <IActionResult> OnPostAsync() { var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); var user_find = _context.Users.Include(u => u.Game).Where(u => u.Id == userId); var user = user_find.FirstOrDefault(); this.disableGame(); List <Exam.Data.User> users = new List <Exam.Data.User>(); users.Add((Exam.Data.User)user); var game = new Exam.Data.Game { Users = users, GameStatus = _context.GameStatuses.Find(3), UserTurnId = user.Id, }; Game = game; _context.Games.Add(game); _context.SaveChanges(); return(Redirect("/Game/Game?id=" + Game.Id)); }
public async Task <IActionResult> PutGame(int id, [FromBody] Exam.Data.Game game) { if (id != game.Id) { return(BadRequest()); } _context.Entry(game).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GameExist(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }