public ActionResult RemoveChapterPost(int chapter_id) { try { doctormembraincomContext db = new doctormembraincomContext(); Chapter c = db.Chapter.Where(x => x.Id == chapter_id).FirstOrDefault(); if (c != null) { Wiki w = db.Wiki .Include(x => x.Chapter) .Where(x => x.Id == c.WikiId) .FirstOrDefault(); w.Chapter = w.Chapter.OrderBy(x => x.Priority).ToList(); foreach (Chapter ch in w.Chapter) { if (ch.Priority > c.Priority) { ch.Priority--; } } db.Chapter.Remove(c); db.SaveChanges(); } return(RedirectToRoute("create_wiki", new { wiki_id = c.WikiId })); } catch (Exception e) { return(NotFound(HttpStatusCode.NotFound)); } }
public ActionResult AddChapterPost(int wiki_id, string c_title, string c_text) { try { doctormembraincomContext db = new doctormembraincomContext(); Wiki w = db.Wiki .Include(x => x.Chapter) .Where(x => x.Id == wiki_id) .FirstOrDefault(); if (w != null) { bool ok; Chapter c = new Chapter(); c.Priority = w.Chapter.Count() + 1; c.Title = StringHelper.OnlyAlphanumeric(c_title, false, true, "", new char[] { ' ', ',', '-', '\'', '"', '&', '#', '(', ')', '\\', '?', '/', '<', '>' }, out ok); c.Text = StringHelper.OnlyAlphanumeric(c_text, true, true, "br", new char[] { ' ', '.', ',', '-', '\'', '"', '*', '&', '#', '(', ')', '\\', '?', '/', '<', '>' }, out ok); w.Chapter.Add(c); db.SaveChanges(); } return(RedirectToRoute("create_wiki", new { wiki_id = w.Id })); } catch (Exception e) { return(NotFound(HttpStatusCode.NotFound)); } }
public ActionResult CreateWikiPost(Wiki model) { try { doctormembraincomContext db = new doctormembraincomContext(); Wiki w = db.Wiki.Where(x => x.Id == model.Id).FirstOrDefault(); if (w != null) { bool ok; w.Title = StringHelper.OnlyAlphanumeric(model.Title, false, true, "", new char[] { ' ', ',', '-', '\'', '"', '&', '#', '(', ')', '\\', '?', '/', '<', '>' }, out ok); w.Intro = StringHelper.OnlyAlphanumeric(model.Intro, true, true, "br", new char[] { ' ', '.', ',', '-', '\'', '"', '*', '&', '#', '(', ')', '\\', '?', '/', '<', '>' }, out ok); } else { w = new Wiki(); bool ok; w.Title = StringHelper.OnlyAlphanumeric(model.Title, false, true, "", new char[] { ' ', ',', '-', '\'', '"', '&', '#', '(', ')', '\\', '?', '/', '<', '>' }, out ok); w.Intro = StringHelper.OnlyAlphanumeric(model.Intro, true, true, "br", new char[] { ' ', '.', ',', '-', '\'', '"', '*', '&', '#', '(', ')', '\\', '?', '/', '<', '>' }, out ok); db.Wiki.Add(w); } db.SaveChanges(); return(RedirectToRoute("create_wiki", new { wiki_id = w.Id })); } catch (Exception e) { return(NotFound(HttpStatusCode.NotFound)); } }
public ActionResult MoveChapter(int chapter_id, string dir) { try { int?id = null; doctormembraincomContext db = new doctormembraincomContext(); Chapter c = db.Chapter.Where(x => x.Id == chapter_id).FirstOrDefault(); if (c != null) { Wiki w = db.Wiki .Include(x => x.Chapter) .Where(x => x.Id == c.WikiId) .FirstOrDefault(); if (w != null) { bool update = true; int new_prio = dir == "up" ? c.Priority - 1 : c.Priority + 1; if (new_prio <= 0) { update = false; } if (new_prio > w.Chapter.Count()) { update = false; } if (update) { c.Priority = new_prio; foreach (Chapter ch in w.Chapter) { if (ch.Priority == new_prio && ch.Id != c.Id) { ch.Priority = dir == "up" ? ch.Priority + 1 : ch.Priority - 1; } } db.SaveChanges(); } id = w.Id; } } return(RedirectToRoute("create_wiki", new { wiki_id = id })); } catch (Exception e) { return(NotFound(HttpStatusCode.NotFound)); } }