Example #1
0
 public static void SaveProductCategories(List <ProductCategory> productCategories)
 {
     try
     {
         using (var context = new WebshopEntities())
         {
             context.ProductCategory.AddRange(productCategories);
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #2
0
 public static int Save(Product product)
 {
     try
     {
         using (var context = new WebshopEntities())
         {
             context.Product.Add(product);
             context.SaveChanges();
             return(product.Id);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #3
0
 public static void DeleteProductCategoriesByProductId(int productId)
 {
     try
     {
         using (var context = new WebshopEntities())
         {
             var productCategories = context.ProductCategory.Where(p => p.ProductId == productId).ToList();
             context.ProductCategory.RemoveRange(productCategories);
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #4
0
        public static Product GetProductById(int id)
        {
            try
            {
                Product product;
                using (var context = new WebshopEntities())
                {
                    product = context.Product.Where(p => p.Id == id).FirstOrDefault();
                }

                return(product);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #5
0
        public static List <Product> GetProducts()
        {
            try
            {
                List <Product> products;
                using (var context = new WebshopEntities())
                {
                    products = context.Product.ToList();
                }

                return(products);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #6
0
        public static List <ProductCategory> GetCategoriesByProductId(int productId)
        {
            try
            {
                List <ProductCategory> productCategories;
                using (var context = new WebshopEntities())
                {
                    productCategories = context.ProductCategory.Where(p => p.ProductId == productId).ToList();
                }

                return(productCategories);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #7
0
        public static List <Category> GetCategories()
        {
            try
            {
                List <Category> categories;
                using (var context = new WebshopEntities())
                {
                    categories = context.Category.ToList();
                }

                return(categories);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #8
0
 public static void Delete(int id)
 {
     try
     {
         using (var context = new WebshopEntities())
         {
             var dataProduct = context.Product.Where(p => p.Id == id).FirstOrDefault();
             if (dataProduct != null)
             {
                 context.Product.Remove(dataProduct);
                 context.SaveChanges();
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #9
0
 public static void Update(int id, Product product)
 {
     try
     {
         using (var context = new WebshopEntities())
         {
             var dataProduct = context.Product.Where(p => p.Id == id).FirstOrDefault();
             if (dataProduct != null)
             {
                 dataProduct.Description    = product.Description;
                 dataProduct.Name           = product.Name;
                 dataProduct.UnitPrice      = product.UnitPrice;
                 dataProduct.UpdateDateTime = DateTime.Now;
                 context.SaveChanges();
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }