/// <summary> /// Trim properties in Wiki object in relation to text formatting af message ect. /// </summary> /// <param name="Wiki">Wiki to be trimed</param> /// <returns>Trimed wiki</returns> public static Wiki Trim(this Wiki Wiki) { if (Wiki.Title != null) { Wiki.Title = Wiki.Title.Substring(0, Wiki.Title.Length > 50 ? 50 : Wiki.Title.Length); } return(Wiki); }
public ActionResult Edit(Wiki Wiki, string Action) { Wiki dbWiki = new Wiki(); if (Wiki.WikiID != Guid.Empty) dbWiki = reposetory.GetWikisItem(Wiki.WikiID); if (dbWiki == null) return HttpNotFound(); if (Wiki.Words == null) { Wiki.Words = new List<WikiWord> { new WikiWord() }; } else { Wiki.Words = Wiki.Words.GroupBy(w => w.Word.ToLower()).Select(w => w.First()).ToList(); } if (Action == "addWord") { Wiki.Words.Add(new WikiWord()); ModelState.Clear(); } if (Action == "Edit" && ModelState.IsValid) { if (reposetory.RemoveWikiWords(dbWiki)) { //Wiki NewWiki = new Wiki(); dbWiki.Title = Wiki.Title; dbWiki.Body = Wiki.Body; dbWiki.Words = new List<WikiWord>(); // NewWiki.Trim(); foreach (WikiWord w in Wiki.Words) { if (!string.IsNullOrEmpty(w.Word)) dbWiki.Words.Add(new WikiWord { Word = w.Word.Trim() }); } dbWiki.Trim(); if (reposetory.Save(dbWiki)) { Wiki = dbWiki; ViewBag.FormSucces = true; ModelState.Clear(); } } } return View(Wiki); }
public ActionResult Edit(Guid? Id) { Wiki Wiki = new Wiki(); if (Id != null) Wiki = reposetory.GetWikisItem((Guid)Id); if (Wiki == null) return HttpNotFound(); if (Wiki.Words == null) Wiki.Words = new List<WikiWord>(); Wiki.Words.Add(new WikiWord()); return View(Wiki); }