public ActionResult CancelOrder() { SessionHelper session = new SessionHelper(); string id = session.SessionID; ProductVisitRepo pvr = new ProductVisitRepo(); pvr.removeProductVisit(id); //VisitRepo visitRepo = new VisitRepo(); //visitRepo.removeVisit(id); return(RedirectToAction("Index", "Cart")); }
public ActionResult ViewCart(int productId, int qty) { if (qty < 1) { TempData["error"] = "A positive quantity must be used"; return(RedirectToAction("Add", "Cart", new { id = productId })); } ShoppingCartEntities db = new ShoppingCartEntities(); SessionHelper session = new SessionHelper(); string id = session.SessionID; ProductVisitRepo pvRepo = new ProductVisitRepo(); pvRepo.addProductVisit(id, productId, qty, DateTime.Now); return(RedirectToAction("MyCart", "Cart")); }
public ActionResult ViewCart(int?id) { string sessionID = System.Web.HttpContext.Current.Session.SessionID; if (id != null) { // remove product visit ProductVisitRepo productVisitRepo = new ProductVisitRepo(); productVisitRepo.RemoveProductVisit(sessionID, (int)id); } ShoppingCartRepo cartRepo = new ShoppingCartRepo(); // get all product visit entries IEnumerable <ProductVisit> productVisits = cartRepo.GetCartItems(sessionID); // if have product visit can create a cart item out of it via the naviagtion properties List <ProductVM> products = new List <ProductVM>(); foreach (ProductVisit item in productVisits) { ProductVM product = new ProductVM(item.Product, (int)item.qtyOrdered); product.SetTotalCost(); product.image = item.Product.Image.imageTitle; products.Add(product); } ShoppingCartVM cart = new ShoppingCartVM(products); if (products.Count() > 0) { return(View(cart)); } else { ViewBag.Message = "No cart items selected"; return(View(cart)); } }
public ActionResult Add(ProductVisit productVisitFromForm) { SessionHelper sessionHelper = new SessionHelper(); productVisitFromForm.sessionID = sessionHelper.SessionID; productVisitFromForm.updated = sessionHelper.StartTime; ProductVisitRepo productVisitRepo = new ProductVisitRepo(); if (productVisitFromForm.productID != 0 && productVisitFromForm.sessionID != null) { productVisitRepo.AddOrUpdateProductVisit(productVisitFromForm); } ProductVisit productVisitFromDB = productVisitRepo.GetCartItem(sessionHelper.SessionID, productVisitFromForm.productID); ViewBag.Qty = 1; if (productVisitFromDB.qtyOrdered != 1) { ViewBag.Qty = productVisitFromDB.qtyOrdered; } return(RedirectToAction("ViewCart", new { id = sessionHelper.SessionID })); }
public ActionResult Add(int id) { SessionHelper sessionHelper = new SessionHelper(); ViewBag.SessionID = System.Web.HttpContext.Current.Session.SessionID; ProductVisitRepo productVisitRepo = new ProductVisitRepo(); ProductVisit productVisitFromDB = productVisitRepo.GetCartItem(System.Web.HttpContext.Current.Session.SessionID, id); if (productVisitFromDB != null) { ViewBag.Qty = productVisitFromDB.qtyOrdered; } else { ViewBag.Qty = 1; } ProductRepo productRepo = new ProductRepo(); RedirectToAction("ViewCart"); return(View(productRepo.GetProduct(id))); }