public IActionResult Return(int?id) { List <Items> bought = new List <Items>(); string email = HttpContext.Session.GetString("Email"); var user = _context.Users.Where(x => x.Email == email).FirstOrDefault(); bought = PurchasedList(user); foreach (Items item in bought) { if (item.ItemId == id) { user.Wallet += item.Price; HttpContext.Session.SetString("Wallet", user.Wallet.ToString()); _context.Users.Update(user); var delete = _context.UserItems.Where(x => x.UserID == user.UserId && x.ItemID == item.ItemId).FirstOrDefault(); _context.UserItems.Remove(delete); var update = _context.Items.Where(x => x.ItemId == id).First(); update.Quantity++; _context.Items.Update(update); _context.SaveChanges(); break; } } return(RedirectToAction("Purchased")); }
public IActionResult MakeNewUser(Users user) { if (!ModelState.IsValid) { return(View()); } DB.Users.Add(user); DB.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult AddFunds(int money) { string email = HttpContext.Session.GetString("Email"); var user = _context.Users.Where(x => x.Email == email).FirstOrDefault(); user.Wallet += money; _context.Users.Update(user); HttpContext.Session.SetString("Wallet", user.Wallet.ToString()); _context.SaveChanges(); return(RedirectToAction("Index", "Items")); }