Beispiel #1
0
 public Category Create(Category category)
 {
     //throw new NotImplementedException();
     using (var ctx = new WingtipToysEntities())
     {
         var added = ctx.Categories.Add(category);
         ctx.SaveChanges();
         return(added);
     }
 }
 public bool Delete(int productId)
 {
     using (var ctx = new WingtipToysEntities())
     {
         var existing = ctx.Products.SingleOrDefault(x => x.ProductID == productId);
         if (existing == null)
         {
             return(false);
         }
         ctx.Products.Remove(existing);
         ctx.SaveChanges();
         return(true);
     }
 }
Beispiel #3
0
 public bool Delete(int categoryId)
 {
     //throw new NotImplementedException();
     using (var ctx = new WingtipToysEntities())
     {
         var existing = ctx.Categories.SingleOrDefault(x => x.CategoryID == categoryId);
         if (existing == null)
         {
             return(false);
         }
         ctx.Categories.Remove(existing);
         ctx.SaveChanges();
         return(true);
     }
 }
Beispiel #4
0
 public Category Update(Category category)
 {
     //throw new NotImplementedException();
     using (var ctx = new WingtipToysEntities())
     {
         var existing = ctx.Categories.SingleOrDefault(x => x.CategoryID == category.CategoryID);
         if (existing == null)
         {
             return(null);
         }
         existing.Description  = category.Description;
         existing.CategoryName = category.CategoryName;
         ctx.SaveChanges();
         return(existing);
     }
 }
 public Product Update(Product product)
 {
     using (var ctx = new WingtipToysEntities())
     {
         var existing = ctx.Products.SingleOrDefault(x => x.ProductID == product.ProductID);
         if (existing == null)
         {
             return(null);
         }
         existing.CategoryID  = product.CategoryID;
         existing.Description = product.Description;
         existing.ImagePath   = product.ImagePath;
         existing.ProductName = product.ProductName;
         existing.UnitPrice   = product.UnitPrice;
         ctx.SaveChanges();
         return(existing);
     }
 }