示例#1
0
        public ActionResult AddArticle(string navSlug, ArticleEditorModel model)
        {
            try
            {
                // get nav
                Nav nav = AdminManager.GetNav(navSlug);

                // date
                DateTime created = model.DateCreated.HasValue ? model.DateCreated.Value : DateTime.Now;
                // status
                PostStatus status = PostStatus.Published;
                if (!model.IsPublished) status = PostStatus.Draft;

                // add
                Article newArticle = BlogApp.AddArticle(nav, model.Subject, model.Body,
                    model.PostSlug, model.Tags, created, status);

                // redirect: Save Drafts -> Drafts page
                if (!model.IsPublished)
                    return RedirectToAction("Drafts");

                // Publish -> Post page
                // TODO: is it necessary to get article again??
                return RedirectToRoute("BlogArticle", new
                {
                    postId = newArticle.PostId,
                    year = newArticle.DateCreated.Year,
                    month = newArticle.DateCreated.Month,
                    day = newArticle.DateCreated.Day,
                    postSlug = newArticle.PostSlug
                });
            }
            catch (SiteException e)
            {
                ModelState.AddModelError("", e.Message);
                // error
                return View("ArticleEditor", model);
            }
        }
示例#2
0
        public ActionResult EditArticle(string navSlug, int postId, ArticleEditorModel model)
        {
            try
            {
                // get nav
                Nav nav = AdminManager.GetNav(navSlug);

                // date
                DateTime created = model.DateCreated.HasValue ? model.DateCreated.Value : DateTime.Now;
                // status
                PostStatus status = PostStatus.Published;
                if (!model.IsPublished) status = PostStatus.Draft;

                // update
                Article updatedArticle = BlogApp.UpdateArticle(nav, postId, model.Subject, model.Body, model.Tags, model.PostSlug,
                    created, status);

                // redirect
                if (!model.IsPublished)
                    return RedirectToAction("Drafts");

                // RedirectToAction did not work for url, it appended year, month etc as query params
                return RedirectToRoute("BlogArticle", new
                {
                    postId = updatedArticle.PostId, // this line is not necessary, since ViewArticle can get postId from the url, it's for consistence
                    year = updatedArticle.DateCreated.Year,
                    month = updatedArticle.DateCreated.Month,
                    day = updatedArticle.DateCreated.Day,
                    postSlug = updatedArticle.PostSlug
                });
            }
            catch (SiteException e)
            {
                //model.Message = blogEx.Message;
                ModelState.AddModelError("", e.Message);
                return View("ArticleEditor", model);
            }
        }
示例#3
0
        public ActionResult EditArticle(string navSlug, int postId)
        {
            // get nav
            Nav nav = AdminManager.GetNav(navSlug);

            // when edit an article, need to show its time in local in UI
            Article post = (Article) BlogApp.GetPost(nav, postId);
            post.DateCreated = TimeZoneInfo.ConvertTimeFromUtc(post.DateCreated, TimeZoneInfo.FindSystemTimeZoneById(SiteConstant.TimeZone));

            var model = new ArticleEditorModel()
            {
                DateCreated = post.DateCreated,
                Body = post.Body,
                Subject = post.Subject,
                Tags = post.TagString,
                PostSlug = post.PostSlug,
                ShowDraftButton = !(post.PostStatus == PostStatus.Published),
            };

            return View("ArticleEditor", model);
        }