public Category Get(int ID)
 {
     using (_dbContext = new ProductsEntities())
     {
         Category category = _dbContext.Categories.FirstOrDefault(p => p.ID == ID);
         return category;
     }
 }
 public Product Get(int ID)
 {
     using (_dbContext = new ProductsEntities())
     {
         Product product = _dbContext.Products.Include("Category").FirstOrDefault(p => p.ID == ID);
         return product;
     }
 }
 public IEnumerable<Category> Get()
 {
     using (_dbContext = new ProductsEntities())
     {
         IEnumerable<Category> categories = _dbContext.Categories.ToList();
         return categories;
     }
 }
 public IEnumerable<Product> Get()
 {
     using (_dbContext = new ProductsEntities())
     {
         IEnumerable<Product> products = _dbContext.Products.Include("Category").ToList();
         return products;
     }
 }
        public int Create(Category category)
        {
            using (_dbContext = new ProductsEntities())
            {
                _dbContext.Categories.Add(category);
                var result = _dbContext.SaveChanges();

                return (result > 0) ? category.ID : -1;
            }
        }
        public int Create(Product product)
        {
            using (_dbContext = new ProductsEntities())
            {
                _dbContext.Products.Add(product);
                var result = _dbContext.SaveChanges();

                return (result > 0) ? product.ID : -1;
            }
        }
        public int Delete(int ID)
        {
            using (_dbContext = new ProductsEntities())
            {
                var category = _dbContext.Categories.FirstOrDefault(p => p.ID == ID);
                _dbContext.Categories.Remove(category);

                var result = _dbContext.SaveChanges();
                return result;
            }
        }
 public int Update(Category category)
 {
     Category dbCategory;
     var result = -1;
     using (_dbContext = new ProductsEntities())
     {
         dbCategory = _dbContext.Categories.FirstOrDefault(p => p.ID == category.ID);
     }
     if (dbCategory != null)
     {
         MapCategory(dbCategory, category);
         using (_dbContext = new ProductsEntities())
         {
             _dbContext.Entry(category).State = System.Data.Entity.EntityState.Modified;
             result = _dbContext.SaveChanges();
         }
     }
     return result;
 }
 public int Update(Product product)
 {
     Product dbProduct;
     var result = -1;
     using (_dbContext = new ProductsEntities())
     {
         dbProduct = _dbContext.Products.FirstOrDefault(p => p.ID == product.ID);
     }
     if (dbProduct != null)
     {
         MapProduct(dbProduct, product);
         using (_dbContext = new ProductsEntities())
         {
             _dbContext.Entry(product).State = System.Data.Entity.EntityState.Modified;
             result = _dbContext.SaveChanges();
         }
     }
     return result;
 }