public Brand SelectById(int id)
 {
     using (ProductsBrandsDbContext context = new ProductsBrandsDbContext())
     {
         return(context.Brands.Find(id));
     }
 }
 public void Insert(Brand entity)
 {
     using (ProductsBrandsDbContext context = new ProductsBrandsDbContext())
     {
         context.Brands.Add(entity);
         context.SaveChanges();
     }
 }
Example #3
0
 public Product SelectById(int id)
 {
     using (ProductsBrandsDbContext context = new ProductsBrandsDbContext())
     {
         //includes brand, otherwise the product will come with brand empty
         return(context.Products.Include("Brand").Single(s => s.Id == id));
     }
 }
 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 #5
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 #6
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();
            }
        }
 public Task <List <Brand> > SelectAll()
 {
     /*
      * Task.Run() to load all brands in a different thread
      * making the main's form load faster
      */
     return(Task.Run(() =>
     {
         using (ProductsBrandsDbContext context = new ProductsBrandsDbContext())
         {
             return context.Brands.ToList();
         }
     }));
 }
Example #8
0
 /// <summary>
 /// @author - Bruno Fontes
 /// @version - 20171127
 ///
 /// Create the product's repository
 /// </summary>
 public Task <List <Product> > SelectAll()
 {
     /*
      * Task.Run() to load all products in a different thread
      * making the main's form load faster
      */
     return(Task.Run(() =>
     {
         using (ProductsBrandsDbContext context = new ProductsBrandsDbContext())
         {
             //includes brand, otherwise the product will come with brand empty
             return context.Products.Include("Brand").ToList();
         }
     }));
 }