public void when_creating_product_on_disposed_store_then_throws()
        {
            var store = new ProductStore(
                "ProductStoreFixture.Simple.json",
                new JsonProductSerializer(),
                Mock.Of<IToolkitCatalog>());

            store.Dispose();

            Assert.Throws<ObjectDisposedException>(() => store.CreateProduct("foo", "bar", "baz"));
        }
        public void when_closing_then_raises_closed()
        {
            var store = new ProductStore(
                "ProductStoreFixture.Simple.json",
                new JsonProductSerializer(),
                Mock.Of<IToolkitCatalog>());

            var closed = false;

            store.Closed += (sender, args) => closed = true;

            store.Close();

            Assert.True(closed);
        }
        public void when_creating_duplicate_named_product_then_throws()
        {
            var store = new ProductStore(
                "ProductStoreFixture.Simple.json",
                new JsonProductSerializer(),
                Mock.Of<IToolkitCatalog>(c => c.Find("SimpleToolkit") ==
                    Mock.Of<IToolkitInfo>(t => t.Products == new[]
                    {
                        Mock.Of<IProductInfo>(p =>
                            p.Toolkit == Mock.Of<IToolkitInfo>() &&
                            p.SchemaId == "NuPattern.Tookit.Simple.IAmazonWebServices")
                    })));

            store.CreateProduct("Foo", "SimpleToolkit", typeof(IAmazonWebServices).ToTypeFullName());

            Assert.Throws<ArgumentException>(() =>
                store.CreateProduct("Foo", "SimpleToolkit", typeof(IAmazonWebServices).ToTypeFullName()));
        }
Example #4
0
 public IEnumerable <ProductStoreType> GetProductStoreTypes(ProductStore store)
 {
     return(null);
 }
Example #5
0
 public CreateProductViewModel(ProductStore productStore)
 {
     CreateProductCommand = new CreateProductCommand(this, productStore);
 }
Example #6
0
 public void Setup()
 {
     productStore       = new ProductStore();
     productsController = new ProductsController(productStore);
 }
Example #7
0
        private void SubTrackStore(Product product, double qtuop, int storageID, Order order)
        {
            Stack <ProductStore> stores = new Stack <ProductStore>();


            order.PersonID        = Convert.ToInt32(comboCustomer.SelectedValue);
            order.StorageName     = comboStore.Text;
            order.TypeOf          = TypeOfOrders.Export;
            order.DateOfOperation = DateTime.Now;



            var item = product.ProductStores.Where(a => a.StoreID == storageID && a.Qtu != 0).OrderBy(a => a.ExpireDate).ToList();


            item.Sort((x, y) => DateTime.Compare(x.ExpireDate, y.ExpireDate));
            foreach (var i in item)
            {
                stores.Push(i);
            }
            double mainQtu = qtuop;

            while (stores.Count > 0)
            {
                ProductStore productStore = stores.Pop();
                if (productStore.Qtu == mainQtu)
                {
                    order.OrderDetails.Add(new OrderDetails()
                    {
                        ExpireDateProduct = productStore.ExpireDate.Date,
                        ProductionDate    = productStore.ProductDate.Date,
                        ProductID         = product.ID,
                        Qtu = mainQtu
                    });

                    productStore.Qtu = 0;

                    break;
                }
                else if (productStore.Qtu > mainQtu)
                {
                    order.OrderDetails.Add(new OrderDetails()
                    {
                        ExpireDateProduct = productStore.ExpireDate.Date,
                        ProductionDate    = productStore.ProductDate.Date,
                        ProductID         = product.ID,
                        Qtu = mainQtu
                    });

                    double qtu = mainQtu;
                    productStore.Qtu -= qtu;

                    break;
                }
                else if (productStore.Qtu < mainQtu)
                {
                    order.OrderDetails.Add(new OrderDetails()
                    {
                        ExpireDateProduct = productStore.ExpireDate.Date,
                        ProductionDate    = productStore.ProductDate.Date,
                        ProductID         = product.ID,
                        Qtu = mainQtu
                    });
                    mainQtu         -= productStore.Qtu;
                    productStore.Qtu = 0;
                }


                context.Entry(product).State = EntityState.Modified;
            }
        }
Example #8
0
        static void Main(string[] args)
        {
            var marketStore = new MarketStore()
            {
                Path = marketPath
            };
            var productStore = new ProductStore()
            {
                Path = productsPath
            };
            var productInfoStore = new ProductInfoStore()
            {
                Path = productInfoPath
            };

            // example 1. get markets with products
            // group markets with products

            var productList     = productStore.GetCollection();
            var marketList      = marketStore.GetCollection();
            var productInfoList = productInfoStore.GetCollection();

            foreach (var item in marketList)
            {
                item.Products = productList
                                .Where(x => x.MarketId == item.Id)
                                .ToList();
            }

            Console.WriteLine("\n");
            Console.WriteLine("Шаг 1. Работа с файлами\n1. Извлечь данные из файлов (csv);");
            Console.WriteLine("2. Отобразить все данные из этих файлов в виде списка;\n");
            var prodTemplate = "{0} | {1} | {2} | {3} | {4}";

            Console.WriteLine(string.Format(prodTemplate,
                                            "Id",
                                            "Name",
                                            "Price",
                                            "Amount",
                                            "Delivery Perion (days)"));
            foreach (var item in marketList)
            {
                foreach (var prod in item.Products)
                {
                    Console.WriteLine(string.Format(prodTemplate,
                                                    prod.Id,
                                                    prod.Name,
                                                    prod.Price,
                                                    prod.Amount,
                                                    prod.DeliveryPeriod));
                }
            }

            Console.WriteLine("\n");

            foreach (var item in productList)
            {
                item.ProductInfo = productInfoList.Where(x => x.ProductId == item.Id).ToList();
            }

            var productInfoListTemplate = "{0} |  {1} |  {2}";

            Console.WriteLine(string.Format(productInfoListTemplate,
                                            "Id",
                                            "Parameter",
                                            "Definition"));

            foreach (var i in productList)
            {
                foreach (var prodInfo in i.ProductInfo)
                {
                    Console.WriteLine(string.Format(productInfoListTemplate,
                                                    prodInfo.Id,
                                                    prodInfo.Parameter,
                                                    prodInfo.Definition));
                }
            }

            Console.WriteLine("\n");
            Console.WriteLine(string.Format(productInfoListTemplate,
                                            "Id",
                                            "Name",
                                            "Rating"));
            foreach (var i in marketList)
            {
                Console.WriteLine(string.Format(productInfoListTemplate,
                                                i.Id,
                                                i.MarketName,
                                                i.Rating));
            }

            Console.WriteLine("\n\nШаг 2. Обработка Market");
            Console.WriteLine("\n1. Отобразить список продуктов;\n");

            foreach (var i in marketList)
            {
                Console.Write(i.MarketName + " | ");
            }
            Console.WriteLine();
            string enteredMarketName = Console.ReadLine();

            var selectedMarket = marketList
                                 .First(x => x.MarketName.Equals(enteredMarketName));

            selectedMarket.Products = productList
                                      .Where(x => x.MarketId == selectedMarket.Id)
                                      .ToList();

            foreach (var item in selectedMarket.Products)
            {
                Console.WriteLine(item.Id + " " + item.Name);
            }

            Console.WriteLine("\n2. Вывести сумму цен всех продуктов выбранного Market; ");

            Console.WriteLine("= " + selectedMarket.Products.Sum(x => x.Price));

            Console.WriteLine("\n\n3. Отсортировать по цене (от меньшего к большему) и вывести продукты выбранного Market;");
            selectedMarket.Products = productList
                                      .Where(x => x.MarketId == selectedMarket.Id)
                                      .OrderBy(x => x.Price)
                                      .ToList();

            foreach (var cur in selectedMarket.Products)
            {
                Console.WriteLine(cur.Price + " " + cur.Name);
            }

            Console.WriteLine("\n4. Отсортировать по кол-ву продуктов и вывести их (по выбранному Market);");
            selectedMarket.Products = productList
                                      .Where(x => x.MarketId == selectedMarket.Id)
                                      .OrderBy(x => x.Amount)
                                      .ToList();
            foreach (var cur in selectedMarket.Products)
            {
                Console.WriteLine(cur.Amount + " " + cur.Name);
            }

            Console.WriteLine("\n\nШаг 3. Работа с ProductInfo\n\n1. Сгруппировать Product и Product Info и отобразить их;\n");
            Console.WriteLine("Group Product and PrInfo by their Name\n");
            string pr6LessStr = "{0} |  {1} |  {2}  |  {3} |  {4} |  {5}";

            Console.WriteLine(string.Format(pr6LessStr,
                                            "Name",
                                            "Price",
                                            "Amount",
                                            "DeliveryPeriod",
                                            "Parameter",
                                            "Definition"));

            var proddListttt = productList
                               .Join(productInfoList, x => x.Id, y => y.ProductId, (x, y) => new {
                x.Name,
                x.Price,
                x.Amount,
                x.DeliveryPeriod,
                y.Parameter,
                y.Definition
            })
                               .GroupBy(x => x.Name)
                               .ToList();

            foreach (var itm in proddListttt)
            {
                foreach (var i in itm)
                {
                    Console.WriteLine(string.Format(pr6LessStr,
                                                    i.Name,
                                                    i.Price,
                                                    i.Amount,
                                                    i.DeliveryPeriod,
                                                    i.Parameter,
                                                    i.Definition));
                }
                Console.WriteLine("\n");
            }

            Console.WriteLine("\n2. Отсортировать название параметра в Product Info;");
            var listOfProdInfo = productInfoList
                                 .OrderBy(x => x.Parameter);

            string listOfProdInfoStr = "{0} |  {1} |  {2}";

            Console.WriteLine(string.Format(productInfoListTemplate,
                                            "Id",
                                            "Parameter",
                                            "Definition"));
            foreach (var cur in listOfProdInfo)
            {
                Console.WriteLine(string.Format(listOfProdInfoStr,
                                                cur.Id,
                                                cur.Parameter,
                                                cur.Definition));
            }

            Console.WriteLine("\n3. Выделить все продукты с рейтингом менее 6;");

            var prodRating6Less = productList
                                  .Join(productInfoList, x => x.Id, y => y.ProductId, (x, y) => new {
                x.Name,
                y.Definition,
                y.Parameter
            })
                                  .Where(x => x.Parameter.Equals("Rating") && Convert.ToInt32(x.Definition) < 6)
                                  .ToList();

            foreach (var print in prodRating6Less)
            {
                Console.WriteLine(print.Definition + " " + print.Name);
            }

            Console.WriteLine("\n\nШаг 4. Общее\n\n1. Сгруппировать Market, Product, ProductInfo и вывести;\n");

            var grMarProd = marketList
                            .Join(productList, x => x.Id, y => y.MarketId, (x, y) => new {
                x.MarketName,
                x.Rating,
                y.Id,
                y.Name,
                y.Price,
                y.Amount,
                y.DeliveryPeriod
            });

            var grMarProdPrInf = grMarProd
                                 .Join(productInfoList, x => x.Id, y => y.ProductId, (x, y) => new {
                x.MarketName,
                x.Rating,
                x.Name,
                x.Price,
                x.Amount,
                x.DeliveryPeriod,
                y.Parameter,
                y.Definition
            })
                                 .GroupBy(x => x.MarketName);

            string grMarProdPrInfStr = "{0} |  {1} |  {2}  |  {3} |  {4} |  {5}  |  {6}  |  {7}";

            Console.WriteLine(string.Format(grMarProdPrInfStr,
                                            "MarketName",
                                            "Rating",
                                            "Name",
                                            "Price",
                                            "Amount",
                                            "DeliveryPeriod",
                                            "Parameter",
                                            "Definition\n"));

            foreach (var grMPP in grMarProdPrInf)
            {
                foreach (var g in grMPP)
                {
                    Console.WriteLine(string.Format(grMarProdPrInfStr,
                                                    g.MarketName,
                                                    g.Rating,
                                                    g.Name,
                                                    g.Price,
                                                    g.Amount,
                                                    g.DeliveryPeriod,
                                                    g.Parameter,
                                                    g.Definition));
                }
            }

            var grMarRatAndProdRat = grMarProd
                                     .Join(productInfoList, x => x.Id, y => y.ProductId, (x, y) => new {
                x.MarketName,
                x.Rating,
                x.Name,
                x.Price,
                x.Amount,
                x.DeliveryPeriod,
                y.Parameter,
                y.Definition
            })
                                     .Where(x => x.Parameter.Equals("Rating"));


            foreach (var grMPP in grMarProdPrInf)
            {
                var avPrInMarket = grMPP
                                   .Where(x => x.Parameter.Equals("Rating"))
                                   .Select(x => Convert.ToInt32(x.Definition))
                                   .ToList();
            }

            Console.WriteLine("\n2. Сравнить рейтинг Market с средним значением рейтингов продуктов. Если рейтинг Market ниже, то выделить Market\n");
            foreach (var grMPP in grMarProdPrInf)
            {
                var avPrInMarket = grMPP
                                   .Where(x => x.Parameter.Equals("Rating"))
                                   .Select(x => Convert.ToInt32(x.Definition))
                                   .Average();

                Console.WriteLine("\nAverage rating of product: " + avPrInMarket + "\n");
                string addedTick = "";
                foreach (var g in grMPP)
                {
                    if (Convert.ToDouble(g.Rating) < Convert.ToDouble(avPrInMarket))
                    {
                        addedTick = "      IS LESS";
                    }
                    else
                    {
                        addedTick = "";
                    }
                }
                foreach (var g in grMPP)
                {
                    Console.WriteLine(string.Format(grMarProdPrInfStr,
                                                    g.MarketName,
                                                    g.Rating + addedTick,
                                                    g.Name,
                                                    g.Price,
                                                    g.Amount,
                                                    g.DeliveryPeriod,
                                                    g.Parameter,
                                                    g.Definition));
                }
            }
        }
        public void when_creating_product_then_store_forwards_events_until_delete()
        {
            var store = new ProductStore(
                "ProductStoreFixture.Simple.json",
                new JsonProductSerializer(),
                Mock.Of<IToolkitCatalog>(c => c.Find("SimpleToolkit") == Mock.Of<IToolkitInfo>(t => t.Products == new[]
                    {
                        Mock.Of<IProductInfo>(p =>
                            p.Toolkit == Mock.Of<IToolkitInfo>(i => i.Id == "SimpleToolkit" && i.Version == "1.0") &&
                            p.SchemaId == typeof(IAmazonWebServices).FullName &&
                            p.Components == new []
                            {
                                Mock.Of<IElementInfo>(e =>
                                    e.SchemaId == typeof(IStorage).FullName &&
                                    e.DefaultName == "Storage" &&
                                    e.Properties == new []
                                    {
                                        Mock.Of<IPropertyInfo>(ak => ak.Name == "RefreshOnLoad" && ak.PropertyType == typeof(bool)),
                                    }
                                )
                            } &&
                            p.Properties == new []
                            {
                                Mock.Of<IPropertyInfo>(ak => ak.Name == "AccessKey" && ak.PropertyType == typeof(string)),
                                Mock.Of<IPropertyInfo>(ak => ak.Name == "SecretKey" && ak.PropertyType == typeof(string)),
                            })
                    })));

            var created = default(IProduct);
            store.ProductEvents.Created += (sender, args) => created = args.Value;

            var product = store.CreateProduct("Simple", "SimpleToolkit", typeof(IAmazonWebServices).FullName);

            Assert.Same(product, created);

            product.Delete();
        }
        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();
            }
        }
        public void when_loading_store_then_loads_product_and_associates_schema_and_store()
        {
            var store = new ProductStore(
                "ProductStoreFixture.Simple.json",
                new JsonProductSerializer(),
                Mock.Of<IToolkitCatalog>(c => c.Find("SimpleToolkit") ==
                    Mock.Of<IToolkitInfo>(t => t.Products == new[]
                    {
                        Mock.Of<IProductInfo>(p =>
                            p.Toolkit == Mock.Of<IToolkitInfo>() &&
                            p.SchemaId == "NuPattern.Tookit.Simple.IAmazonWebServices")
                    })));

            store.Load(NullProgress<int>.Default);

            Assert.Equal(1, store.Products.Count());
            Assert.NotNull(store.Products.First().Schema);
            Assert.Same(store, store.Products.First().Store);
        }
        public void when_loaded_product_deleted_then_removes_from_store_and_resets_store()
        {
            var store = new ProductStore(
                "ProductStoreFixture.Simple.json",
                new JsonProductSerializer(),
                Mock.Of<IToolkitCatalog>());

            store.Load(NullProgress<int>.Default);

            var product = store.Products.First();

            product.Delete();

            Assert.Equal(0, store.Products.Count());
            Assert.Null(product.Store);
        }
Example #13
0
        private void metroButton3_Click(object sender, EventArgs e)
        {
            List <OrderDetails> list = new List <OrderDetails>();

            foreach (DataGridViewRow item in dataGridView1.Rows)
            {
                list.Add(new OrderDetails()
                {
                    ProductID         = Convert.ToInt32(item.Cells[0].Value),
                    Qtu               = Convert.ToInt32(item.Cells[2].Value),
                    ProductionDate    = Convert.ToDateTime(item.Cells[4].Value),
                    ExpireDateProduct = Convert.ToDateTime(item.Cells[3].Value),
                });
            }
            Order order = new Order()
            {
                PersonID        = Convert.ToInt32(comboSupplierAndCustomer.SelectedValue),
                StorageName     = comboStorage.Text,
                DateOfOperation = DateTime.Now,
                TypeOf          = TypeOfOrders.Import,
                OrderDetails    = list
            };
            List <ProductStore> productStores = new List <ProductStore>();

            foreach (DataGridViewRow item in dataGridView1.Rows)
            {
                int      productId = Convert.ToInt32(item.Cells[0].Value);
                DateTime Exdate    = Convert.ToDateTime(item.Cells[3].Value);
                DateTime Prdate    = Convert.ToDateTime(item.Cells[4].Value);
                int      StorageId = Convert.ToInt32(comboStorage.SelectedValue);
                var      items     = context.ProductStores.Where(a => a.ProductID == productId && DbFunctions.TruncateTime(a.ExpireDate) == Exdate.Date &&
                                                                 DbFunctions.TruncateTime(a.ProductDate) == Prdate.Date && a.StoreID == StorageId
                                                                 ).ToList();
                if (items.Count == 0)
                {
                    productStores.Add(new ProductStore()
                    {
                        ExpireDate  = Convert.ToDateTime(item.Cells[3].Value),
                        ProductDate = Convert.ToDateTime(item.Cells[4].Value),
                        Qtu         = Convert.ToInt32(item.Cells[2].Value),
                        ProductID   = Convert.ToInt32(item.Cells[0].Value),
                        StoreID     = Convert.ToInt32(comboStorage.SelectedValue)
                    });
                }
                else
                {
                    ProductStore currentProduct = context.ProductStores.FirstOrDefault(a => a.StoreID == StorageId && a.ProductID == productId);
                    currentProduct.Qtu += Convert.ToDouble(item.Cells[2].Value);
                }
            }
            foreach (var item in productStores)
            {
                context.ProductStores.Add(item);
            }


            context.Orders.Add(order);
            if (context.SaveChanges() > 0)
            {
                MessageBox.Show("The Bill of is added", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #14
0
 public ProductServices()
 {
     store = new ProductStore();
 }
Example #15
0
 public ProductsController(ProductStore productStore)
 {
     _mProductStore = productStore;
 }
Example #16
0
 public HomeController()
 {
     store = new ProductStore();
 }
Example #17
0
 public virtual ProductStore DeleteProductStore(ProductStore entity)
 {
     this.DeleteProductStore(entity.ProductId);
     return(entity);
 }