public async Task <IActionResult> PutBoardGame([FromRoute] int id, [FromBody] BoardGame boardGame) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != boardGame.Id) { return(BadRequest()); } _context.Entry(boardGame).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BoardGameExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task UpdateGameAsync(int id, UpdateBoardGameRequest gameToUpdate) { var dbGames = await dbContext.BoardGames.Where(g => g.Id == id).ToArrayAsync(); if (dbGames.Length == 0) { throw new RequestedResourceNotFoundException(); } var dbGame = dbGames[0]; mapper.Map(gameToUpdate, dbGame); dbGame.Modified = DateTime.Now; dbContext.Entry(dbGames[0]).State = EntityState.Modified; await dbContext.SaveChangesAsync(); }