示例#1
0
        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());
        }
示例#2
0
        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();
        }