コード例 #1
0
        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));
            }
        }
コード例 #2
0
        public JsonResult AddLink(string suggestion)
        {
            //SetupCurrentUser();

            try
            {
                doctormembraincomContext db = new doctormembraincomContext();
                bool ok;
                suggestion = StringHelper.OnlyAlphanumeric(suggestion.ToLower().Trim(), false, false, "", new char[] { ' ' }, out ok);

                if (ok)
                {
                    Wiki w = db.Wiki.Where(x => x.Title.ToLower().Trim().Contains(suggestion)).FirstOrDefault();

                    if (w != null)
                    {
                        return(Json(new { success = true, id = w.Id, title = w.Title }));
                    }
                    else
                    {
                        return(Json(new { success = false }));
                    }
                }
                else
                {
                    return(Json(new { success = false }));
                }
            }
            catch (Exception e)
            {
                return(Json(new { success = false }));
            }
        }
コード例 #3
0
        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));
            }
        }
コード例 #4
0
        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));
            }
        }
コード例 #5
0
        public IActionResult CreateWiki(int?wiki_id = null)
        {
            try
            {
                doctormembraincomContext db = new doctormembraincomContext();
                Wiki        w     = new Wiki();
                List <Wiki> wikis = db.Wiki.ToList();
                ViewBag.Wikis = wikis;
                if (wiki_id == null)
                {
                    w.Chapter = new List <Chapter>();
                }
                else
                {
                    w = db.Wiki
                        .Include(x => x.Chapter)
                        .Where(x => x.Id == wiki_id)
                        .FirstOrDefault();
                    w.Chapter = w.Chapter.OrderBy(x => x.Priority).ToList();
                }

                return(View("CreateWiki", w));
            }
            catch (Exception e)
            {
                return(NotFound(HttpStatusCode.NotFound));
            }
        }
コード例 #6
0
        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));
            }
        }
コード例 #7
0
 public IActionResult Wiki(int?wiki_id)
 {
     try
     {
         doctormembraincomContext db = new doctormembraincomContext();
         Wiki w;
         if (wiki_id != null)
         {
             w = db.Wiki
                 .Include(x => x.Chapter)
                 .Where(x => x.Id == wiki_id)
                 .FirstOrDefault();
         }
         else
         {
             w = db.Wiki
                 .Include(x => x.Chapter)
                 .FirstOrDefault();
         }
         if (w != null)
         {
             w.Title = StringHelper.SearchStringForTag(w.Title, "a");
             w.Intro = StringHelper.SearchStringForTag(w.Intro, "a");
             foreach (Chapter ch in w.Chapter)
             {
                 ch.Title = StringHelper.SearchStringForTag(ch.Title, "a");
                 ch.Text  = StringHelper.SearchStringForTag(ch.Text, "a");
             }
             w.Chapter = w.Chapter.OrderBy(x => x.Priority).ToList();
             return(View("Wiki", w));
         }
         return(RedirectToRoute("welcome"));
     }
     catch (Exception e)
     {
         return(NotFound(HttpStatusCode.NotFound));
     }
 }