public ActionResult CreateEntry() { var model = new EntryEditModel { PageTitle = "Create entry" }; return View(model); }
public ActionResult CreateEntry(EntryEditModel model) { var slug = model.Title.ToSlug(); if (_entryRepository.Exists(slug)) ModelState.AddModelError("Title", "An entry already exists with this title, please change it."); if (!ModelState.IsValid) { model.PageTitle = "Create entry"; return View(model); } var stringTags = !String.IsNullOrEmpty(model.TagString) ? model.TagString.Split(',') : new string[] { }; var newEntry = new Entry { Body = model.Body, Category = GetCategorie(model.CategoryName), Title = model.Title, Slug = slug, UserId = _userRepository.GetByName(User.Identity.Name).Id, Tags = GetTags(stringTags), EntryMetaKeywords = model.EntryMetaKeywords, EntryMetaDescription = model.EntryMetaDescription }; _entryRepository.Save(newEntry); return RedirectToAction("Administration"); }