public ActionResult AddedToCart(string skuId) { long userId = CurrentUser != null ? CurrentUser.Id : 0; try { string productId = skuId.Split('_')[0]; ViewBag.ProductId = productId; var productService = _iProductService; var cart = cartHelper.GetCart(userId); ProductInfo product; SKUInfo sku; var products = cart.Items.Select(item => { product = productService.GetProduct(item.ProductId); sku = productService.GetSku(item.SkuId); return(new CartItemModel() { skuId = item.SkuId, id = product.Id, imgUrl = product.ImagePath + "/1_50.png", name = product.ProductName, price = sku.SalePrice, count = item.Quantity }); }); ViewBag.Current = products.FirstOrDefault(item => item.skuId == skuId); ViewBag.Others = products.Where(item => item.skuId != skuId); ViewBag.Amount = products.Sum(item => item.price * item.count); ViewBag.TotalCount = products.Sum(item => item.count); } catch { } return(View("AddToCart")); }
public ActionResult CartSummary() { var cart = CartHelper.GetCart(_context.Users.SingleOrDefault(u => u.Email == System.Web.HttpContext.Current.User.Identity.Name)); ViewData["CartCount"] = cart.GetCount(); return(PartialView("CartSummary")); }
public ActionResult RemoveFromCart(int id) { // Remove the item from the cart var cart = CartHelper.GetCart(_context.Users.SingleOrDefault(u => u.Email == System.Web.HttpContext.Current.User.Identity.Name)); // Get the name of the album to display confirmation string albumName = _context.CartItems .Single(item => item.BundleID == id).Bundle.Name; // Remove from cart int itemCount = cart.RemoveFromCart(id); // Display the confirmation message var results = new ShoppingCartRemoveViewModel { Message = Server.HtmlEncode(albumName) + " has been removed from your shopping cart.", CartTotal = cart.GetTotal(), CartCount = cart.GetCount(), BundleCount = itemCount, DeleteId = id }; return(Json(results)); }
public ActionResult AddressAndPayment(FormCollection values) { var order = new Orders(); var record = new Records(); var user = _context.Users.SingleOrDefault(u => u.Email == System.Web.HttpContext.Current.User.Identity.Name); TryUpdateModel(order); try { order.Username = User.Identity.Name; order.OrderDate = DateTime.Now; //Save Order _context.Orders.Add(order); _context.SaveChanges(); //Process the order var cart = CartHelper.GetCart(user); record.OrderId = _context.Orders.AsEnumerable().Last().OrderId; record.UserId = user.Id; cart.CreateOrder(record); return(RedirectToAction("Complete", new { id = order.OrderId })); } catch { //Invalid - redisplay with errors return(View(order)); } }
// GET: Carts public ActionResult AddItemToCart(int ItemId, int qty) { var cart = carthelper.GetCart(); var cartId = cart.CartNumber; var item = db.Items.FirstOrDefault(u => u.Id == ItemId); if (item.Qty >= qty) { carthelper.AddItem(ItemId, qty, cartId); return(RedirectToAction("MyCart", "CartItems")); } else { return(RedirectToAction("OutofStock", "Items")); } }
public double GetCouponDiscount(CartHelper.CartExamples cartExample, int productPrice10Quantity, int productPrice250Quantity, int productPrice50Quantity, bool applyCoupon) { Cart cart = CartHelper.GetCart(cartExample, productPrice10Quantity, productPrice250Quantity, productPrice50Quantity); if (applyCoupon) { Coupon coupon = new RateCoupon("100 TL üzeri %20 İndirim", 100, 20); cart.ApplyCoupon(coupon); } return(cart.GetCouponDiscount()); }
public double GetCartTotalAmountAfterDiscounts(CartHelper.CartExamples cartExample, int productFirstQuantity, int productSecondQuantity, int productThirdQuantity, bool applyCoupon) { Cart cart = CartHelper.GetCart(cartExample, productFirstQuantity, productSecondQuantity, productThirdQuantity); if (applyCoupon) { Coupon coupon = new RateCoupon("100 TL üzeri %20 İndirim", 100, 20); cart.ApplyCoupon(coupon); } return(cart.GetCartTotalAmountAfterDiscounts()); }
// GET: /Store/AddToCart/5 public ActionResult AddToCart(int id) { // Retrieve the album from the database var addedBundle = _context.Bundles .Single(bundle => bundle.Id == id); // Add it to the shopping cart var cart = CartHelper.GetCart(_context.Users.SingleOrDefault(u => u.Email == System.Web.HttpContext.Current.User.Identity.Name)); cart.AddToCart(addedBundle); // Go back to the main store page for more shopping return(RedirectToAction("Index")); }
// GET api/<controller>/5 public CartDetailsModel Get(Guid CartID) { try { _cartHelper = new CartHelper(); return(_cartHelper.GetCart(CartID)); } catch (Exception ex) { return(null); } }
public ActionResult Index() { var cart = CartHelper.GetCart(_context.Users.SingleOrDefault(u => u.Email == System.Web.HttpContext.Current.User.Identity.Name)); // Set up our ViewModel var viewModel = new ShoppingCartViewModel { CartItems = cart.GetCartItems(), CartTotal = cart.GetTotal() }; // Return the view return(View(viewModel)); }
public ActionResult Create(VisitsViewModel model) { if (ModelState.IsValid) { Visit one = new Visit(); one.Status = "Oczekująca"; one.TestsId = CartHelper.GetCart(); one.dateTime = model.Date; one.User = _user.FindByIdAsync(_user.GetUserId(HttpContext.User)).Result; _visits.Add(one); CartHelper.ResetCart(); } ViewBag.Save = 1; return(RedirectToAction("Create")); }
public ActionResult AddedToCart(string skuId) { ProductInfo productInfo = null; SKUInfo sKUInfo = null; long num = (base.CurrentUser != null ? base.CurrentUser.Id : 0); try { CartHelper cartHelper = new CartHelper(); string str = skuId; char[] chrArray = new char[] { '\u005F' }; string str1 = str.Split(chrArray)[0]; ViewBag.ProductId = str1; IProductService productService = ServiceHelper.Create <IProductService>(); ShoppingCartInfo cart = cartHelper.GetCart(num); IEnumerable <CartItemModel> cartItemModels = cart.Items.Select <ShoppingCartItem, CartItemModel>((ShoppingCartItem item) => { productInfo = productService.GetProduct(item.ProductId); sKUInfo = productService.GetSku(item.SkuId); return(new CartItemModel() { skuId = item.SkuId, id = productInfo.Id, imgUrl = string.Concat(productInfo.ImagePath, "/1_50.png"), name = productInfo.ProductName, price = sKUInfo.SalePrice, count = item.Quantity }); }); base.ViewBag.Current = cartItemModels.FirstOrDefault((CartItemModel item) => item.skuId == skuId); base.ViewBag.Others = from item in cartItemModels where item.skuId != skuId select item; base.ViewBag.Amount = cartItemModels.Sum <CartItemModel>((CartItemModel item) => item.price * item.count); base.ViewBag.TotalCount = cartItemModels.Sum <CartItemModel>((CartItemModel item) => item.count); } catch { } return(View("AddToCart")); }
public JsonResult GetCartProducts() { var cartHelper = new CartHelper(); var cart = cartHelper.GetCart(CurrentUser.Id); var productService = _iProductService; var shopService = _iShopService; var vshopService = _iVShopService; //会员折扣 decimal discount = 1.0M;//默认折扣为1(没有折扣) if (CurrentUser != null) { discount = CurrentUser.MemberDiscount; } List <long> pids = new List <long>(); decimal prodPrice = 0.0M; //优惠价格 var limitProducts = LimitTimeApplication.GetPriceByProducrIds(cart.Items.Select(e => e.ProductId).ToList()); //限时购价格 var products = cart.Items.Select(item => { var product = productService.GetProduct(item.ProductId); var shop = shopService.GetShop(product.ShopId); SKUInfo sku = null; string colorAlias = ""; string sizeAlias = ""; string versionAlias = ""; string skuDetails = ""; if (null != shop) { var vshop = vshopService.GetVShopByShopId(shop.Id); sku = productService.GetSku(item.SkuId); if (sku == null) { return(null); } //处理限时购、会员折扣价格 var prod = limitProducts.FirstOrDefault(e => e.ProductId == item.ProductId); prodPrice = sku.SalePrice; if (prod != null) { prodPrice = prod.MinPrice; } else { if (shop.IsSelf) {//官方自营店才计算会员折扣 prodPrice = sku.SalePrice * discount; } } var typeInfo = TypeApplication.GetType(product.TypeId); colorAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias; sizeAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias; versionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias; skuDetails = ""; if (!string.IsNullOrWhiteSpace(sku.Size)) { skuDetails += sizeAlias + ":" + sku.Size + " "; } if (!string.IsNullOrWhiteSpace(sku.Color)) { skuDetails += colorAlias + ":" + sku.Color + " "; } if (!string.IsNullOrWhiteSpace(sku.Version)) { skuDetails += versionAlias + ":" + sku.Version + " "; } return(new { cartItemId = item.Id, skuId = item.SkuId, id = product.Id, imgUrl = Himall.Core.HimallIO.GetProductSizeImage(product.RelativePath, 1, (int)ImageSize.Size_150), name = product.ProductName, price = prodPrice, count = item.Quantity, shopId = shop.Id, vshopId = vshop == null ? 0 : vshop.Id, shopName = shop.ShopName, shopLogo = vshop == null ? "" : vshop.Logo, status = (product.AuditStatus == ProductInfo.ProductAuditStatus.Audited && product.SaleStatus == ProductInfo.ProductSaleStatus.OnSale) ? 1 : 0, Size = sku.Size, Color = sku.Color, Version = sku.Version, ColorAlias = colorAlias, SizeAlias = sizeAlias, VersionAlias = versionAlias, skuDetails = skuDetails, AddTime = item.AddTime }); } else { return(null); } }).Where(d => d != null).OrderBy(s => s.vshopId).ThenByDescending(o => o.AddTime); var cartModel = new { products = products, amount = products.Sum(item => item.price * item.count), totalCount = products.Sum(item => item.count) }; return(Json(cartModel)); }
public JsonResult UpdateCartItem(string skuId, int count) { //TODO:FG 购物车改造 购物车数量变更 long userId = CurrentUser != null ? CurrentUser.Id : 0; var cartHelper = new CartHelper(); var skucart = cartHelper.GetCart(userId).Items.FirstOrDefault(d => d.SkuId == skuId); bool isadd = true; if (skucart != null) { if (skucart.Quantity > count) { isadd = false; } } Entities.SKUInfo skuinfo = OrderApplication.GetSkuByID(skuId); if (skuinfo.Stock < count && isadd) { return(Json(new { success = false, msg = "库存不足", stock = skuinfo.Stock })); } var product = ProductManagerApplication.GetProduct(skuinfo.ProductId); if (product != null) { if (product.MaxBuyCount > 0 && count > product.MaxBuyCount && !product.IsOpenLadder) { return(Json(new { success = false, msg = string.Format("每个ID限购{0}件", product.MaxBuyCount), stock = product.MaxBuyCount })); } } cartHelper.UpdateCartItem(skuId, count, userId); #region 购物车修改数量阶梯价变动--张宇枫 //获取产品详情 var price = 0m; if (product.IsOpenLadder) { var shop = ShopApplication.GetShop(product.ShopId); var groupCartByProduct = cartHelper.GetCart(userId).Items.Where(item => item.ShopBranchId == 0).Select(c => { var cItem = new Himall.Entities.ShoppingCartItem(); var skuInfo = _iProductService.GetSku(c.SkuId); if (skuInfo != null) { cItem = c; } return(cItem); }).GroupBy(i => i.ProductId).ToList(); var quantity = groupCartByProduct.Where(i => i.Key == product.Id).ToList().Sum(cartitem => cartitem.Sum(i => i.Quantity)); decimal discount = 1M; if (CurrentUser != null) { discount = CurrentUser.MemberDiscount; } price = ProductManagerApplication.GetProductLadderPrice(product.Id, quantity); if (shop.IsSelf) { price = price * discount; } } #endregion return(SuccessResult <dynamic>(data: new { saleprice = price.ToString("F2"), productid = product.Id, isOpenLadder = product.IsOpenLadder })); }
public double GetProductCount(CartHelper.CartExamples cartExample, int productPrice10Quantity, int productPrice250Quantity, int productPrice50Quantity) { Cart cart = CartHelper.GetCart(cartExample, productPrice10Quantity, productPrice250Quantity, productPrice50Quantity); return(cart.ProductCount); }
public double GetCartAmountAfterCampaignDiscount(CartHelper.CartExamples cartExample, int productPrice10Quantity, int productPrice250Quantity, int productPrice50Quantity) { Cart cart = CartHelper.GetCart(cartExample, productPrice10Quantity, productPrice250Quantity, productPrice50Quantity); return(cart.GetCartAmountAfterCampaignDiscount()); }
private void GetOrderProductsInfo(string cartItemIds) { CartHelper cartHelper = new CartHelper(); IEnumerable <ShoppingCartItem> cartItems = null; if (!string.IsNullOrWhiteSpace(cartItemIds)) { char[] chrArray = new char[] { ',' }; IEnumerable <long> nums = from t in cartItemIds.Split(chrArray) select long.Parse(t); cartItems = ServiceHelper.Create <ICartService>().GetCartItems(nums); } else { cartItems = cartHelper.GetCart(base.CurrentUser.Id).Items; } int cityId = 0; ShippingAddressInfo defaultUserShippingAddressByUserId = ServiceHelper.Create <IShippingAddressService>().GetDefaultUserShippingAddressByUserId(base.CurrentUser.Id); if (defaultUserShippingAddressByUserId != null) { cityId = Instance <IRegionService> .Create.GetCityId(defaultUserShippingAddressByUserId.RegionIdPath); } IProductService productService = ServiceHelper.Create <IProductService>(); IShopService shopService = ServiceHelper.Create <IShopService>(); List <CartItemModel> list = cartItems.Select <ShoppingCartItem, CartItemModel>((ShoppingCartItem item) => { ProductInfo product = productService.GetProduct(item.ProductId); SKUInfo sku = productService.GetSku(item.SkuId); return(new CartItemModel() { skuId = item.SkuId, id = product.Id, imgUrl = product.GetImage(ProductInfo.ImageSize.Size_100, 1), name = product.ProductName, price = sku.SalePrice, shopId = product.ShopId, count = item.Quantity }); }).ToList(); IEnumerable <IGrouping <long, CartItemModel> > groupings = from a in list group a by a.shopId; List <ShopCartItemModel> shopCartItemModels = new List <ShopCartItemModel>(); foreach (IGrouping <long, CartItemModel> nums1 in groupings) { IEnumerable <long> nums2 = from r in nums1 select r.id; IEnumerable <int> nums3 = from r in nums1 select r.count; ShopCartItemModel shopCartItemModel = new ShopCartItemModel() { shopId = nums1.Key }; if (ServiceHelper.Create <IVShopService>().GetVShopByShopId(shopCartItemModel.shopId) != null) { shopCartItemModel.vshopId = ServiceHelper.Create <IVShopService>().GetVShopByShopId(shopCartItemModel.shopId).Id; } else { shopCartItemModel.vshopId = 0; } shopCartItemModel.CartItemModels = ( from a in list where a.shopId == shopCartItemModel.shopId select a).ToList(); shopCartItemModel.ShopName = shopService.GetShop(shopCartItemModel.shopId, false).ShopName; if (cityId > 0) { shopCartItemModel.Freight = ServiceHelper.Create <IProductService>().GetFreight(nums2, nums3, cityId); } List <ShopBonusReceiveInfo> detailToUse = ServiceHelper.Create <IShopBonusService>().GetDetailToUse(shopCartItemModel.shopId, base.CurrentUser.Id, nums1.Sum <CartItemModel>((CartItemModel a) => a.price * a.count)); List <CouponRecordInfo> userCoupon = ServiceHelper.Create <ICouponService>().GetUserCoupon(shopCartItemModel.shopId, base.CurrentUser.Id, nums1.Sum <CartItemModel>((CartItemModel a) => a.price * a.count)); if (detailToUse.Count() > 0 && userCoupon.Count() > 0) { ShopBonusReceiveInfo shopBonusReceiveInfo = detailToUse.FirstOrDefault(); CouponRecordInfo couponRecordInfo = userCoupon.FirstOrDefault(); decimal?price = shopBonusReceiveInfo.Price; decimal num = couponRecordInfo.ChemCloud_Coupon.Price; if ((price.GetValueOrDefault() <= num ? true : !price.HasValue)) { shopCartItemModel.Coupon = new CouponModel() { CouponName = couponRecordInfo.ChemCloud_Coupon.CouponName, CouponId = couponRecordInfo.Id, CouponPrice = couponRecordInfo.ChemCloud_Coupon.Price, Type = 0 }; } else { shopCartItemModel.Coupon = new CouponModel() { CouponName = shopBonusReceiveInfo.ChemCloud_ShopBonusGrant.ChemCloud_ShopBonus.Name, CouponId = shopBonusReceiveInfo.Id, CouponPrice = shopBonusReceiveInfo.Price.Value, Type = 1 }; } } else if (detailToUse.Count() <= 0 && userCoupon.Count() <= 0) { shopCartItemModel.Coupon = null; } else if (detailToUse.Count() <= 0 && userCoupon.Count() > 0) { CouponRecordInfo couponRecordInfo1 = userCoupon.FirstOrDefault(); shopCartItemModel.Coupon = new CouponModel() { CouponName = couponRecordInfo1.ChemCloud_Coupon.CouponName, CouponId = couponRecordInfo1.Id, CouponPrice = couponRecordInfo1.ChemCloud_Coupon.Price, Type = 0 }; } else if (detailToUse.Count() > 0 && userCoupon.Count() <= 0) { ShopBonusReceiveInfo shopBonusReceiveInfo1 = detailToUse.FirstOrDefault(); shopCartItemModel.Coupon = new CouponModel() { CouponName = shopBonusReceiveInfo1.ChemCloud_ShopBonusGrant.ChemCloud_ShopBonus.Name, CouponId = shopBonusReceiveInfo1.Id, CouponPrice = shopBonusReceiveInfo1.Price.Value, Type = 1 }; } decimal num1 = shopCartItemModel.CartItemModels.Sum <CartItemModel>((CartItemModel d) => d.price * d.count); decimal num2 = num1 - (shopCartItemModel.Coupon == null ? new decimal(0) : shopCartItemModel.Coupon.CouponPrice); decimal freeFreight = shopService.GetShop(shopCartItemModel.shopId, false).FreeFreight; shopCartItemModel.isFreeFreight = false; if (freeFreight > new decimal(0)) { shopCartItemModel.shopFreeFreight = freeFreight; if (num2 >= freeFreight) { shopCartItemModel.Freight = new decimal(0); shopCartItemModel.isFreeFreight = true; } } shopCartItemModels.Add(shopCartItemModel); } decimal num3 = ( from a in shopCartItemModels where a.Coupon != null select a).Sum <ShopCartItemModel>((ShopCartItemModel b) => b.Coupon.CouponPrice); ViewBag.products = shopCartItemModels; base.ViewBag.totalAmount = list.Sum <CartItemModel>((CartItemModel item) => item.price * item.count); base.ViewBag.Freight = shopCartItemModels.Sum <ShopCartItemModel>((ShopCartItemModel a) => a.Freight); dynamic viewBag = base.ViewBag; dynamic obj = ViewBag.totalAmount; viewBag.orderAmount = obj + ViewBag.Freight - num3; IMemberIntegralService memberIntegralService = ServiceHelper.Create <IMemberIntegralService>(); MemberIntegral memberIntegral = memberIntegralService.GetMemberIntegral(base.CurrentUser.Id); int num4 = (memberIntegral == null ? 0 : memberIntegral.AvailableIntegrals); ViewBag.userIntegrals = num4; ViewBag.integralPerMoney = 0; ViewBag.memberIntegralInfo = memberIntegral; MemberIntegralExchangeRules integralChangeRule = memberIntegralService.GetIntegralChangeRule(); decimal num5 = new decimal(0); decimal num6 = new decimal(0); decimal viewBag1 = (decimal)ViewBag.totalAmount; if (integralChangeRule == null || integralChangeRule.IntegralPerMoney <= 0) { num5 = new decimal(0); num6 = new decimal(0); } else { if (((viewBag1 - num3) - Math.Round((decimal)num4 / integralChangeRule.IntegralPerMoney, 2)) <= new decimal(0)) { num5 = Math.Round(viewBag1 - num3, 2); num6 = Math.Round((viewBag1 - num3) * integralChangeRule.IntegralPerMoney); } else { num5 = Math.Round((decimal)num4 / integralChangeRule.IntegralPerMoney, 2); num6 = num4; } if (num5 <= new decimal(0)) { num5 = new decimal(0); num6 = new decimal(0); } } ViewBag.integralPerMoney = num5; ViewBag.userIntegrals = num6; }
public object GetUpdateToCart(string openId, string SkuID, int Quantity, int GiftID = 0) { //验证用户 CheckUserLogin(); var cartHelper = new CartHelper(); long userId = CurrentUser != null ? CurrentUser.Id : 0; var skus = cartHelper.GetCart(userId); var oldQuantity = GetCartProductQuantity(skus, skuId: SkuID); oldQuantity = oldQuantity + Quantity; long productId = 0; var skuItem = skus.Items.FirstOrDefault(i => i.SkuId == SkuID); if (null == skuItem) { var sku = ProductManagerApplication.GetSKU(SkuID); if (null == sku) { return(Json(ErrorResult <dynamic>("错误的参数:SkuId"))); } productId = sku.ProductId; } else { productId = skuItem.ProductId; } var ladderPrice = 0m; var product = ProductManagerApplication.GetProduct(productId); if (product != null) { if (product.MaxBuyCount > 0 && oldQuantity > product.MaxBuyCount && !product.IsOpenLadder) { cartHelper.UpdateCartItem(SkuID, product.MaxBuyCount, userId); return(Json(ErrorResult <dynamic>(string.Format("每个ID限购{0}件", product.MaxBuyCount), new { stock = product.MaxBuyCount }))); } } SKUInfo skuinfo = OrderApplication.GetSkuByID(SkuID); if (skuinfo.Stock < oldQuantity) { cartHelper.UpdateCartItem(SkuID, Convert.ToInt32(skuinfo.Stock), userId); return(Json(ErrorResult <dynamic>("库存不足", new { stock = skuinfo.Stock }))); } cartHelper.UpdateCartItem(SkuID, oldQuantity, userId); //调用查询购物车数据 #region 阶梯价--张宇枫 var isOpenLadder = product.IsOpenLadder; if (isOpenLadder) { var shop = ShopApplication.GetShop(product.ShopId); var groupCartByProduct = cartHelper.GetCart(userId).Items.Where(item => item.ShopBranchId == 0).GroupBy(i => i.ProductId).ToList(); //var groupCartByProduct = skus.Items.Where(item => item.ShopBranchId == 0).Select(c => //{ // var cItem = new Mall.Entities.ShoppingCartItem(); // var skuInfo = ServiceProvider.Instance<IProductService>.Create.GetSku(c.SkuId); // if (skuInfo != null) // cItem = c; // return cItem; //}).GroupBy(i => i.ProductId).ToList(); var quantity = groupCartByProduct.Where(i => i.Key == productId) .ToList() .Sum(cartitem => cartitem.Sum(i => i.Quantity)); ladderPrice = ProductManagerApplication.GetProductLadderPrice(productId, quantity); if (shop.IsSelf) { ladderPrice = CurrentUser.MemberDiscount * ladderPrice; } } #endregion return(Json(new { Price = ladderPrice.ToString("F2"), ProductId = productId, IsOpenLadder = isOpenLadder ? 1 : 0 })); }
private void GetOrderProductsInfo(string cartItemIds, long?regionId) { ShippingAddressInfo shippingAddressInfo = new ShippingAddressInfo(); shippingAddressInfo = (!regionId.HasValue ? ServiceHelper.Create <IShippingAddressService>().GetDefaultUserShippingAddressByUserId(base.CurrentUser.Id) : ServiceHelper.Create <IShippingAddressService>().GetUserShippingAddress(regionId.Value)); int cityId = 0; if (shippingAddressInfo != null) { cityId = Instance <IRegionService> .Create.GetCityId(shippingAddressInfo.RegionIdPath); } CartHelper cartHelper = new CartHelper(); IEnumerable <ShoppingCartItem> cartItems = null; if (!string.IsNullOrWhiteSpace(cartItemIds)) { char[] chrArray = new char[] { ',' }; IEnumerable <long> nums = from t in cartItemIds.Split(chrArray) select long.Parse(t); cartItems = ServiceHelper.Create <ICartService>().GetCartItems(nums); } else { cartItems = cartHelper.GetCart(base.CurrentUser.Id).Items; } IProductService productService = ServiceHelper.Create <IProductService>(); IShopService shopService = ServiceHelper.Create <IShopService>(); List <CartItemModel> list = cartItems.Select <ShoppingCartItem, CartItemModel>((ShoppingCartItem item) => { ProductInfo product = productService.GetProduct(item.ProductId); SKUInfo sku = productService.GetSku(item.SkuId); return(new CartItemModel() { skuId = item.SkuId, id = product.Id, imgUrl = product.GetImage(ProductInfo.ImageSize.Size_50, 1), name = product.ProductName, price = sku.SalePrice, shopId = product.ShopId, count = item.Quantity, productCode = product.ProductCode }); }).ToList(); IEnumerable <IGrouping <long, CartItemModel> > groupings = from a in list group a by a.shopId; List <ShopCartItemModel> shopCartItemModels = new List <ShopCartItemModel>(); foreach (IGrouping <long, CartItemModel> nums1 in groupings) { IEnumerable <long> nums2 = from r in nums1 select r.id; IEnumerable <int> nums3 = from r in nums1 select r.count; ShopCartItemModel shopCartItemModel = new ShopCartItemModel() { shopId = nums1.Key, Freight = (cityId <= 0 ? new decimal(0) : ServiceHelper.Create <IProductService>().GetFreight(nums2, nums3, cityId)), }; shopCartItemModel.CartItemModels = ( from a in list where a.shopId == shopCartItemModel.shopId select a).ToList(); shopCartItemModel.ShopName = shopService.GetShop(shopCartItemModel.shopId, false).ShopName; shopCartItemModel.UserCoupons = ServiceHelper.Create <ICouponService>().GetUserCoupon(shopCartItemModel.shopId, base.CurrentUser.Id, nums1.Sum <CartItemModel>((CartItemModel a) => a.price * a.count)); shopCartItemModel.UserBonus = ServiceHelper.Create <IShopBonusService>().GetDetailToUse(shopCartItemModel.shopId, base.CurrentUser.Id, nums1.Sum <CartItemModel>((CartItemModel a) => a.price * a.count)); shopCartItemModels.Add(shopCartItemModel); } ViewBag.products = shopCartItemModels; base.ViewBag.totalAmount = list.Sum <CartItemModel>((CartItemModel item) => item.price * item.count); base.ViewBag.Freight = shopCartItemModels.Sum <ShopCartItemModel>((ShopCartItemModel a) => a.Freight); dynamic viewBag = base.ViewBag; dynamic obj = ViewBag.totalAmount; viewBag.orderAmount = obj + ViewBag.Freight; }
public double CalculateDeliveryCost(CartHelper.CartExamples cartExample, int quantity1, int quantity2, int quantity3) { Cart cart = CartHelper.GetCart(cartExample, quantity1, quantity2, quantity3); return(_deliveryService.CalculateDeliveryCost(cart)); }