public void BlogPostsWidget_FilterBlogPostsByTags() { int countOfItemsWithTag = 1; string blogTitle = "Blog"; string blogPost1Title = "BlogPost_WithTag"; string blogPost2Title = "BlogPost_NoTag"; string tagTitle = "TestTag"; BlogPostController blogPostsController = new BlogPostController(); try { Guid blogId = ServerOperations.Blogs().CreateBlog(blogTitle); ServerOperations.Blogs().CreatePublishedBlogPost(blogPost2Title, blogId); var taxonId = ServerOperations.Taxonomies().CreateFlatTaxon(TaxonomiesConstants.TagsTaxonomyId, tagTitle); var blogPost1Id = ServerOperations.Blogs().CreatePublishedBlogPost(blogPost1Title, blogId); ServerOperations.Blogs().AssignTaxonToBlogPost(blogPost1Id, "Tags", taxonId); ITaxon taxonomy = TaxonomyManager.GetManager().GetTaxon(taxonId); var items = blogPostsController.Model.CreateListViewModel(taxonomy, 1).Items.ToArray(); Assert.AreEqual(countOfItemsWithTag, items.Count()); Assert.IsTrue(items[0].Fields.Title.Equals(blogPost1Title, StringComparison.CurrentCulture), "The blog post with this title was not found!"); } finally { ServerOperations.Taxonomies().DeleteTags(tagTitle); ServerOperations.Blogs().DeleteAllBlogs(); } }
/// <summary> /// Add blog posts widget to existing page. /// </summary> /// <param name="pageId">The page Id.</param> /// <param name="placeholder">The placeholderId.</param> /// <param name="parentFilterMode">The parent filter mode.</param> public void AddBlogPostsWidgetToPage(Guid pageId, string placeholder, ParentFilterMode parentFilterMode) { PageManager pageManager = PageManager.GetManager(); pageManager.Provider.SuppressSecurityChecks = true; var pageDataId = pageManager.GetPageNode(pageId).PageId; var page = pageManager.EditPage(pageDataId, CultureInfo.CurrentUICulture); using (var mvcWidget = new Telerik.Sitefinity.Mvc.Proxy.MvcControllerProxy()) { mvcWidget.ControllerName = typeof(BlogPostController).FullName; var controller = new BlogPostController(); controller.Model.ParentFilterMode = parentFilterMode; mvcWidget.Settings = new ControllerSettings(controller); this.CreateControl(pageManager, page, mvcWidget, "Blog posts", placeholder); } }
private MvcWidgetProxy CreateBlogPostsMvcWidget(Guid selectedParentId, ParentFilterMode parentMode, SelectionMode selectionMode, Guid selectedItemId) { var mvcProxy = new MvcWidgetProxy(); mvcProxy.ControllerName = typeof(BlogPostController).FullName; var controller = new BlogPostController(); controller.Model.ParentFilterMode = parentMode; controller.Model.SelectionMode = selectionMode; if (selectedParentId != null) { controller.Model.SerializedSelectedParentsIds = "[" + selectedParentId.ToString() + "]"; } if (selectedItemId != null) { controller.Model.SerializedSelectedItemsIds = "[" + selectedItemId.ToString() + "]"; } mvcProxy.Settings = new ControllerSettings(controller); return mvcProxy; }
private MvcWidgetProxy CreateBlogPostsMvcWidget(ListDisplayMode displayMode, int itemsPerPage, string sortExpression) { var mvcProxy = new MvcWidgetProxy(); mvcProxy.ControllerName = typeof(BlogPostController).FullName; var controller = new BlogPostController(); controller.Model.DisplayMode = displayMode; controller.Model.ItemsPerPage = itemsPerPage; controller.Model.SortExpression = sortExpression; mvcProxy.Settings = new ControllerSettings(controller); return mvcProxy; }