public IActionResult Post(string posttitle, string day, string month, string year)
        {
            var lpvm       = new ListPostsViewModel();
            var postDtTime = DateTime.MinValue;
            var dayYear    = 0;

            if (dasBlogSettings.SiteConfiguration.EnableTitlePermaLinkUnique)
            {
                dayYear = Convert.ToInt32(string.Format("{0}{1}{2}", year, month, day));
            }

            var routeAffectedFunctions = new RouteAffectedFunctions(dasBlogSettings.SiteConfiguration.EnableTitlePermaLinkUnique);

            if (!routeAffectedFunctions.IsValidDay(dayYear))
            {
                return(NotFound());
            }

            var dt = routeAffectedFunctions.ConvertDayToDate(dayYear);

            if (routeAffectedFunctions.IsSpecificPostRequested(posttitle, dayYear))
            {
                var entry = blogManager.GetBlogPost(posttitle, dt);
                if (entry != null)
                {
                    var pvm = mapper.Map <PostViewModel>(entry);

                    var lcvm = new ListCommentsViewModel
                    {
                        Comments = blogManager.GetComments(entry.EntryId, false)
                                   .Select(comment => mapper.Map <CommentViewModel>(comment)).ToList(),
                        PostId       = entry.EntryId,
                        PostDate     = entry.CreatedUtc,
                        CommentUrl   = dasBlogSettings.GetCommentViewUrl(posttitle),
                        ShowComments = dasBlogSettings.SiteConfiguration.ShowCommentsWhenViewingEntry
                    };
                    pvm.Comments = lcvm;

                    if (httpContextAccessor.HttpContext.Request.Path.Value.EndsWith(".aspx", StringComparison.OrdinalIgnoreCase))
                    {
                        return(RedirectPermanent(pvm.PermaLink));
                    }

                    lpvm.Posts = new List <PostViewModel>()
                    {
                        pvm
                    };
                    return(SinglePostView(lpvm));
                }
                else
                {
                    return(NotFound());
                }
            }
            else
            {
                return(RedirectToAction("index", "home"));
            }
        }
        private void ValidatePost(PostViewModel post)
        {
            var routeAffectedFunctions = new RouteAffectedFunctions(dasBlogSettings.SiteConfiguration.EnableTitlePermaLinkUnique);

            var dt    = routeAffectedFunctions.SelectDate(post);
            var entry = blogManager.GetBlogPost(post.Title.Replace(" ", string.Empty), dt);

            if (entry != null && string.Compare(entry.EntryId, post.EntryId, true) > 0)
            {
                ModelState.AddModelError(string.Empty, "A post with this title already exists. Titles must be unique");
            }
        }
Example #3
0
        public IActionResult Post(string posttitle, string day, string month, string year)
        {
            var      lpvm       = new ListPostsViewModel();
            DateTime postDtTime = DateTime.MinValue;
            int      dayYear    = 0;

            if (dasBlogSettings.SiteConfiguration.EnableTitlePermaLinkUnique)
            {
                dayYear = Convert.ToInt32(string.Format("{0}{1}{2}", year, month, day));
            }

            var routeAffectedFunctions = new RouteAffectedFunctions(dasBlogSettings.SiteConfiguration.EnableTitlePermaLinkUnique);

            if (!routeAffectedFunctions.IsValidDay(dayYear))
            {
                return(NotFound());
            }

            var dt = routeAffectedFunctions.ConvertDayToDate(dayYear);

            if (routeAffectedFunctions.IsSpecificPostRequested(posttitle, dayYear))
            {
                var entry = blogManager.GetBlogPost(posttitle.Replace(dasBlogSettings.SiteConfiguration.TitlePermalinkSpaceReplacement, string.Empty), dt);
                if (entry != null)
                {
                    var pvm = mapper.Map <PostViewModel>(entry);

                    if (httpContextAccessor.HttpContext.Request.Path.Value.EndsWith(".aspx", StringComparison.OrdinalIgnoreCase))
                    {
                        return(RedirectPermanent(pvm.PermaLink));
                    }

                    lpvm.Posts = new List <PostViewModel>()
                    {
                        pvm
                    };
                    return(SinglePostView(lpvm));
                }
                else
                {
                    return(NotFound());
                }
            }
            else
            {
                return(RedirectToAction("index", "home"));
            }
        }
Example #4
0
        public IActionResult Post(string posttitle, int day)
        {
            ListPostsViewModel     lpvm = new ListPostsViewModel();
            RouteAffectedFunctions routeAffectedFunctions = new RouteAffectedFunctions(
                dasBlogSettings.SiteConfiguration.EnableTitlePermaLinkUnique);

            if (!routeAffectedFunctions.IsValidDay(day))
            {
                return(NotFound());
            }

            DateTime?dt = routeAffectedFunctions.ConvertDayToDate(day);

            if (routeAffectedFunctions.IsSpecificPostRequested(posttitle, day))
            {
                var entry = blogManager.GetBlogPost(posttitle.Replace(dasBlogSettings.SiteConfiguration.TitlePermalinkSpaceReplacement,
                                                                      string.Empty), dt);
                if (entry != null)
                {
                    lpvm.Posts = new List <PostViewModel>()
                    {
                        mapper.Map <PostViewModel>(entry)
                    };

                    SinglePost(lpvm.Posts.First());

                    return(View("Page", lpvm));
                }
                else
                {
                    return(NotFound());
                }
            }
            else
            {
                return(RedirectToAction("index", "home"));
            }
        }