public ActionResult 購物車清單() { if (Session[CSession關鍵字.SK_LOGINED_CUSTOMER] != null) { MotaiDataEntities dbContext = new MotaiDataEntities(); tCustomer cust = Session[CSession關鍵字.SK_LOGINED_CUSTOMER] as tCustomer; List <tStatu> StateList = dbContext.tStatus.Where(c => c.sCustomerId == cust.CustomerId).ToList(); List <StatusCartViewModel> cartList = new List <StatusCartViewModel>(); foreach (var items in StateList) { tPromotion discount = dbContext.tPromotions.Where(p => p.PromotionId == items.sProductId).FirstOrDefault(); tProduct cartProd = dbContext.tProducts.Where(p => p.ProductId == items.sProductId).FirstOrDefault(); StatusCartViewModel cartC = new StatusCartViewModel(); cartC.StatusId = items.StatusId; cartC.pName = cartProd.pName; cartC.pPrice = cartProd.pPrice; cartC.sProductQty = items.sProductQty; cartC.pDiscountCode = discount.pDiscountCode; cartList.Add(cartC); } return(View(cartList)); } else { return(RedirectToAction("首頁")); } }
public ActionResult 購物車清單() { if (Session[CSession關鍵字.SK_LOGINED_CUSTOMER] != null) { MotaiDataEntities dbContext = new MotaiDataEntities(); tCustomer cust = Session[CSession關鍵字.SK_LOGINED_CUSTOMER] as tCustomer; int count = dbContext.tStatus.Where(c => c.sCustomerId == cust.CustomerId).ToList().Count; ViewBag.Count = count + "項"; List <tStatu> StateList = dbContext.tStatus.Where(c => c.sCustomerId == cust.CustomerId).ToList(); List <StatusCartViewModel> cartList = new List <StatusCartViewModel>(); StatusCartGoToPayViewModel Cart = new StatusCartGoToPayViewModel(); foreach (var items in StateList) { tProduct cartProd = dbContext.tProducts.Where(p => p.ProductId == items.sProductId).FirstOrDefault(); StatusCartViewModel cartC = new StatusCartViewModel(); cartC.StatusId = items.StatusId; cartC.ProductId = items.sProductId; cartC.pName = cartProd.pName; cartC.pPrice = cartProd.pPrice; cartC.sProductQty = items.sProductQty; cartList.Add(cartC); } Cart.Carts = cartList; var warehouseNames = commodityRespoitory.GetWarehouseAll(); List <SelectListItem> warehouselist = commodityRespoitory.GetSelectList(warehouseNames); Cart.warehouses = warehouselist; return(View(Cart)); } else { return(RedirectToAction("首頁")); } }