Example #1
0
        /// <summary>
        /// 获取虚拟购物车物品
        /// </summary>
        /// <param name="sku"></param>
        /// <param name="exchangeRate"></param>
        /// <returns></returns>
        public CartViewModel GetBuyVirtualCart(string sku, int ping, int proid, decimal?exchangeRate = null)
        {
            var entity = CartBll.GetVirtualCartItemEntity(sku, base.language, base.DeliveryRegion);
            IList <PromotionEntity> promotions = null;

            if (entity != null)
            {
                if (ping == 1)
                {
                    promotions = itemBll.GetPromotionEntitiesTeam(proid);
                }
                else
                {
                    promotions = itemBll.GetPromotionEntities(new[] { sku });
                }
            }

            var itemArray = new ShoppingCartItemEntity[] { entity };

            var items = itemArray.AsProdcutItems(promotions, base.ExchangeRate);


            CartViewModel model = new CartViewModel(base.ExchangeRate)
            {
                Items = items
            };

            return(model);
        }
        public void AddCartItem(string email, ShoppingCartItemInputModel shoppingCartItem, float priceInUsd)
        {
            // Add a cart item to the database
            var user = _dbContext.Users.FirstOrDefault(u => u.Email == email);

            var cartItem = new ShoppingCartItemEntity
            {
                ShoppingCartId    = user.ShoppingCart.Id,
                ProductIdentifier = shoppingCartItem.ProductIdentifier,
                Quantity          = shoppingCartItem.Quantity,
                UnitPrice         = priceInUsd
            };

            _dbContext.ShoppingCartItems.Add(cartItem);
            _dbContext.SaveChanges();
        }
Example #3
0
        /// <summary>
        /// 获取可以销售的商品。
        /// </summary>
        /// <param name="itemEntity"></param>
        /// <returns></returns>
        public static ShoppingCartItemEntity ForSales(this ShoppingCartItemEntity itemEntity, Action <ShoppingCartItemEntity> extra = null)
        {
            if (itemEntity == null || !itemEntity.IsOnSaled)
            {
                return(null);
            }

            if (itemEntity.ForOrderQty - itemEntity.CartQuantity < 0)
            {
                return(null);
            }

            ShoppingCartItemEntity forSale = itemEntity.Clone();


            if (extra != null)
            {
                extra(forSale);
            }

            return(forSale);
        }
Example #4
0
        async Task IShoppingCartService.AddToCart(string SessionCartId, int productId)
        {
            var shoppingCartItem =
                await _context.ShoppingCartItems.SingleOrDefaultAsync(
                    s => s.ProductId == productId && s.SessionCartId == SessionCartId);

            if (shoppingCartItem == null)
            {
                shoppingCartItem = new ShoppingCartItemEntity
                {
                    SessionCartId = SessionCartId,
                    ProductId     = productId,
                    Quantity      = 1,
                    CreatedAt     = DateTime.Now,
                };

                _context.ShoppingCartItems.Add(shoppingCartItem);
            }
            else
            {
                shoppingCartItem.Quantity++;
            }
            await _context.SaveChangesAsync();
        }