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!"); }
private void Checkout() { payType = new PaymentType() { Name = "Cash" }; if (RegisteredBuyer == null) { Buyer buyr = Buyers.Where(brs => brs.Name == SearchBuyerName).ToList().First(); purch = new Purchase() { Favorite = false, PurchaseAdress = "123123213", PurchaseDate = DateTime.Now, SumPurchase = 100213, PaymentType = payType, PaymentTypeID = payType.Id, BuyerID = buyr.Id }; } else { purch = new Purchase() { Favorite = false, PurchaseAdress = "123123213", PurchaseDate = DateTime.Now, SumPurchase = 100213, PaymentType = payType, PaymentTypeID = payType.Id, Buyer = RegisteredBuyer, BuyerID = RegisteredBuyer.Id }; } }