public IActionResult Purchase() { string shoppingCartJson = HttpContext.Session.GetString("CartSession"); shoppingCart = JsonConvert.DeserializeObject <List <Item> >(shoppingCartJson); string userJson = HttpContext.Session.GetString("LoginSession"); User thisUser = JsonConvert.DeserializeObject <User>(userJson); float cost = 0; foreach (Item item in shoppingCart) { cost += item.Price; } if (thisUser.Funds >= cost) { float remainingFunds = ((thisUser.Funds) - cost); thisUser.Funds = (remainingFunds); _context.Update(thisUser); _context.SaveChanges(); TempData["Receipt"] = $"Purchase cost: ${cost}, Remaining funds: ${remainingFunds}"; return(RedirectToAction("Receipt")); } else { TempData["Funds"] = $"Insufficient Funds: available:${thisUser.Funds}, required:${cost}"; return(View("Error")); } }