/// <summary>
        /// In this method i can add product type to product
        /// </summary>
        /// <param name="json"></param>
        public void Add(string json)
        {
            ProductType productType = wrapperTypeProduct.DeserializeProduct(json);
            ICollection<Product> prTypesProduct = productType.Products;// because productType`ve child elements
            productType.Products = null;// after that productType don`t have child elements and we can this add to db
            bool includeType = false;
            Product dynamicProduct = new Product();

            foreach (var item in _productTypeRepository.GetAll())
            {
                ////if we have productType with the same name we give product id type that was
                if (item.Name == productType.Name)  // will replace by sql script
                {
                    foreach (var prTP in prTypesProduct)
                    {
                        ReplacementProduct(prTP);
                        dynamicProduct = prTP;
                        dynamicProduct.ProductType = null;
                        dynamicProduct.ProductTypeID = item.Id;
                    }
                    includeType = true;
                    _productRepository.Add(dynamicProduct);
                }
            }

            if (!includeType)
            {
                ReplacementProducts(prTypesProduct);
            }
            _productRepository.Save();
        }
コード例 #2
0
 public void AddProduct(Product product)
 {
     Console.WriteLine("You have already added the product, type of product and parametres of product !" +
                       " Please, will add the parametr value of product");
 }
コード例 #3
0
 public void AddProduct(Product product)
 {
     _state.AddProduct(product);
 }
コード例 #4
0
        public void FillDB()
        {
            using (MngPaycheckContext db = new MngPaycheckContext())
            {
                //WORK WITH PRODUCT
                Product prod = new Product()
                {
                    Name = "Asus",
                    Characteristicks = "Super laptop",
                    Cost = 1012,
                    Description = "It`s a super"
                };

                Product prod2 = new Product()
                {
                    Name = "Acer",
                    Characteristicks = "Super laptop",
                    Cost = 2016,
                    Description = "It`s a super"
                };

                ProductType prodType = new ProductType()
                {
                    Name = "Laptop",
                };

                ProductParametrValue productParametrValue = new ProductParametrValue(prod, "5 gb");
                ProductParametr productParametr = new ProductParametr()
                {
                    Name = "Ram",
                    ProductType = prodType,
                    ProductParametrValue = productParametrValue
                };

                prod.ProductType = prodType;

                db.Products.Add(prod);
                db.ProductTypes.Add(prodType);
                db.ProductParametrs.Add(productParametr);
                db.ProductParametrValues.Add(productParametrValue);
                db.SaveChanges();

                /////////WORK WITH PURCHASES
                ///////Create one purchase and added two products in this purchase
                ///
                ///
                ///
                ///
                //Create Buyer and add to Buyer purchase
                Buyer buyer = new Buyer()
                {
                    Name = "Andrew",
                    Login = "******",
                    Password = "******",
                };
                db.Buyers.Add(buyer);
                db.SaveChanges();

                Purchase purchase = new Purchase()
                {
                    Favorite = false,
                    PurchaseAdress = "123123213",
                    PurchaseDate = DateTime.Now,
                    SumPurchase = 100213,
                    PaymentType = new PaymentType() { Name = "Cash"},
                    Buyer = buyer
                };

                PurchaseProduct purchaseProduct = new PurchaseProduct()
                {
                    Cost = prod.Cost,
                    Units = 12,
                    Product = prod,
                    Purchase = purchase
                };

                PurchaseProduct purchaseProduct2 = new PurchaseProduct()
                {
                    Cost = prod2.Cost,
                    Product = prod2,
                    Purchase = purchase
                };

                db.PurchaseProducts.Add(purchaseProduct);
                db.PurchaseProducts.Add(purchaseProduct2);
                db.SaveChanges();
                //////////////////////

                PaymentType paytype = new PaymentType()
                {
                    Name = "Creditka"
                };

                purchase.PaymentType = paytype;

                db.PaymentTypes.Add(paytype);
                db.SaveChanges();

                foreach (var item in db.Buyers.Select(a=>a.Purchases).ToList())
                {
                    foreach (var it in item.Select(a=>a.Favorite))
                    {
                       Console.WriteLine(it.ToString());
                    }
                }

                //LogicsType<Purchase> payType = new LogicsType<Purchase>(new PaymentTypeStrategy());
                //foreach (var item in payType.Execute(paytype))//получаю список всех елементов, у которых тип == paytype
                //{
                //    Console.WriteLine(item.PurchaseAdress);
                //}

                //Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!");

                //LogicsType<Product> productType = new LogicsType<Product>(new ProductTypeStrategy());
                //foreach (var item in productType.Execute(prodType))
                //{
                //    Console.WriteLine(item.Name);
                //}
            }
            Console.WriteLine("OK!");
        }
コード例 #5
0
        public void testState()
        {
            var logicsState = new LogicsState();
            Product product = new Product()
            {
                Name = "Asus",
                Characteristicks = "Super laptop",
                Cost = 1012,
                Description = "It`s a super"
            };

            ProductType productType = new ProductType()
            {
                Name = "Laptop"
            };

            logicsState.SetState(new AddedProductState(logicsState));

            logicsState.AddProductType(productType);

            logicsState.AddProduct(product);
            logicsState.AddProductType(productType);

            //ProductParametrValue productParametrValue = new ProductParametrValue()
            //{
            //    Value = "value",
            //    Product = product
            //};

            //ProductParametr productParametr = new ProductParametr()
            //{
            //    Name = "RAM",
            //    ProductParametrValue = productParametrValue
            //};

            //logicsState.AddProductParametrValue(productParametr, productParametrValue);
            //List<ProductParametr> ListOfProductParametr = new List<ProductParametr>() { productParametr };
            //logicsState.AddProductParametr(ListOfProductParametr);
            //logicsState.AddProductParametrValue(productParametr, productParametrValue);
        }
コード例 #6
0
 protected ProductParametrValue(Product product)
 {
     Product = product;
 }
コード例 #7
0
 public ProductParametrValue(Product product, string value)
     : this(product)
 {
     Value = value;
 }
 public void ReplacementProduct(Product ProductClient)
 {
     _productRepository.Delete(_productRepository.GetAll().Where(pr => pr.Name == ProductClient.Name).ToList().FirstOrDefault());
     _productRepository.Save();
 }
コード例 #9
0
 public void AddProduct(Product product)
 {
     Console.WriteLine("+ Added a product. Let`s add the product type");
     _logicsState.SetState(_logicsState.AddedProductTypeState);
 }
コード例 #10
0
 public void AddProduct(Product product)
 {
     Console.WriteLine("You added the product please, add the parametr of product");
 }