public static void AddProduct(Product product, List <int> patlangacIds) { product.Id = products.Last().Id + 1; product.Category = categories.First(t => t.Id == product.CategoryId); product.Patlangacs = new List <Patlangac>(); foreach (int patlangacId in patlangacIds) { Patlangac patlangac = patlangacs.First(t => t.Id == patlangacId); product.Patlangacs.Add(patlangac); } products.Add(product); }
public static void UpdateProduct(Product product, List <int> patlangacIds) { for (int i = 0; i < products.Count; i++) { if (products[i].Id == product.Id) { products[i] = product; break; } } product.Category = categories.First(y => y.Id == product.CategoryId); product.Patlangacs = new List <Patlangac>(); foreach (int patlangacId in patlangacIds) { Patlangac patlangac = patlangacs.First(t => t.Id == patlangacId); product.Patlangacs.Add(patlangac); } }