public async Task <IActionResult> PostAdventureSession([FromBody] AdventureSession adventureSession) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.AdventureSession.Add(adventureSession); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (AdventureSessionExists(adventureSession.TeamID)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtAction("GetAdventureSession", new { id = adventureSession.TeamID }, adventureSession)); }
public async Task <IActionResult> PutAdventureSession([FromRoute] int teamID, [FromRoute] int adventureID, [FromBody] AdventureSession adventureSession) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } AdventureSession ExistingAdventureSession = await _context.AdventureSession.Where(ads => ads.TeamID == teamID) .Where(ads => ads.AdventureID == adventureID).FirstOrDefaultAsync(); if (ExistingAdventureSession != null) { ExistingAdventureSession.WaypointID = adventureSession.WaypointID; } try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (ExistingAdventureSession == null) { return(NotFound()); } else { throw; } } return(NoContent()); }