public ActionResult Carts() { IEnumerable <Cart> model = new List <Cart>(); List <Cart> session = new List <Cart>(); try { session = (List <Cart>)Session["Carts"]; if (session != null) { if (User.Identity.IsAuthenticated) { var userId = (User)Session["Id"]; foreach (var VARIABLE in session) { VARIABLE.User_Id = userId.Id; _cartsdb.AddCart(VARIABLE); _cartsdb.Commit(); } model = BusinessLogic.LoadOrdersAndCarts(_cartsdb.GetAllCarts()); return(View(model)); } } else { return(RedirectToAction("NotFound")); } } catch (Exception e) { Console.WriteLine(e); throw; } model = BusinessLogic.LoadOrdersAndCarts(session); return(View(model)); }
public ActionResult Details(int id, int quantity) { if (!ModelState.IsValid) { TempData["message"] = "please please specify a valid quantity"; return(RedirectToAction("Details")); } var model = _dbProducts.GetProduct(id); if (model == null) { return(RedirectToAction("NotFound", "Users")); } var cart = BusinessLogic.MapCart(model); cart.Quantity = quantity; if (User.Identity.IsAuthenticated) { var userId = (User)Session["Id"]; cart.User_Id = userId.Id; _cartsDb.AddCart(cart); if (_cartsDb.Commit()) { BusinessLogic.ListingCarts.Add(cart); Session["Carts"] = BusinessLogic.ListingCarts; return(RedirectToAction("Index", "Home")); } } else { BusinessLogic.ListingCarts.Add(cart); Session["Carts"] = BusinessLogic.ListingCarts; return(RedirectToAction("Index", "Home")); } return(RedirectToAction("NotFound", "Users")); }