public static void AddProduct(Product product) { using (var db = new ElectroSterkDbContext()) { if (product != null) { db.Products.Add(product); db.SaveChanges(); } } // if (string.IsNullOrEmpty(product.Name)) // { // using (var db = new ElectroSterkDbContext()) // { // product.Categories = new SelectList(db.Categories.ToList(), "Id", "Name"); // return product; // } // } // using (var db = new ElectroSterkDbContext()) // { // if (db.Products.Any(x=> x.Name == product.Name)) // { // product.Categories = new SelectList(db.Categories.ToList(), "Id", "Name"); // return product; // } // } }
public static void DeleteCategory(Category category) { using (var db = new ElectroSterkDbContext()) { db.Entry(category).State = EntityState.Deleted; db.SaveChanges(); } }
public static void UpdateSidbar(Sidebar sidebar) { using (var db = new ElectroSterkDbContext()) { db.Entry(sidebar).State = EntityState.Modified; db.SaveChanges(); } }
public static void DeletePage(Page page) { using (var db = new ElectroSterkDbContext()) { db.Entry(page).State = EntityState.Deleted; db.SaveChanges(); } }
public static bool UpdatePage(Page page) { using (var db = new ElectroSterkDbContext()) { db.Entry(page).State = EntityState.Modified; return(db.SaveChanges() > 0); } }
public static bool AddPage(Page page) { using (var db = new ElectroSterkDbContext()) { db.Pages.Add(page); return(db.SaveChanges() > 0); } }
public static string UpdateCategory(string name, int id) { using (var db = new ElectroSterkDbContext()) { if (db.Categories.Any(x => x.Name == name)) { return("titleused"); } var category = db.Categories.FirstOrDefault(x => x.Id == id); category.Name = name; db.SaveChanges(); } return("done"); }
public static string AddCategory(string name) { string id; using (var db = new ElectroSterkDbContext()) { if (db.Categories.Any(x => x.Name == name)) { return("titletaken"); } var category = new Category { Name = name, Sorting = 100 }; db.Categories.Add(category); db.SaveChanges(); id = category.Id.ToString(); } return(id); }