public void Insert(Brand entity) { using (ProductsBrandsDbContext context = new ProductsBrandsDbContext()) { context.Brands.Add(entity); context.SaveChanges(); } }
public void Remove(Brand entity) { using (ProductsBrandsDbContext context = new ProductsBrandsDbContext()) { context.Brands.Attach(entity); context.Entry(entity).State = System.Data.Entity.EntityState.Deleted; context.SaveChanges(); } }
public void Insert(Product entity) { using (ProductsBrandsDbContext context = new ProductsBrandsDbContext()) { //avoiding duplicate brands Brand brand = context.Brands.Find(entity.BrandId); entity.Brand = brand; context.Products.Add(entity); context.SaveChanges(); } }
public void Update(Product entity) { using (ProductsBrandsDbContext context = new ProductsBrandsDbContext()) { //avoiding duplicate brands Brand brand = context.Brands.Find(entity.BrandId); entity.Brand = brand; context.Products.Attach(entity); context.Entry(entity).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } }