Example #1
0
        public ProductResponse GetProducts()
        {
            ProductValidation productValidation = new ProductValidation(new RepositoryFactory <ProductEntity>(), _appSettings.Value.MongoConnectionString);

            try
            {
                var productValidationStatus = productValidation.GetAllProducts();
                if (productValidationStatus.GotAllProducts)
                {
                    return(new ProductResponse()
                    {
                        Message = "Products found",
                        ProductEntities = productValidationStatus.ProductEntities
                    });
                }
                else
                {
                    return(new ProductResponse()
                    {
                        Message = "Products not found",
                        ProductEntities = null
                    });
                }
            }
            catch (KeyNotFoundException keyNotFound)
            {
                return(new ProductResponse()
                {
                    Message = keyNotFound.Message,
                    ProductEntities = null
                });
            }
        }
Example #2
0
        private bool ValidateProducts(List <ProductEntity> products)
        {
            ProductValidation productValidation = new ProductValidation(new RepositoryFactory <ProductEntity>(), ConnString);

            var allProducts = productValidation.GetAllProducts().ProductEntities;

            var totalPillCount = productValidation.CheckPillCount(products);

            if (totalPillCount > 38)
            {
                return(false);
            }

            var inStock = productValidation.CheckStock(allProducts, products);

            var quantityChanged = false;

            if (inStock)
            {
                foreach (var product in products)
                {
                    quantityChanged = productValidation.ChangeQuantity(product);
                }
            }

            return(quantityChanged);
        }