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 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 #5
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;
     }
 }