public bool UpdateCategory(int id, string name, string description) { using var db = new NorthwindContex(); if (id > 0) { var category = db.Categories.Find(id); if (category != null) { category.Id = id; category.Name = name; category.Description = description; int changes = db.SaveChanges(); if (changes > 0) { return(true); } else { return(false); } } else { return(false); } } else { return(false); } }
public bool DeleteCategory(int id) { using var db = new NorthwindContex(); if (id > 0) { var category = db.Categories.Find(id); if (category != null) { db.Categories.Remove(category); int changes = db.SaveChanges(); if (changes > 0) { return(true); } else { return(false); } } else { return(false); } } else { return(false); } }
//13 public Boolean DeleteCategory(int idquery) { using var db = new NorthwindContex(); var category = db.Categories.Find(idquery); if (category != null) { db.Categories.Remove(category); db.SaveChanges(); return(true); } else { return(false); } }
//11 public Category CreateCategory(string namequery, string descriptionquery) { using var db = new NorthwindContex(); var nextId = db.Categories.Max(x => x.Id) + 1; var cat = new Category { Id = nextId, Name = namequery, Description = descriptionquery }; db.Categories.Add(cat); db.SaveChanges(); return(db.Categories.Find(nextId)); }
//12 public Boolean UpdateCategory(int idquery, string namequery, string descriptionquery) { using var db = new NorthwindContex(); var category = db.Categories.Find(idquery); if (category != null) { category.Name = namequery; category.Description = descriptionquery; db.SaveChanges(); return(true); } else { return(false); } }
public Category CreateCategory(string name, string description) { using var db = new NorthwindContex(); var nextId = db.Categories.Max(x => x.Id) + 1; var category = new Category { Id = nextId, Name = name, Description = description }; db.Categories.Add(category); int changes = db.SaveChanges(); if (changes > 0) { return(category); } else { return(null); } }