示例#1
0
 public void PlaceOrder(Guid UserID, AddressDTO addressDTO)
 {
     if (orderDataBaseContext.ItemsExist(UserID))
     {
         Guid AddressID = addressDatabaseContext.AddAddress(UserID, addressDTO);
         CartVariantItemsDTO cartVariantItemsDTO = cartDataBaseContext.GetCart(UserID);
         double subtotal = new double();
         foreach (var cartVariant in cartVariantItemsDTO.CartItems)
         {
             int    OrderQuantity = cartVariant.Quantity;
             double Discount      = cartVariant.Variant.Discount;
             double Price         = cartVariant.Variant.ListingPrice;
             cartVariant.Variant.DiscountedPrice = (Price * (100 - Discount) / 100);
             double DiscountedPrice = cartVariant.Variant.DiscountedPrice;
             subtotal += DiscountedPrice * OrderQuantity;
         }
         cartVariantItemsDTO.SubTotal = subtotal;
         orderDataBaseContext.PlaceOrder(UserID, cartVariantItemsDTO, AddressID);
         productDatabaseContext.UpdateInventory(cartVariantItemsDTO);
         cartDataBaseContext.EmptyCart(UserID);
     }
     else
     {
         throw new CartEmptyException();
     }
 }
        public void PlaceOrder(Guid userID, Guid addressID)
        {
            if (orderDatabaseContext.checkItemsExistInCart(userID))
            {
                CartItemsDTO cartItemsDTO = cartDatabaseContext.GetCart(userID);

                double TotalAmount   = 0;
                double TotalDiscount = 0;
                foreach (var CartProduct in cartItemsDTO.CartItems)
                {
                    int    Quantity = CartProduct.Quantity;
                    double Discount = CartProduct.Variant.Discount;
                    double Price    = CartProduct.Variant.ListingPrice;
                    CartProduct.Variant.DiscountedPrice = (Price * (100 - Discount) / 100);
                    double DiscountedPrice = CartProduct.Variant.DiscountedPrice;
                    TotalAmount   += DiscountedPrice * Quantity;
                    TotalDiscount += Discount * Price / 100;
                }
                cartItemsDTO.TotalAmount   = TotalAmount;
                cartItemsDTO.TotalDiscount = TotalDiscount;
                orderDatabaseContext.PlaceOrder(userID, addressID, cartItemsDTO);
                productDatabaseContext.UpdateInventory(cartItemsDTO);
                cartDatabaseContext.EmptyCart(userID);
            }
            else
            {
                throw new CartEmptyException();
            }
        }
        public bool PlaceOrder(Guid UserID, AddressDTO addressDTO)
        {
            Guid     AddressID = addressDatabaseContext.AddAddress(UserID, addressDTO);
            CartsDTO cartsDTO  = cartDataBaseContext.GetCart(UserID);
            int      subtotal  = new int();

            foreach (var cartVariant in cartsDTO.CartItems)
            {
                int OrderQuantity = cartVariant.OrderQuantity;
                int Discount      = cartVariant.Variant.Product.Discount;
                int Price         = cartVariant.Variant.Product.ListingPrice;
                cartVariant.Variant.Product.DiscountedPrice = (Price * (100 - Discount) / 100);
                int DiscountedPrice = cartVariant.Variant.Product.DiscountedPrice;
                subtotal += DiscountedPrice * OrderQuantity;
            }
            cartsDTO.SubTotal = subtotal;
            orderDataBaseContext.PlaceOrder(UserID, cartsDTO, AddressID);
            productDatabaseContext.UpdateInventory(cartsDTO);
            cartBusinessContext.EmptyCart(UserID);
            return(true);
        }