public IActionResult EditChore(Chore editedChore) { Chore dbChore = _context.Chore.Find(editedChore.ChoreId); if (ModelState.IsValid) { dbChore.PointValue = editedChore.PointValue; dbChore.ChoreName = editedChore.ChoreName; dbChore.ChoreDescription = editedChore.ChoreDescription; dbChore.DueDate = editedChore.DueDate; _context.Entry(dbChore).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _context.Update(dbChore); _context.SaveChanges(); } return(RedirectToAction("ViewChores")); }
public IActionResult Result(string selection, string answer, int points) { Helper helper = new Helper(_contextAccessor); var player = helper.PopulateFromSession(); var foundPlayer = _context.Player.Find(player.UserId); string outcome; //evaluates Player selection. Awards points if correct, and increments WrongAnswer if incorrect if (selection == answer) { if (ModelState.IsValid) { foundPlayer.CurrentPoints += points; foundPlayer.TotalPoints += points; foundPlayer.CorrectAnswers += 1; _context.Entry(foundPlayer).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _context.Update(foundPlayer); _context.SaveChanges(); } outcome = ($"Correct! you earned {points} points!"); return(View("Result", outcome)); } else { if (ModelState.IsValid) { foundPlayer.IncorrectAnswers += 1; _context.Entry(foundPlayer).State = Microsoft.EntityFrameworkCore.EntityState.Modified; //here _context.Update(foundPlayer); // _context.SaveChanges(); //here } outcome = $"Incorrect. The correct answer was \"{answer}\""; return(View("Result", outcome)); } }