public ActionResult Add(ContentPage input) { if (!ModelState.IsValid) return View("Edit", input); var pageId = ContentHelpers.FullContentPageId(SlugConverter.TitleToSlug(input.Title)); var page = RavenSession.Load<ContentPage>(pageId); if (page != null) { ModelState.AddModelError("Id", "Page already exists for the slug you're trying to create it under"); return View("Edit", input); } input.Id = pageId; RavenSession.Store(input); return RedirectToAction("Index"); }
public ActionResult Edit(ContentPage input) { if (!ModelState.IsValid) return View("Edit", input); var page = string.IsNullOrWhiteSpace(input.Id) ? null : RavenSession.Load<ContentPage>(ContentHelpers.FullContentPageId(input.Id)); if (page != null) { // TODO Use optimistic concurrency? page.Content = input.Content; page.Title = input.Title; } else { // Create new page if none matching found input.Id = ContentHelpers.FullContentPageId(SlugConverter.TitleToSlug(input.Title)); RavenSession.Store(input); } return RedirectToAction("Index"); }