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)); } }
public IEnumerable <Category> GetAll() { //throw new NotImplementedException(); using (var ctx = new WingtipToysEntities()) { return(ctx.Categories.ToList()); } }
public Category Get(int categoryId) { //throw new NotImplementedException(); using (var ctx = new WingtipToysEntities()) { return(ctx.Categories.SingleOrDefault(x => x.CategoryID == categoryId)); } }
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); } }
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); } }
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); } }
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); } }