public async Task <IActionResult> PutHighScoreViewModel([FromRoute] int id, [FromBody] HighScoreViewModel highScoreViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != highScoreViewModel.ScoreId) { return(BadRequest()); } _context.Entry(highScoreViewModel).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!HighScoreViewModelExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PostHighScoreViewModel([FromBody] HighScoreViewModel highScoreViewModel) { if (!ModelState.IsValid) { _logger.LogWarning("Model state invalid"); return(BadRequest(ModelState)); } _context.HighScoreViewModel.Add(highScoreViewModel); await _context.SaveChangesAsync(); _logger.LogInformation("New High score successfully created "); return(CreatedAtAction("GetHighScoreViewModel", new { id = highScoreViewModel.ScoreId }, highScoreViewModel)); }