示例#1
0
        public CartProcessingResult ProcessCart(int idUser, Cart cart)
        {
            CartProcessingResult result = CompleteAndValidateObject(idUser, cart);

            if (result.IsOk)
            {
                Save(cart);
            }

            return(result);
        }
        public CartProcessingResult ValidateStock(List <ProductCart> products)
        {
            CartProcessingResult result = new CartProcessingResult();

            IList <ProductStock> stocks = repository.GetStockOfProducts(products.Select(x => x.Product.Id).ToList());

            foreach (var prodCart in products)
            {
                var prodStock = stocks.FirstOrDefault(p => p.Product.Id == prodCart.Product.Id);
                if (prodStock == null)
                {
                    result.Add(prodCart.Product, "Product is not available in Stock" + prodCart.Product.Id);
                }

                if (prodStock.Quantity < prodCart.Quantity)
                {
                    result.Add(prodCart.Product, "Quant. in Stock (" + prodStock.Quantity + ") is less than Quant. Required (" + prodCart.Quantity + ")");
                }
            }

            return(result);
        }