Exemplo n.º 1
0
 public Brand GetById(int id)
 {
     using (ProductBrandDbContext context = new ProductBrandDbContext())
     {
         return(context.Brands.Find(id));
     }
 }
Exemplo n.º 2
0
 public Product GetById(int id)
 {
     using (ProductBrandDbContext context = new ProductBrandDbContext())
     {
         return(context.Products.Include("ProductBrand").Single(x => x.Id == id));
     }
 }
Exemplo n.º 3
0
 public void Insert(Brand entity)
 {
     using (ProductBrandDbContext context = new ProductBrandDbContext())
     {
         context.Brands.Add(entity);
         context.SaveChanges();
     }
 }
Exemplo n.º 4
0
 public void Delete(Product entity)
 {
     using (ProductBrandDbContext context = new ProductBrandDbContext())
     {
         context.Products.Attach(entity);
         context.Entry(entity).State = System.Data.Entity.EntityState.Deleted;
         context.SaveChanges();
     }
 }
Exemplo n.º 5
0
 public void Update(Brand entity)
 {
     using (ProductBrandDbContext context = new ProductBrandDbContext())
     {
         context.Brands.Attach(entity);
         context.Entry(entity).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Exemplo n.º 6
0
 public void Insert(Product entity)
 {
     using (ProductBrandDbContext context = new ProductBrandDbContext())
     {
         Brand productBrand = context.Brands.Find(entity.IdBrand);
         entity.ProductBrand = productBrand;
         context.Products.Add(entity);
         context.SaveChanges();
     }
 }
Exemplo n.º 7
0
 public Task <List <Product> > GetAll()
 {
     return(Task.Run(() =>
     {
         using (ProductBrandDbContext context = new ProductBrandDbContext())
         {
             return context.Products.Include("ProductBrand").ToList();
         }
     }));
 }
Exemplo n.º 8
0
 public Task <List <Brand> > GetAll()
 {
     return(Task.Run(() =>
     {
         using (ProductBrandDbContext context = new ProductBrandDbContext())
         {
             return context.Brands.ToList();
         }
     }));
 }
Exemplo n.º 9
0
 public void Update(Product entity)
 {
     using (ProductBrandDbContext context = new ProductBrandDbContext())
     {
         Brand productBrand = context.Brands.Find(entity.IdBrand);
         entity.ProductBrand = productBrand;
         context.Products.Attach(entity);
         context.Entry(entity).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }