public ActionResult BlogRecent(AgilityContentItem module)
        {
            #region --- Get Blog Config and Repos ---
            var blogConfigRef             = module["BlogConfiguration"] as string;
            AgilityContentItem blogConfig = null;
            IAgilityContentRepository <AgilityContentItem> blogPosts      = null;
            IAgilityContentRepository <AgilityContentItem> blogCategories = null;
            IAgilityContentRepository <AgilityContentItem> blogTags       = null;
            IAgilityContentRepository <AgilityContentItem> blogAuthors    = null;
            BlogUtils.GetBlogConfig(blogConfigRef, out blogConfig, out blogPosts, out blogCategories, out blogTags, out blogAuthors);
            #endregion

            int recentPostsLimit;
            int.TryParse(string.Format("{0}", blogConfig["RecentPostsMax"]), out recentPostsLimit);

            if (recentPostsLimit < 1)
            {
                recentPostsLimit = 12;
            }

            var posts = BlogUtils.GetPosts(blogPosts, "", "Date Desc", recentPostsLimit, 0);

            var model = new BlogLinkViewModel();
            model.ShowCount = false;
            model.Items     = posts.Select(i => new BlogLinkItem()
            {
                Title   = i["Title"] as string,
                Url     = i.BlogDynamicUrl(blogConfig, null),
                Excerpt = BlogUtils.GetPostDescription(i, "Excerpt", blogConfig["AutoExcerptLength"])
            }).ToList();
            model.Configuration = blogConfig;

            return(PartialView(AgilityComponents.TemplatePath("Blog-RecentPostsModule"), model));
        }
        public ActionResult BlogAuthorDetails(AgilityContentItem module)
        {
            HttpContext.Response.Cache.VaryByParams[BlogContext.PagingQueryStringKey] = true;

            #region --- Get Blog Config and Repos ---
            var blogConfigRef             = module["BlogConfiguration"] as string;
            AgilityContentItem blogConfig = null;
            IAgilityContentRepository <AgilityContentItem> blogPosts      = null;
            IAgilityContentRepository <AgilityContentItem> blogCategories = null;
            IAgilityContentRepository <AgilityContentItem> blogTags       = null;
            IAgilityContentRepository <AgilityContentItem> blogAuthors    = null;
            BlogUtils.GetBlogConfig(blogConfigRef, out blogConfig, out blogPosts, out blogCategories, out blogTags, out blogAuthors);
            #endregion

            var author = AgilityContext.GetDynamicPageItem <AgilityContentItem>();
            if (!author.IsBlogAuthor())
            {
                return(null);
            }


            #region --- Get Posts and set Pagination ---
            List <AgilityContentItem> posts      = null;
            BlogPaginationViewModel   pagination = null;

            if (BlogUtils.GetBool(module["DisplayRecentBlogPosts"]))
            {
                int pageSize = 10;
                int.TryParse(string.Format("{0}", module["PageSize"]), out pageSize);
                if (pageSize < 1)
                {
                    pageSize = 10;
                }
                int pageNumber = 1;
                int.TryParse(Request.QueryString[BlogContext.PagingQueryStringKey] as string, out pageNumber);
                if (pageNumber < 1)
                {
                    pageNumber = 1;
                }
                int skip       = (pageNumber * pageSize) - pageSize;
                int totalCount = 0;

                //get the posts
                posts      = BlogUtils.GetPosts(blogPosts, author.ContentID, "", "", "", "", "Date Desc", pageSize, skip, out totalCount);
                pagination = new BlogPaginationViewModel(pageNumber, pageSize, totalCount, true, 5, BlogContext.PagingQueryStringKey, "agility-active", "agility-disabled");
            }
            #endregion

            var model = new BlogAuthorViewModel();
            model.Author        = author;
            model.Posts         = posts;
            model.Module        = module;
            model.Configuration = blogConfig;
            model.Pagination    = pagination;

            return(PartialView(AgilityComponents.TemplatePath("Blog-AuthorDetailsModule"), model));
        }
        public ActionResult BlogListing(AgilityContentItem module)
        {
            HttpContext.Response.Cache.VaryByParams["month"] = true;
            HttpContext.Response.Cache.VaryByParams[BlogContext.PagingQueryStringKey] = true;

            /*
             * check querystrings for filtering by "month"
             * check module for any specific filters being set (by category(s) or by tag(s))
             * check current dynamic page item and identify if its a category or tag, if so override any previous filter
             * get all blog posts by passing in filter and paging logic
             * create a viewmodel that contains posts, the module, and blog configuration
             * return partial view in inline code or local files (dependant on setting in BlogUtils)
             */

            #region --- Get Blog Config and Repos ---
            var blogConfigRef             = module["BlogConfiguration"] as string;
            AgilityContentItem blogConfig = null;
            IAgilityContentRepository <AgilityContentItem> blogPosts      = null;
            IAgilityContentRepository <AgilityContentItem> blogCategories = null;
            IAgilityContentRepository <AgilityContentItem> blogTags       = null;
            IAgilityContentRepository <AgilityContentItem> blogAuthors    = null;
            BlogUtils.GetBlogConfig(blogConfigRef, out blogConfig, out blogPosts, out blogCategories, out blogTags, out blogAuthors);
            #endregion

            #region --- Determine Filters ---
            DateTime filterMonth = DateTime.MinValue;
            var      categories  = new List <AgilityContentItem>();
            var      tags        = new List <AgilityContentItem>();

            //check for month
            string monthQS = Request.QueryString["month"] as string; //look for month=05-2015
            if (!string.IsNullOrEmpty(monthQS))
            {
                try
                {
                    filterMonth = DateTime.ParseExact(monthQS, "MM-yyyy", CultureInfo.InvariantCulture);
                }
                catch (FormatException ex)
                {
                    Agility.Web.Tracing.WebTrace.WriteInfoLine(ex.ToString());
                }
            }

            //check for dynamic item
            var dynamicItem = ResolveBlogCategory();
            var node        = SiteMap.CurrentNode;
            if (dynamicItem != null)
            {
                if (dynamicItem.IsBlogTag())
                {
                    tags.Add(dynamicItem);
                }
                else if (dynamicItem.IsBlogCategory())
                {
                    categories.Add(dynamicItem);
                }
                else
                {
                    //this is on some other dynamic page item, ignore it
                    dynamicItem = null;
                }
            }


            //skip module settings if we have a dynamic item set, else check
            if (dynamicItem == null)
            {
                string categoryIDs = module["FilterByCategoriesIDs"] as string;
                string tagsIDs     = module["FilterByTagsIDs"] as string;

                if (!string.IsNullOrEmpty(categoryIDs))
                {
                    var categoriesFromModule = blogCategories.GetByIDs(categoryIDs);
                    if (categoriesFromModule != null && categoriesFromModule.Any())
                    {
                        categories.AddRange(categoriesFromModule);
                    }
                }

                if (!string.IsNullOrEmpty(tagsIDs))
                {
                    var tagsFromModule = blogTags.GetByIDs(tagsIDs);
                    if (tagsFromModule != null && tagsFromModule.Any())
                    {
                        tags.AddRange(tagsFromModule);
                    }
                }
            }
            string dateFilter = "";
            if (filterMonth != DateTime.MinValue)
            {
                dateFilter = BlogUtils.GetSqlBetweenMonthRangeStatement("Date", filterMonth);
            }
            #endregion --- End Determine Filters ---

            #region --- Get Posts and set Pagination ---
            int pageSize = 10;
            int.TryParse(string.Format("{0}", module["PageSize"]), out pageSize);
            if (pageSize < 1)
            {
                pageSize = 10;
            }
            int pageNumber = 1;
            int.TryParse(Request.QueryString[BlogContext.PagingQueryStringKey] as string, out pageNumber);
            if (pageNumber < 1)
            {
                pageNumber = 1;
            }
            int skip       = (pageNumber * pageSize) - pageSize;
            int totalCount = 0;

            //get the posts
            List <AgilityContentItem> posts = BlogUtils.GetPosts(blogPosts, null, null, categories, tags, dateFilter, "Date Desc", pageSize, skip, out totalCount);
            var pagination = new BlogPaginationViewModel(pageNumber, pageSize, totalCount, true, 5, BlogContext.PagingQueryStringKey, "agility-active", "agility-disabled");
            #endregion

            #region --- Set Title ---
            //cannot set Page Title from child controller action and no way of knowing how the website layout is setting the title...
            //best we can do is utilize the Page Title from the Dynamic Page settings and set the <h1> on the module
            string title = module["DefaultTitle"] as string;
            if (dynamicItem != null)
            {
                title = dynamicItem["Title"] as string;
            }
            if (filterMonth != DateTime.MinValue)
            {
                if (!string.IsNullOrEmpty(title))
                {
                    title += ": ";
                }
                title += filterMonth.ToString("MMMM yyyy");
            }
            #endregion

            #region --- Set ViewModel ---
            var model = new BlogListingViewModel();
            model.Module          = module;
            model.Posts           = posts;
            model.Title           = title;
            model.Configuration   = blogConfig;
            model.CurrentCategory = categories.FirstOrDefault();
            model.Pagination      = pagination;
            #endregion

            return(PartialView(AgilityComponents.TemplatePath("Blog-ListingModule"), model));
        }