private Product Create(Product product) { using (var productContext = new ProductContext()) { var result = productContext.Products.Add(product); productContext.SaveChanges(); return productContext.Products.Add(result); } }
private Product Update(Product product) { using (var productContext = new ProductContext()) { productContext.Products.Attach(product); productContext.Entry(product).State = EntityState.Modified; productContext.SaveChanges(); return product; } }
public Product Save(Product product) { if (product.Id == Guid.Empty) { return Create(product); } else { return Update(product); } }
public ProductMessage(Product product):this() { this.Id = product.Id; this.Type = product.Type; this.Name = product.Name; this.Links.Add(new ProductLink() { Id = this.Id, Name = this.Name, Type = "self" }); // вообще это здесь не нужно скорее всего, оно должно быть на эндпоинте. Но пусть будет пока if (product.Parent!=null) { this.Links.Add(new ProductLink() { Id = product.Parent.Id, Name = product.Parent.Name, Type = "parent" }); } foreach (var child in product.ChildProducts) { this.Links.Add(new ProductLink() { Type = child.Type, Name = child.Name, Id = child.Id }); } }
public static void TestProductRecursive(Product expected, Product actual) { TestProduct(expected, actual); if (actual.ChildProducts.Count != 0) { var expectedChildProducts = (List<Product>)expected.ChildProducts; var actualChildProducts = (List<Product>)actual.ChildProducts; for (int childIdx = 0; childIdx < expectedChildProducts.Count; childIdx++) { TestProductRecursive(expectedChildProducts[childIdx], actualChildProducts[childIdx]); } } }
private static void TestProduct(Product expected, Product actual) { Assert.AreEqual(expected.Name, actual.Name); Assert.AreEqual(expected.Type, actual.Type); if (expected.Parent != null) { Assert.AreEqual(expected.Parent.Id, actual.Parent.Id); } Assert.AreEqual(expected.ChildProducts.Count, actual.ChildProducts.Count); Assert.IsNotNull(actual.Id); }
private void TestProductFromDB(Product product, Guid Id) { var getResult = repository.Get(Id); TestProductRecursive(product, getResult); }
public static Product GetComplexProduct(int childCount) { var product = new Product() { Name = string.Format("ComplexTestProduct_{0}", Guid.NewGuid()), Type = string.Format("ComplexType_{0}", Guid.NewGuid()) }; product.ChildProducts = GetSimpleProductsCollection(childCount); return product; }