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 async Task <CartItemsDTO> getCartItemById(int cartItemId)
        {
            CartItems result = await this.repo.GetCartItemsAsyncById(cartItemId);

            CartItemsDTO cartItem = this.mapper.Map <CartItemsDTO>(result);

            return(cartItem);
        }
Exemplo n.º 3
0
        public CartItemsDTO GetCart(Guid UserID)
        {
            var cartItems = FutureKartDBObject.CartVariantMappings.Where(c => c.CartID == UserID).ToList();

            Debug.WriteLine(FutureKartDBObject.CartVariantMappings.Where(c => c.CartID == UserID).ToList());
            CartItemsDTO cartItemsDTO = new CartItemsDTO();

            cartItemsDTO.CartItems = CartItemsMapper.Map <IEnumerable <CartVariantMapping>, IEnumerable <CartProductsDTO> >(cartItems);
            return(cartItemsDTO);
        }
 public void UpdateInventory(CartItemsDTO cartItemsDTO)
 {
     foreach (CartProductsDTO cartItem in cartItemsDTO.CartItems)
     {
         futureKartEntities.Variants.FirstOrDefault(v => v.ID == cartItem.Variant.ID).Inventory -= cartItem.Quantity;
         Debug.WriteLine(futureKartEntities.Variants.FirstOrDefault(v => v.ID == cartItem.Variant.ID).Inventory);
         futureKartEntities.Variants.FirstOrDefault(v => v.ID == cartItem.Variant.ID).QuantitySold += cartItem.Quantity;
         Debug.WriteLine(futureKartEntities.Variants.FirstOrDefault(v => v.ID == cartItem.Variant.ID).QuantitySold);
         futureKartEntities.Categories.FirstOrDefault(c => c.ID == cartItem.Variant.Product.Category.ID).ProductsSold += cartItem.Quantity;
         Debug.WriteLine(futureKartEntities.Categories.FirstOrDefault(c => c.ID == cartItem.Variant.Product.Category.ID).ProductsSold);
         futureKartEntities.SaveChanges();
     }
     return;
 }
Exemplo n.º 5
0
 /// <summary>
 /// displays cart
 /// </summary>
 /// <returns></returns>
 public ActionResult ViewCart()
 {
     try
     {
         CartItemsDTO       CartInfoDTO        = CartBusinessContextObject.GetCart(new Guid(Session["UserID"].ToString()));
         CartItemsViewModel cartItemsViewModel = new CartItemsViewModel();
         cartItemsViewModel = CartInfoMapper.Map <CartItemsDTO, CartItemsViewModel>(CartInfoDTO);
         return(View(cartItemsViewModel));
     }
     catch (Exception ex)
     {
         return(RedirectToAction("ExceptionCatch", "Static", new { exception = ex.Message }));
     }
 }
Exemplo n.º 6
0
        public static CartDTO PreparePromotionData2()
        {
            CartItemsDTO cartItemsViewModelObj;
            CartDTO      cartViewModelObj = new CartDTO();

            cartViewModelObj.CartId    = 2;
            cartViewModelObj.OrderId   = 2;
            cartViewModelObj.CartItems = new List <CartItemsDTO>();
            //item 1
            cartItemsViewModelObj = new CartItemsDTO();
            cartItemsViewModelObj.OrderLineItemId    = 1;
            cartItemsViewModelObj.SKUId              = "A";
            cartItemsViewModelObj.ProductName        = "Almonds";
            cartItemsViewModelObj.ProductDescription = "California''s handpicked almonds.Best quality.";
            cartItemsViewModelObj.UnitPrice          = 50;
            cartItemsViewModelObj.Quantity           = 3;
            cartViewModelObj.CartItems.Add(cartItemsViewModelObj);
            //item 2
            cartItemsViewModelObj = new CartItemsDTO();
            cartItemsViewModelObj.OrderLineItemId    = 2;
            cartItemsViewModelObj.SKUId              = "B";
            cartItemsViewModelObj.ProductName        = "Cashews";
            cartItemsViewModelObj.ProductDescription = "Cashews with best quality assured.";
            cartItemsViewModelObj.UnitPrice          = 30;
            cartItemsViewModelObj.Quantity           = 5;
            cartViewModelObj.CartItems.Add(cartItemsViewModelObj);
            //item 3
            cartItemsViewModelObj = new CartItemsDTO();
            cartItemsViewModelObj.OrderLineItemId    = 3;
            cartItemsViewModelObj.SKUId              = "C";
            cartItemsViewModelObj.ProductName        = "Walnuts";
            cartItemsViewModelObj.ProductDescription = "Walnuts with no bitter taste.";
            cartItemsViewModelObj.UnitPrice          = 20;
            cartItemsViewModelObj.Quantity           = 1;
            cartViewModelObj.CartItems.Add(cartItemsViewModelObj);
            //item 4
            cartItemsViewModelObj = new CartItemsDTO();
            cartItemsViewModelObj.OrderLineItemId    = 4;
            cartItemsViewModelObj.SKUId              = "D";
            cartItemsViewModelObj.ProductName        = "Raisins";
            cartItemsViewModelObj.ProductDescription = "Soft and Sweet Raisins";
            cartItemsViewModelObj.UnitPrice          = 15;
            cartItemsViewModelObj.Quantity           = 1;
            cartViewModelObj.CartItems.Add(cartItemsViewModelObj);

            return(cartViewModelObj);
        }
Exemplo n.º 7
0
        public CartItemsDTO GetCart(Guid UserID)
        {
            CartItemsDTO CartItemsDTOObject = CartDatabaseContextObject.GetCart(UserID);
            double       TotalAmount        = 0;
            double       TotalDiscount      = 0;

            foreach (var CartProduct in CartItemsDTOObject.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;
            }
            CartItemsDTOObject.TotalAmount   = TotalAmount;
            CartItemsDTOObject.TotalDiscount = TotalDiscount;
            return(CartItemsDTOObject);
        }
Exemplo n.º 8
0
        public IHttpActionResult GetViewCart(int id)
        {
            List <CartItemsDTO> cartItems = new List <CartItemsDTO>();
            var context = new OSRSEntities();

            try
            {
                //var query = from p in context.Products
                //            join c in context.CartItemMappings on
                //            p.product_id equals c.product_id
                //            join d in context.Carts on c.cart_id equals d.cart_id
                //            where p.userid == id
                //            select new { p.product_name, p.price, p.product_category, c.cart_id, c.quantity, c.no_of_renting_days, Total = p.price * c.quantity };
                var query = context.getcartitemmappingv3(id);
                foreach (var item in query)
                {
                    CartItemsDTO cartitem = new CartItemsDTO();
                    cartitem.product_name       = item.product_name;
                    cartitem.price              = item.price;
                    cartitem.product_category   = item.product_category;
                    cartitem.quantity           = item.quantity;
                    cartitem.no_of_renting_days = item.no_of_renting_days;
                    cartitem.cartid             = item.cart_id;
                    //// cartitem.productid = item.product_id;
                    cartitem.total = item.total;
                    cartItems.Add(cartitem);
                }
                if (query == null)
                {
                    return(NotFound());
                }
                return(Ok(cartItems));
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }