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));
        }
Example #2
0
        public ActionResult ProductDetailsModule(Module_ProductDetails module)
        {
            var product = AgilityContext.GetDynamicPageItem <Product>();

            var model = new ProductDetailsModule();

            model.Module = module;

            if (product != null && product.ReferenceName == "Products")
            {
                model.Product = product;

                var category = new AgilityContentRepository <ProductCategory>("ProductCategories").Items().Where(i => i.ContentID == product.ProductCategoryID).FirstOrDefault();
                model.Category = category;
            }

            return(PartialView(model));
        }
        public Task <IViewComponentResult> InvokeAsync(Module_ProductDetails module)
        {
            return(Task.Run <IViewComponentResult>(() =>
            {
                var product = AgilityContext.GetDynamicPageItem <Product>();

                var model = new ProductDetailsModule();
                model.Module = module;

                if (product != null && product.ReferenceName == "Products")
                {
                    model.Product = product;

                    var category = new AgilityContentRepository <ProductCategory>("ProductCategories").Items().Where(i => i.ContentID == product.ProductCategoryID).FirstOrDefault();
                    model.Category = category;
                }



                return View("~/Views/Products/ProductDetailsModule.cshtml", model);
            }));
        }
        protected virtual AgilityContentItem ResolveBlogPostDetails()
        {
            var post = AgilityContext.GetDynamicPageItem <AgilityContentItem>();

            return(post);
        }
        public ActionResult BlogDetails(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

            #region --- Resolve Dynamic Post and Category (if any) ---

            var post = ResolveBlogPostDetails();

            if (post == null || !post.IsBlogPost())
            {
                Agility.Web.Tracing.WebTrace.WriteErrorLine("Cannot resolve current dynamic item to a Blog Posts.");
                return(null);
            }

            var currentNode = SiteMap.CurrentNode;
            AgilityContentItem currentCategory = null;
            if (currentNode != null && currentNode.ParentNode != null)
            {
                currentCategory = AgilityContext.GetDynamicPageItem <AgilityContentItem>(currentNode.ParentNode);
            }

            //only set category if the parent dynamic item is a category
            if (currentCategory != null && !currentCategory.IsBlogCategory())
            {
                currentCategory = null;
            }
            #endregion


            #region --- Get Related Posts ---
            int relatedPostsLimit;
            int.TryParse(string.Format("{0}", module["RelatedPostsLimit"]), out relatedPostsLimit);
            if (relatedPostsLimit < 0)
            {
                relatedPostsLimit = 0;
            }
            var relatedPosts = BlogUtils.GetRelatedPosts(post, blogPosts, true, relatedPostsLimit);
            #endregion

            #region --- Set SEO Properties ---
            string canonicalUrl = post.BlogDynamicUrl(blogConfig, currentCategory);
            AgilityContext.CanonicalLink = BlogUtils.GetAbsoluteUrl(canonicalUrl);

            //Enables image for twitter cards - but twitter cards need to be enabled ...
            //to enable twitter cards include setting in app settings in web.config
            AgilityContext.FeaturedImageUrl = BlogUtils.GetPostImageUrl(blogConfig, post, PostImageType.Details);

            if (string.IsNullOrEmpty(AgilityContext.Page.MetaTags))
            {
                AgilityContext.Page.MetaTags = Server.HtmlEncode(BlogUtils.GetPostDescription(post, "Excerpt", 255, true));
            }

            string websiteName = blogConfig["WebsiteName"] as string;
            if (string.IsNullOrEmpty(websiteName))
            {
                websiteName = AgilityContext.WebsiteName;
            }
            AgilityContext.Page.MetaTagsRaw += string.Format(
                "{6}" +
                "<meta property='og:title' content='{0}' />" +
                "<meta property='og:type' content='{1}' />" +
                "<meta property='og:url' content='{2}' />" +
                "<meta property='og:image' content='{3}' />" +
                "<meta property='og:site_name' content='{4}' />" +
                "<meta property='og:description' content='{5}' />",
                Server.HtmlEncode(AgilityContext.Page.Title),
                "article",
                Request.Url.ToString(),
                BlogUtils.GetPostImageUrl(blogConfig, post, PostImageType.Details),
                websiteName,
                Server.HtmlEncode(AgilityContext.Page.MetaTags),
                Environment.NewLine
                );
            #endregion

            #region --- Set ViewModel ---
            var model = new PostViewModel();
            model.Configuration   = blogConfig;
            model.Post            = post;
            model.RelatedPosts    = relatedPosts;
            model.CurrentCategory = currentCategory;
            model.Module          = module;
            model.Categories      = BlogUtils.GetItemsByIDs(blogCategories.ContentReferenceName, post["CategoriesIDs"]);;
            model.Tags            = BlogUtils.GetItemsByIDs(blogTags.ContentReferenceName, post["BlogTagsIDs"]);;
            #endregion

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