public ActionResult RemoveCartProduct(int CartProductId) { CMember member = (CMember)Session[CMemberSession.Session_Login_User]; CCartVM currentCart = CCartVM.GetCurrentCart(member); CCartProduct CartProduct = currentCart.lscartprooduct.FirstOrDefault(p => p.fCartProductId == CartProductId); CCartProductFactory.fn購物車商品刪除(CartProduct); return(RedirectToAction("CartView")); }
public ActionResult CartClear(int CartId) { CMember member = (CMember)Session[CMemberSession.Session_Login_User]; CCartVM currentCart = CCartVM.GetCurrentCart(member); foreach (var item in currentCart.lscartprooduct.Where(p => p.fCartId == CartId)) { CCartProductFactory.fn購物車商品刪除(item); } return(RedirectToAction("CartView")); }
public ActionResult RemoveFromCart(int CartProductId) { //登入的會員資訊 CMember member = (CMember)Session[CMemberSession.Session_Login_User]; //目前購物車Session的項目 CCartVM currentCart = CCartVM.GetCurrentCart(member); //商品資訊,給fn購物車商品刪除()使用 CCartProduct CartProduct = currentCart.lscartprooduct.FirstOrDefault(p => p.fCartProductId == CartProductId); CCartProductFactory.fn購物車商品刪除(CartProduct); return(PartialView("_CartPartial")); }
//GET:檢視購物車詳細列表 public ActionResult CartView() { //登入的會員資訊 CMember member = (CMember)Session[CMemberSession.Session_Login_User]; //防止未登入者進入 if (member == null) { return(RedirectToAction("../Member/Login")); } //目前購物車Session的項目 CCartVM currentCart = CCartVM.GetCurrentCart(member); return(View(currentCart)); }
public ActionResult AddToCart(int ProductId) { //登入的會員資訊 CMember member = (CMember)Session[CMemberSession.Session_Login_User]; //目前購物車Session的項目 CCartVM currentCart = CCartVM.GetCurrentCart(member); //商品資訊,給fn購物車商品新增()使用 CProduct product = CProductFactory.fn商品查詢().FirstOrDefault(p => p.fProductId == ProductId); //判斷商品是否已在Cart內 if (currentCart.lscartprooduct.Any(p => p.fProductId == product.fProductId)) { return(View("Index", "ShoppingHome")); } else { //不存在購物車內,則新增一筆 CCartProductFactory.fn購物車商品新增(product, currentCart.mycart); } return(PartialView("_CartPartial")); }
//GET:下次再買 public ActionResult PurchaseNextTime(int CartProductId) { CMember member = (CMember)Session[CMemberSession.Session_Login_User]; CCartVM currentCart = CCartVM.GetCurrentCart(member); CCartProduct CartProduct = currentCart.lscartprooduct.FirstOrDefault(p => p.fCartProductId == CartProductId); //新增購物車 CCart cart = new CCart() { fMemberId = member.fMemberId, fSubmitTime = null }; CCart mycart = CCartFactory.fn購物車新增(member, cart); //新增下次再買的商品到新的購物車 CProduct product = CProductFactory.fn商品查詢().FirstOrDefault(p => p.fProductId == CartProduct.fProductId); CCartProductFactory.fn購物車商品新增(product, mycart); //刪除現在購物車裡的商品 CCartProductFactory.fn購物車商品刪除(CartProduct); return(RedirectToAction("CartView")); }