public ActionResult Add(Page page) { if (ModelState.IsValid) { if (string.IsNullOrEmpty(page.Slug)) page.Slug = page.Title; try { repo.AddPage(page); MudHookNotifications.Set(new Notification("success", "Your new page has been added")); return RedirectToAction("Index"); } catch (ArgumentException ae) { MudHookNotifications.Set(new Notification("error", ae.Message)); } } else { var allErrors = ModelState.Values.SelectMany(v => v.Errors); string message = ""; foreach (var e in allErrors) { message += e.ErrorMessage + ","; } MudHookNotifications.Set(new Notification("error", message.TrimEnd())); } return View(page); }
public void AddPage(Page page) { page.Slug = page.Slug.ToSlug(); if (SlugExists(page)) throw new ArgumentException("A page with the same slug already exists, please change your page slug"); db.Pages.Add(page); Save(); }
public ActionResult Edit(Page page) { if (ModelState.IsValid) { if (string.IsNullOrEmpty(page.Slug)) page.Slug = page.Title; try { repo.EditPage(page); MudHookNotifications.Set(new Notification("success", "Your page has been updated.")); return RedirectToAction("Index"); } catch (ArgumentException ae) { MudHookNotifications.Set(new Notification("error", ae.Message)); } } return View(page); }
public bool SlugExists(Page page) { if (page == null) return false; return (db.Pages.Any(p => p.Slug == page.Slug && p.Id != page.Id)); }
public void EditPage(Page page) { page.Slug = page.Slug.ToSlug(); if (SlugExists(page)) throw new ArgumentException("A page with the same slug already exists, please change your page slug"); db.Entry(page).State = EntityState.Modified; Save(); }