public bool Delete(int categoryId) { using (var ctx = new WingtipToysModel()) { 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) { using (var ctx = new WingtipToysModel()) { 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 WingtipToysModel()) { 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); } }