Exemplo n.º 1
0
        private WaitCreateOrder ConvertToWaitCreateOrder(Cart cart, SellingPriceCart sellingPriceCart, ShippingAddress shippingAddress, PaymentMethod paymentMethod, Express express, Coupon coupon)
        {
            var orderItems = new List <WaitCreateOrderItem>();

            foreach (var sellingPriceFullGroup in sellingPriceCart.FullGroups)
            {
                foreach (var sellingPriceCartItem in sellingPriceFullGroup.CartItems)
                {
                    var cartItem = cart.GetCartItem(sellingPriceCartItem.ProductId);
                    var product  = DomainRegistry.ProductService().GetProduct(cartItem.ID);

                    var unitPrice = cartItem.UnitPrice - sellingPriceCartItem.ReducePrice;
                    orderItems.Add(new WaitCreateOrderItem(sellingPriceCartItem.ProductId, cartItem.Quantity, unitPrice, sellingPriceFullGroup.MultiProductsPromotionId, product.SaleName));
                }
            }

            foreach (var sellingPriceCartItem in sellingPriceCart.CartItems)
            {
                var cartItem = cart.GetCartItem(sellingPriceCartItem.ProductId);
                var product  = DomainRegistry.ProductService().GetProduct(cartItem.ID);

                orderItems.Add(new WaitCreateOrderItem(sellingPriceCartItem.ProductId, cartItem.Quantity, cartItem.UnitPrice, null, product.SaleName));
            }

            return(new WaitCreateOrder(cart.ID, cart.UserId, shippingAddress.Receiver, shippingAddress.CountryId, shippingAddress.CountryName, shippingAddress.ProvinceId, shippingAddress.ProvinceName, shippingAddress.CityId, shippingAddress.CityName, shippingAddress.DistrictId, shippingAddress.DistrictName, shippingAddress.Address, shippingAddress.Mobile, shippingAddress.Phone, shippingAddress.Email, paymentMethod.ID, paymentMethod.Name, express.ID, express.Name, express.Freight, coupon.ID, coupon.Name, coupon.Value, DateTime.Now, orderItems));
        }
Exemplo n.º 2
0
        private CartItemDTO ConvertToCartItem(SellingPriceCartItem sellingPriceCartItem, CartItem cartItem)
        {
            var product = DomainRegistry.ProductService().GetProduct(cartItem.ID);

            return(new CartItemDTO
            {
                ProductId = cartItem.ID,
                ProductName = product == null ? "商品已失效" : product.SaleName,
                ReducePrice = sellingPriceCartItem.ReducePrice,
                SalePrice = cartItem.UnitPrice
            });
        }
Exemplo n.º 3
0
        public async Task Buy(Guid userId, Guid productId, int quantity)
        {
            var product = DomainRegistry.ProductService().GetProduct(productId);

            if (product == null)
            {
                throw new NotFoundException("对不起,未能获取产品信息,请重试~");
            }

            var cart = DomainRegistry.MarketService().GetCartOfUser(userId);

            cart.AddCartItem(productId, quantity, product.Price);
            await DomainRegistry.Repository <ICartRepository>().SaveAsync <Guid, Domain.Market.Cart>(cart, true);
        }
Exemplo n.º 4
0
        public Result Buy(string userId, string productId, int quantity)
        {
            var product = DomainRegistry.ProductService().GetProduct(productId);

            if (product == null)
            {
                return(Result.Fail("对不起,未能获取产品信息请重试~"));
            }

            var cart = _confirmUserCartExistedDomainService.GetUserCart(userId);

            cart.AddCartItem(productId, quantity, product.SalePrice);
            DomainRegistry.CartRepository().Save(cart);
            return(Result.Success());
        }