public IEnumerable <Product> GetAll()
 {
     using (var ctx = new WingtipToysEntities())
     {
         return(ctx.Products.ToList());
     }
 }
 public IEnumerable <Product> GetByCategoryId(int categoryId)
 {
     using (var ctx = new WingtipToysEntities())
     {
         return(ctx.Products.Where(x => x.CategoryID == categoryId).ToList());
     }
 }
 public Product Get(int productId)
 {
     using (var ctx = new WingtipToysEntities())
     {
         return(ctx.Products.SingleOrDefault(x => x.ProductID == productId));
     }
 }
示例#4
0
 public IEnumerable <Category> GetAll()
 {
     //throw new NotImplementedException();
     using (var ctx = new WingtipToysEntities())
     {
         return(ctx.Categories.ToList());
     }
 }
示例#5
0
 public Category Get(int categoryId)
 {
     //throw new NotImplementedException();
     using (var ctx = new WingtipToysEntities())
     {
         return(ctx.Categories.SingleOrDefault(x => x.CategoryID == categoryId));
     }
 }
示例#6
0
 public Category Get(string categoryName)
 {
     //throw new NotImplementedException();
     using (var ctx = new WingtipToysEntities())
     {
         return(ctx.Categories.SingleOrDefault(x => x.CategoryName.Equals(categoryName, StringComparison.InvariantCultureIgnoreCase)));
     }
 }
 public Product Create(Product product)
 {
     using (var ctx = new WingtipToysEntities())
     {
         var added = ctx.Products.Add(product);
         ctx.SaveChanges();
         return(added);
     }
 }
示例#8
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);
     }
 }
示例#10
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);
     }
 }
示例#11
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);
     }
 }