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();
     }
 }
Example #3
0
        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();
            }
        }
Example #4
0
        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();
            }
        }