private void FillProductsForDelete(String id) { var list = pdb.Get_All(); Products = new List <ProductToOrder>(); foreach (var item in db.GetOrders_Info(id)) { var pd = list.Where(i => i.ID.CompareTo(item.Product_ID) == 0).FirstOrDefault(); if (pd == null) { var up = new MProducers().GetUNProducer().ID; var uc = new MCategories().GetUNCategory().ID; Product product = new Product() { ID = item.Product_ID, Picture = "", Product_Name = "", Quantity = 0, Price = 0, Category_ID = uc, Producer_ID = up }; pdb.Add(product); } var oi = (new ProductToOrder(pd, item.Price, item.Quantity)); Products.Add(oi); } }
private void FillProductsList(String id = "") { var list = pdb.Get_All(); Products = new List <ProductToOrder>(); foreach (var item in list) { item.Category = new MCategories().Get(item.Category_ID); item.Producer = new MProducers().Get(item.Producer_ID); Products.Add(new ProductToOrder(item)); } if (!String.IsNullOrEmpty(id)) { foreach (var item in db.GetOrders_Info(id)) { var oi = Products.Where(i => i.ID.CompareTo(item.Product_ID) == 0).FirstOrDefault(); if (oi != null) { oi.OrderQuantity = item.Quantity; oi.PurchasePrice = item.Price; } else { var up = new MProducers().GetUNProducer().ID; var uc = new MCategories().GetUNCategory().ID; Product product = new Product() { ID = item.Product_ID, Picture = "", Product_Name = "", Quantity = 0, Price = 0, Category_ID = up, Producer_ID = uc }; pdb.Add(product); Products.Add(new ProductToOrder(product, item.Price, item.Quantity)); } } } }