public async Task <IActionResult> PutHighscoreEntry(int id, HighscoreEntry highscoreEntry) { if (id != highscoreEntry.ID) { return(BadRequest()); } _context.Entry(highscoreEntry).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!HighscoreEntryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Highscore> > AddHighscore(Highscore highscore) { if (highscore.Score < 0) { return(BadRequest("Not a highScore")); } var highscores = await _context.Highscores.OrderByDescending(a => a.Score).ToListAsync(); if (highscores.Count < 10) { _context.Highscores.Add(highscore); await _context.SaveChangesAsync(); return(Ok(highscore)); } else { for (int i = 0; i < highscores.Count; i++) { if (highscore.Score > highscores[i].Score) { _context.Remove(highscores.Last()); _context.Add(highscore); await _context.SaveChangesAsync(); return(Ok(highscore)); } } } return(BadRequest("Not a highScore")); }
//[ValidateAntiForgeryToken] public async Task <IActionResult> Create([Bind("Name,Score,Level,Date")] Highscore highscore) { if (ModelState.IsValid && Request.Headers["Token"] == "12414141414") { _context.Add(highscore); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(highscore)); }
public async Task <ActionResult <Highscore> > PostHighscore(Highscore highscore) { _context.Highscores.Add(highscore); await _context.SaveChangesAsync(); return(CreatedAtAction("GetHighscore", new { id = highscore.HighscoreId }, highscore)); }
public async Task Initialize(HighscoreContext context) { context.Players.Add(new Player() { Name = "Caan Dalek" }); await context.SaveChangesAsync(); }
public async void NewHighestHighscore() { dataContext.Highscores.RemoveRange((await controller.GetHighscores()).Value); await dataContext.SaveChangesAsync(); Highscore highscore; for (var i = 1; i < 12; i++) { highscore = new Highscore(); highscore.Score = 100 * i; highscore.Initials = "AS" + i; await controller.AddHighscore(highscore); } highscore = new Highscore(); highscore.Score = 999999; highscore.Initials = "ASD"; await controller.AddHighscore(highscore); var highscores = await controller.GetHighscores(); Assert.Equal(highscore.Score, (await controller.GetHighscores()).Value.ElementAt(0).Score); dataContext.Highscores.RemoveRange((await controller.GetHighscores()).Value); await dataContext.SaveChangesAsync(); }