Beispiel #1
0
 public int AddCategory(Category category)
 {
     using (var context = new EFSportsStoreContext())
     {
         context.Category.Add(category);
         context.SaveChanges();
     };
     return(category.Id);
 }
Beispiel #2
0
 public int AddProduct(Product product)
 {
     using (var context = new EFSportsStoreContext())
     {
         context.Product.Add(product);
         context.SaveChanges();
     };
     return(product.Id);
 }
 public int AddProduct(Product product)
 {
     using (var context = new EFSportsStoreContext())
     {
         context.Product.Add(product);
         context.SaveChanges();
     };
     return product.Id;
 }
 public int AddCategory(Category category)
 {
     using (var context = new EFSportsStoreContext())
     {
         context.Category.Add(category);
         context.SaveChanges();
     };
     return category.Id;
 }
Beispiel #5
0
        public IEnumerable <Category> GetCategories()
        {
            IEnumerable <Category> categories = null;

            using (var context = new EFSportsStoreContext())
            {
                categories = context.Category.ToList();
            };

            return(categories);
        }
        public IEnumerable<Category> GetCategories()
        {
            IEnumerable<Category> categories = null;

            using (var context = new EFSportsStoreContext())
            {
                categories = context.Category.ToList();
            };

            return categories;
        }
 public bool DeleteProduct(int id)
 {
     var isDeleted = false;
     using (var context = new EFSportsStoreContext())
     {
         var existingProduct = GetExistingProduct(id, context);
         if (existingProduct != null)
         {
             context.Product.Remove(existingProduct);
             context.SaveChanges();
             isDeleted = true;
         }
     }
     return isDeleted;
 }
 public bool DeleteCategory(int id)
 {
     var isDeleted = false;
     using (var context = new EFSportsStoreContext())
     {
         var existingcategory = GetExistingCategory(id, context);
         if (existingcategory != null)
         {
             context.Category.Remove(existingcategory);
             context.SaveChanges();
             isDeleted = true;
         }
     }
     return isDeleted;
 }
Beispiel #9
0
        public bool DeleteCategory(int id)
        {
            var isDeleted = false;

            using (var context = new EFSportsStoreContext())
            {
                var existingcategory = GetExistingCategory(id, context);
                if (existingcategory != null)
                {
                    context.Category.Remove(existingcategory);
                    context.SaveChanges();
                    isDeleted = true;
                }
            }
            return(isDeleted);
        }
Beispiel #10
0
        public bool DeleteProduct(int id)
        {
            var isDeleted = false;

            using (var context = new EFSportsStoreContext())
            {
                var existingProduct = GetExistingProduct(id, context);
                if (existingProduct != null)
                {
                    context.Product.Remove(existingProduct);
                    context.SaveChanges();
                    isDeleted = true;
                }
            }
            return(isDeleted);
        }
        public bool EditCategory(Category category)
        {
            var isUpdated = false;
            using (var context = new EFSportsStoreContext())
            {
                var existingcategory = GetExistingCategory(category.Id, context);
                if (existingcategory != null)
                {
                    existingcategory.Name = category.Name;

                    context.Entry(existingcategory).State = EntityState.Modified;
                    context.SaveChanges();
                    isUpdated = true;
                }
            }
            return isUpdated;
        }
Beispiel #12
0
        public bool EditCategory(Category category)
        {
            var isUpdated = false;

            using (var context = new EFSportsStoreContext())
            {
                var existingcategory = GetExistingCategory(category.Id, context);
                if (existingcategory != null)
                {
                    existingcategory.Name = category.Name;

                    context.Entry(existingcategory).State = EntityState.Modified;
                    context.SaveChanges();
                    isUpdated = true;
                }
            }
            return(isUpdated);
        }
 public bool EditProduct(Product product)
 {
     var isUpdated = false;
     using (var context = new EFSportsStoreContext())
     {
         var existingProduct = GetExistingProduct(product.Id, context);
         if (existingProduct != null)
         {
             existingProduct.CategoryId = product.CategoryId;
             existingProduct.Description = product.Description;
             existingProduct.Name = product.Name;
             existingProduct.Price = product.Price;
             context.Entry(existingProduct).State = EntityState.Modified;
             context.SaveChanges();
             isUpdated = true;
         }
     }
     return isUpdated;
 }
 public IEnumerable<ProductDetails> GetProducts()
 {
     IEnumerable<ProductDetails> products = null;
     using (var context = new EFSportsStoreContext())
     {
         var query = from p in context.Product
                     from c in context.Category.Where(x => x.Id == p.CategoryId)
                     select new ProductDetails
                     {
                         ProductId = p.Id,
                         CategoryId = c.Id,
                         CategoryName = c.Name,
                         ProductName = p.Name,
                         Price = p.Price,
                         Description = p.Description
                     };
         products = query.ToList<ProductDetails>();
     }
     return products;
 }
Beispiel #15
0
        public bool EditProduct(Product product)
        {
            var isUpdated = false;

            using (var context = new EFSportsStoreContext())
            {
                var existingProduct = GetExistingProduct(product.Id, context);
                if (existingProduct != null)
                {
                    existingProduct.CategoryId           = product.CategoryId;
                    existingProduct.Description          = product.Description;
                    existingProduct.Name                 = product.Name;
                    existingProduct.Price                = product.Price;
                    context.Entry(existingProduct).State = EntityState.Modified;
                    context.SaveChanges();
                    isUpdated = true;
                }
            }
            return(isUpdated);
        }
Beispiel #16
0
        public IEnumerable <ProductDetails> GetProducts()
        {
            IEnumerable <ProductDetails> products = null;

            using (var context = new EFSportsStoreContext())
            {
                var query = from p in context.Product
                            from c in context.Category.Where(x => x.Id == p.CategoryId)
                            select new ProductDetails
                {
                    ProductId    = p.Id,
                    CategoryId   = c.Id,
                    CategoryName = c.Name,
                    ProductName  = p.Name,
                    Price        = p.Price,
                    Description  = p.Description
                };
                products = query.ToList <ProductDetails>();
            }
            return(products);
        }
 private Product GetExistingProduct(int id, EFSportsStoreContext context)
 {
     return context.Product.Single(p => p.Id == id);
 }
 private Category GetExistingCategory(int id, EFSportsStoreContext context)
 {
     return context.Category.Single(p => p.Id == id);
 }
Beispiel #19
0
 private Product GetExistingProduct(int id, EFSportsStoreContext context)
 {
     return(context.Product.Single(p => p.Id == id));
 }
Beispiel #20
0
 private Category GetExistingCategory(int id, EFSportsStoreContext context)
 {
     return(context.Category.Single(p => p.Id == id));
 }