public async Task <IActionResult> PutRoleGame(int id, RoleGameDTO roleGamedto) { RoleGame roleGame = roleGamedto.Update(_context.RoleGames.Find(id), _context); if (id != roleGame?.Id) { return(BadRequest()); } var oldPlayings = _context.Playings.Where(x => x.RoleGameId == id).ToList(); _context.RemoveRange(oldPlayings); _context.Entry(roleGame).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RoleGameExists(id)) { return(NotFound()); } else { throw; } } roleGamedto.Id = roleGame.Id; return(Ok(roleGamedto)); }
public async Task <ActionResult <RoleGameDTO> > PostRoleGame(RoleGameDTO roleGamedto) { RoleGame roleGame = roleGamedto.Convert(_context); _context.RoleGames.Add(roleGame); try { await _context.SaveChangesAsync(); } catch (Exception) { return(BadRequest()); } roleGamedto.Id = roleGame.Id; return(Ok(roleGamedto)); }