Exemple #1
0
 public ActionResult RemoveCategory(RemoveCategoryBindingModel bm)
 {
     if (!ModelState.IsValid || !this.service.RemoveCategory(bm))
     {
         this.AddNotification("Failed to remove category.", NotificationType.ERROR);
         return(this.RedirectToAction("AllCategories"));
     }
     this.AddNotification("Category removed", NotificationType.SUCCESS);
     return(this.RedirectToAction("AllCategories"));
 }
 public bool RemoveCategory(RemoveCategoryBindingModel bm)
 {
     if (this.db.Categories.GetAll().Any(c => c.Id == bm.Id))
     {
         var category = this.db.Categories.Find(c => c.Id == bm.Id);
         this.db.Categories.Remove(category);
         this.db.SaveChanges();
         return(true);
     }
     return(false);
 }