public async Task <IActionResult> PutHighscore(int id, Highscore highscore) { if (id != highscore.ID) { return(BadRequest()); } _context.Entry(highscore).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!HighscoreExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async void GetEmptyList() { _context.HighscoreLists.RemoveRange(_controller.Get()); await _context.SaveChangesAsync(); Assert.Equal(0, _context.HighscoreLists.Count()); }
public async Task <ActionResult <Highscore> > PostHighscore(Captcha captcha) { // if (CheckCaptcha(captcha.captcha)) // { if (_context.HighscoreLists.Count() >= 10) { var lastHighscore = _context.HighscoreLists.OrderByDescending(h => h.Score).Last(); if (lastHighscore.Score < captcha.Highscore.Score) { _context.HighscoreLists.Remove(lastHighscore); } else { return(BadRequest("This score is not a highscore")); } } _context.HighscoreLists.Add(captcha.Highscore); await _context.SaveChangesAsync(); return(CreatedAtAction("GetHighScore", new { id = captcha.Highscore.HighScoreId }, captcha.Highscore)); /* } * else * { * return BadRequest("You are a bot!"); * } */ }