Example #1
0
        public void CreateTest()
        {
            var prd = new Product
            {
                Name = "TestProductName-Long"
            };
            var preCount  = _db.Products.Count();
            var prdAfter  = _store.Create(prd);
            var postCount = _db.Products.Count();

            Assert.AreEqual(prd.Name, prdAfter.Name);
            Assert.AreEqual(preCount + 1, postCount);

            var prd1 = new Product
            {
                Name = "TestProductName-Short"
            };
            var prd2 = new Product
            {
                Name = "ProductName-Short"
            };

            _store.Create(prd1);
            _store.Create(prd2);
            var lastCount = _db.Products.Count();

            Assert.AreEqual(postCount + 2, lastCount);
        }
        public async Task <IActionResult> Create([FromBody] ProductDTO productDTO)
        {
            var systemOfMeasurement = await _productsRepository.AssignMeasurementUnitToMeasurementSystem(productDTO.UnitOfMeasurement);

            var product = Product.Create(
                productDTO.Name,
                productDTO.Brand,
                productDTO.Quantity,
                productDTO.UnitOfMeasurement,
                systemOfMeasurement);
            await _productsRepository.Add(product);

            foreach (var price in productDTO.Prices)
            {
                var store = await _storesRepository.GetByName(price.StoreName);

                var productStore = ProductStore.Create(
                    product.Id,
                    store.FirstOrDefault().Id,
                    price.Price);
                await _productStoresRepository.Add(productStore);
            }

            return(Ok(product));
        }
Example #3
0
        public async Task AddProductCustom(string name, string brand, double quantity, string unitOfMeasurement, string storeName, double price)
        {
            Product product;

            if (!await Exists(name, brand, quantity, unitOfMeasurement))
            {
                Guid storeId;
                if (!await _storesRepository.Exists(storeName))
                {
                    Store store = Store.Create(storeName, "", "");
                    await _storesRepository.Add(store);

                    storeId = store.Id;
                }
                else
                {
                    storeId = (await _storesRepository.GetByName(storeName)).FirstOrDefault().Id;
                }

                int measurementSystem = (int)MeasureSystem.Undefined;
                if (unitOfMeasurementConversion.ContainsKey(unitOfMeasurement))
                {
                    measurementSystem = unitOfMeasurementConversion[unitOfMeasurement].Item2;
                }
                else
                {
                    measurementSystem = (int)MeasureSystem.Undefined;
                }

                product = Product.Create(name, brand, quantity, unitOfMeasurement, measurementSystem);
                await Add(product);

                Guid         productId = product.Id;
                ProductStore productStore;
                productStore = ProductStore.Create(productId, storeId, price);
                await _productStoresRepository.Add(productStore);
            }
        }
 public Product Post(Product product)
 {
     _productStore.Create(product);
     return(product);
 }
        public static void Initialize(IApplicationBuilder app)
        {
            using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope())
            {
                var context = serviceScope.ServiceProvider.GetService <DatabaseContext>();

                if (context.Stores != null && context.Stores.Any())
                {
                    return;
                }
                List <Store> stores = new List <Store>
                {
                    Store.Create("KMart", "KMart is the best store.", "https://www.KMart.com"),
                    Store.Create("Kepco", "Kepco is the best store.", "https://www.Kepco.com"),
                    Store.Create("Shop Ro 2000", "Shop Ro 2000 is the best store.", "https://www.shopro2000.com"),
                    Store.Create("GoShop", "GoShop is the best store.", "https://www.GoShop.com")
                };
                context.Stores.AddRange(stores);
                context.SaveChanges();

                List <Product> products = new List <Product>
                {
                    Product.Create("sugar", "SugarBrand", 1, "kilogram", 1),
                    Product.Create("flour", "FlourBrand", 1, "kilogram", 1),
                    Product.Create("water", "WaterBrand", 2.5, "litre", 2),
                    Product.Create("soy sauce", "Soy B", 500, "millilitre", 2),
                    Product.Create("chicken breast", "Kf Chicken", 1, "kilogram", 1),
                    Product.Create("salt", "SaltBrand", 1, "kilogram", 1)
                };
                context.Products.AddRange(products);
                context.SaveChanges();

                List <ProductStore> productStores = new List <ProductStore>
                {
                    ProductStore.Create(products[0].Id, stores[0].Id, 2.99),
                    ProductStore.Create(products[0].Id, stores[1].Id, 3.09),
                    ProductStore.Create(products[0].Id, stores[2].Id, 2.98),
                    ProductStore.Create(products[0].Id, stores[3].Id, 2.99),

                    ProductStore.Create(products[1].Id, stores[0].Id, 2.47),
                    ProductStore.Create(products[1].Id, stores[1].Id, 2.50),
                    ProductStore.Create(products[1].Id, stores[2].Id, 2.99),
                    ProductStore.Create(products[1].Id, stores[3].Id, 2.01),

                    ProductStore.Create(products[2].Id, stores[0].Id, 2.59),
                    ProductStore.Create(products[2].Id, stores[1].Id, 3.59),
                    ProductStore.Create(products[2].Id, stores[2].Id, 4.89),
                    ProductStore.Create(products[2].Id, stores[3].Id, 3.09),

                    ProductStore.Create(products[3].Id, stores[0].Id, 2.22),
                    ProductStore.Create(products[3].Id, stores[1].Id, 2.23),
                    ProductStore.Create(products[3].Id, stores[2].Id, 2.24),
                    ProductStore.Create(products[3].Id, stores[3].Id, 2.03),


                    ProductStore.Create(products[4].Id, stores[0].Id, 4.41),
                    ProductStore.Create(products[4].Id, stores[1].Id, 5.49),
                    ProductStore.Create(products[4].Id, stores[2].Id, 3.99),
                    ProductStore.Create(products[4].Id, stores[3].Id, 4.79),

                    ProductStore.Create(products[5].Id, stores[0].Id, 1.41),
                    ProductStore.Create(products[5].Id, stores[1].Id, 1.49),
                    ProductStore.Create(products[5].Id, stores[2].Id, 1.99),
                    ProductStore.Create(products[5].Id, stores[3].Id, 1.79),
                };
                context.ProductStores.AddRange(productStores);
                context.SaveChanges();

                Recipe recipe = Recipe.Create(
                    "Pancakes",
                    "New day, you want to start it right. Try this fresh and tasty Pancakes recipe!",
                    4,
                    500,
                    30,
                    0,
                    0,
                    0,
                    0);
                context.Recipes.Add(recipe);
                context.SaveChanges();

                List <Ingredient> ingredients = new List <Ingredient>
                {
                    Ingredient.Create(recipe.Id, productStores[2].Id, "sugar", 100, 2.98, "grams", 1),
                    Ingredient.Create(recipe.Id, productStores[7].Id, "flour", 500, 2.01, "grams", 1),
                    Ingredient.Create(recipe.Id, productStores[11].Id, "water", 100, 1.09, "millilitre", 1)
                };
                context.Ingredients.AddRange(ingredients);
                context.SaveChanges();

                List <Instruction> instructions = new List <Instruction>
                {
                    Instruction.Create(recipe.Id, "In a large bowl, sift together the flour, baking powder, " +
                                       "salt and sugar. Make a well in the center and pour in the milk, egg and melted butter; " +
                                       "mix until smooth.", 1),
                    Instruction.Create(recipe.Id, "Heat a lightly oiled griddle or frying pan over medium high " +
                                       "heat. Pour or scoop the batter onto the griddle, using approximately 1/4 cup for each pancake. " +
                                       "Brown on both sides and serve hot.", 2)
                };
                context.Instructions.AddRange(instructions);
                context.SaveChanges();
            }
        }