예제 #1
0
        public int GetInventory(CartVariantMappingDTO cartVariantMappingDTO)
        {
            int Inventory = shoppingCartEntities.Variants.Where(c => c.ID == cartVariantMappingDTO.VariantID).Select(p => p.Inventory).FirstOrDefault();

            Debug.WriteLine(shoppingCartEntities.Variants.Where(c => c.ID == cartVariantMappingDTO.VariantID).Select(p => p.Inventory).FirstOrDefault());
            return(Inventory);
        }
예제 #2
0
        private bool isItemPresent(CartVariantMappingDTO cartVariantMappingDTO)
        {
            CartVariantMapping cart = shoppingCartEntities.CartVariantMappings.Where(c => c.CartID == cartVariantMappingDTO.UserID && c.VariantID == cartVariantMappingDTO.VariantID).FirstOrDefault();

            Debug.WriteLine(shoppingCartEntities.CartVariantMappings.Where(c => c.CartID == cartVariantMappingDTO.UserID && c.VariantID == cartVariantMappingDTO.VariantID).FirstOrDefault());
            if (cart != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #3
0
        public int GetOrderLimit(CartVariantMappingDTO cartVariantMappingDTO)
        {
            Guid productID  = shoppingCartEntities.Variants.Where(c => c.ID == cartVariantMappingDTO.VariantID).Select(p => p.ProductID).FirstOrDefault();
            var  OrderLimit = shoppingCartEntities.Products.Where(p => p.ID == productID).Select(o => o.OrderLimit).FirstOrDefault();

            Debug.WriteLine(shoppingCartEntities.Variants.Where(c => c.ID == cartVariantMappingDTO.VariantID).Select(p => p.ProductID).FirstOrDefault());
            Debug.WriteLine(shoppingCartEntities.Products.Where(p => p.ID == productID).Select(o => o.OrderLimit).FirstOrDefault());
            if (OrderLimit == null)
            {
                int inventoryValue = GetInventory(cartVariantMappingDTO);
                return(inventoryValue);
            }
            return(OrderLimit.GetValueOrDefault());
        }
예제 #4
0
        public int PresentInCart(CartVariantMappingDTO cartVariantMappingDTO)
        {
            int quantity = shoppingCartEntities.CartVariantMappings.Where(c => c.CartID == cartVariantMappingDTO.UserID && c.VariantID == cartVariantMappingDTO.VariantID)
                           .Select(q => q.Quantity).FirstOrDefault();

            Debug.WriteLine(shoppingCartEntities.CartVariantMappings.Where(c => c.CartID == cartVariantMappingDTO.UserID && c.VariantID == cartVariantMappingDTO.VariantID)
                            .Select(q => q.Quantity).FirstOrDefault());

            if (quantity == 0)
            {
                return(quantity);
            }
            return(quantity);
        }
예제 #5
0
        public ActionResult AddItem([Bind(Include = "VariantID, ProductID, Quantity, OrderLimit, Inventory")] CartViewModel cartViewModel)
        {
            CartMessageViewModel cartMessageViewModel = new CartMessageViewModel();

            if (ModelState.IsValid)
            {
                CartVariantMappingDTO cartVariantMappingDTO = CartMapper.Map <CartViewModel, CartVariantMappingDTO>(cartViewModel);
                cartVariantMappingDTO.UserID = new Guid(Session["UserID"].ToString());
                try
                {
                    cartBusinessContext.AddItem(cartVariantMappingDTO);
                    cartMessageViewModel.SuccessMessage = "Item Successfuly Added to Cart";
                    return(View(cartMessageViewModel));
                }
                catch (ItemAlreadyInCartException ex)
                {
                    cartMessageViewModel.ErrorMessages.Add("Item is already present in the cart");
                    return(View(cartMessageViewModel));
                }
                catch (OrderLimitExceededException)
                {
                    cartMessageViewModel.ErrorMessages.Add("Order Quantity Exceeded the limit");
                    return(View(cartMessageViewModel));
                }
                catch (QuantityUnavailableException)
                {
                    cartMessageViewModel.ErrorMessages.Add("Requested Quantity is UnAvailable");
                    return(View(cartMessageViewModel));
                }
                catch (Exception ex)
                {
                    return(View("InternalError"));
                }
            }
            else
            {
                foreach (var modelState in ModelState.Values)
                {
                    foreach (var err in modelState.Errors)
                    {
                        cartMessageViewModel.ErrorMessages.Add(err.ErrorMessage.ToString());
                    }
                }
                return(View(cartMessageViewModel));
            }
        }
예제 #6
0
        public void AddToCart(CartVariantMappingDTO cartVariantMappingDTO)
        {
            CartVariantMapping cart = new CartVariantMapping {
                ID           = Guid.NewGuid(), CartID = cartVariantMappingDTO.UserID, VariantID = cartVariantMappingDTO.VariantID, Quantity = cartVariantMappingDTO.Quantity,
                SellingPrice = cartVariantMappingDTO.SellingPrice
            };

            if (isItemPresent(cartVariantMappingDTO))
            {
                cart          = shoppingCartEntities.CartVariantMappings.Where(c => c.CartID == cartVariantMappingDTO.UserID && c.VariantID == cartVariantMappingDTO.VariantID).FirstOrDefault();
                cart.Quantity = cartVariantMappingDTO.Quantity;
            }
            else
            {
                shoppingCartEntities.CartVariantMappings.Add(cart);
            }
            shoppingCartEntities.SaveChanges();
        }
예제 #7
0
        public void AddItem(CartVariantMappingDTO cartVariantMappingDTO)
        {
            try
            {
                int totalQuantity   = cartDatabaseContext.PresentInCart(cartVariantMappingDTO) + cartVariantMappingDTO.Quantity;
                int inventoryValue  = cartDatabaseContext.GetInventory(cartVariantMappingDTO);
                int orderLimitValue = cartDatabaseContext.GetOrderLimit(cartVariantMappingDTO);

                if (totalQuantity > orderLimitValue)
                {
                    throw new OrderLimitExceededException();
                }
                if (totalQuantity > inventoryValue)
                {
                    throw new QuantityUnavailableException();
                }
                cartVariantMappingDTO.Quantity = totalQuantity;
                cartDatabaseContext.AddToCart(cartVariantMappingDTO);
            }
            catch (AlreadyPresentException ex)
            {
                throw new ItemAlreadyInCartException();
            }
        }