public virtual ActionResult Create()
        {
            var model = new AdminBlogPostModel();

            model.AllowComments = true;
            return(View(model));
        }
        public virtual ActionResult List(DataSourceRequest command)
        {
            var blogPosts = _blogService.GetAllBlogPosts(null, null, command.Page - 1, command.PageSize, true);
            var gridModel = new DataSourceResult
            {
                Data = blogPosts.Select(x =>
                {
                    var m           = new AdminBlogPostModel();
                    m.AllowComments = x.AllowComments;
                    m.BodyOverview  = x.BodyOverview;
                    m.Tags          = x.Tags;
                    m.Title         = x.Title;
                    m.Id            = x.Id;

                    //little performance optimization: ensure that "Body" is not returned
                    m.Body = "";
                    if (x.StartDateUtc.HasValue)
                    {
                        m.StartDate = ConvertToUserTime(x.StartDateUtc.Value, DateTimeKind.Utc);
                    }
                    if (x.EndDateUtc.HasValue)
                    {
                        m.EndDate = ConvertToUserTime(x.EndDateUtc.Value, DateTimeKind.Utc);
                    }
                    m.CreatedOn           = ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc);
                    m.ApprovedComments    = _blogService.GetBlogCommentsCount(x, isApproved: true);
                    m.NotApprovedComments = _blogService.GetBlogCommentsCount(x, isApproved: false);

                    return(m);
                }),
                Total = blogPosts.TotalCount
            };

            return(Json(gridModel));
        }
        public virtual ActionResult Edit(AdminBlogPostModel model)
        {
            try
            {
                var blogPost = _blogService.GetBlogPostById(model.Id);
                if (blogPost == null)
                {
                    //No blog post found with the specified id
                    return(RedirectToAction("List"));
                }

                if (ModelState.IsValid)
                {
                    blogPost.Title         = model.Title;
                    blogPost.Tags          = model.Tags;
                    blogPost.BodyOverview  = model.BodyOverview.Trim();
                    blogPost.Body          = HttpUtility.HtmlDecode(model.Body);
                    blogPost.AllowComments = model.AllowComments;
                    blogPost.StartDateUtc  = model.StartDate;
                    blogPost.EndDateUtc    = model.EndDate;
                    _blogService.UpdateBlogPost(blogPost);

                    SuccessNotification("The blog post has been updated successfully.");
                    return(RedirectToAction("List"));
                }
            }
            catch { }
            return(View(model));
        }
        public virtual ActionResult Create(AdminBlogPostModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var blogPost = new BlogPost();
                    blogPost.Title         = model.Title;
                    blogPost.Tags          = model.Tags;
                    blogPost.BodyOverview  = model.BodyOverview.Trim();
                    blogPost.Body          = HttpUtility.HtmlDecode(model.Body);
                    blogPost.AllowComments = model.AllowComments;
                    blogPost.StartDateUtc  = model.StartDate;
                    blogPost.EndDateUtc    = model.EndDate;
                    blogPost.CreatedOnUtc  = DateTime.UtcNow;
                    _blogService.InsertBlogPost(blogPost);

                    SuccessNotification("The new blog post has been added successfully.");

                    return(RedirectToAction("List"));
                }
            }
            catch { }

            return(View(model));
        }
        public virtual ActionResult Edit(int id)
        {
            var blogPost = _blogService.GetBlogPostById(id);

            if (blogPost == null)
            {
                //No blog post found with the specified id
                return(RedirectToAction("List"));
            }

            var model = new AdminBlogPostModel();

            model.Title         = blogPost.Title;
            model.Tags          = blogPost.Tags;
            model.BodyOverview  = blogPost.BodyOverview.Trim();
            model.Body          = blogPost.Body;
            model.AllowComments = blogPost.AllowComments;
            model.StartDate     = blogPost.StartDateUtc;
            model.EndDate       = blogPost.EndDateUtc;
            return(View(model));
        }