public IActionResult AddPlayer(Player newPlayer)
 {
     if (ModelState.IsValid)
     {
         //check which IDENTITY user is logged in.
         //do... newPlayer.HouseholdId = (identity stuff)
         _context.Player.Add(newPlayer);
         _context.SaveChanges();
     }
     return(View());
 }
        public IActionResult AddChore(Chore newChore)
        {
            newChore.ChoreStr1 = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            if (ModelState.IsValid)
            {
                _context.Chore.Add(newChore);
                _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));
            }
        }
        public IActionResult AddNewPlayer(Player newPlayer)
        {
            //initialize all Player properties
            newPlayer.PlayerStr1       = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            newPlayer.CurrentPoints    = 0;
            newPlayer.TotalPoints      = 0;
            newPlayer.CorrectAnswers   = 0;
            newPlayer.IncorrectAnswers = 0;
            newPlayer.ChoresComplete   = 0;
            newPlayer.PlayerStr2       = "";
            newPlayer.PlayerInt1       = 0;
            newPlayer.PlayerInt2       = 0;

            _context.Player.Add(newPlayer);
            _context.SaveChanges();
            return(RedirectToAction("Index", "Home"));
        }