private void SortAndFilterRequest(GetBlogPostsModel request) { var tagName = Request.QueryString["blogtag"]; var categoryName = Request.QueryString["blogcategory"]; var orFilter = new DataFilter(FilterConnector.Or); orFilter.Add("ExpirationDate", null); orFilter.Add("ExpirationDate", DateTime.Today, FilterOperation.GreaterOrEqual); request.Order.By.Add(new OrderItem("ActivationDate", OrderDirection.Desc)); request.Order.By.Add(new OrderItem("Id")); request.Filter.Add("ActivationDate", DateTime.Today, FilterOperation.LessOrEqual); request.Filter.Inner.Add(orFilter); if (!string.IsNullOrEmpty(categoryName)) { request.FilterByCategoriesNames.Add(categoryName); } if (!string.IsNullOrEmpty(tagName)) { request.FilterByTags.Add(tagName); } }
public virtual ActionResult SubMenu(string parentUrl) { var menuItems = new List <MenuItemViewModel>(); using (var api = ApiFactory.Create()) { var pageRequest = new PageExistsRequest { PageUrl = parentUrl }; var pageResponse = api.Pages.Page.Exists(pageRequest); var sitemapId = GetSitemapId(api); if (sitemapId.HasValue) { var parentRequest = new GetSitemapNodesRequest(); parentRequest.SitemapId = sitemapId.Value; parentRequest.Data.Take = 1; parentRequest.Data.Filter.Add("ParentId", null); var filter = new DataFilter(FilterConnector.Or); parentRequest.Data.Filter.Inner.Add(filter); filter.Add("Url", parentUrl); if (pageResponse.Data.Exists) { filter.Add("PageId", pageResponse.Data.PageId.Value); } parentRequest.Data.Order.Add("DisplayOrder"); var parentResponse = api.Pages.Sitemap.Nodes.Get(parentRequest); if (parentResponse.Data.Items.Count == 1) { var request = new GetSitemapTreeRequest { SitemapId = sitemapId.Value }; request.Data.NodeId = parentResponse.Data.Items[0].Id; var response = api.Pages.Sitemap.Tree.Get(request); if (response.Data.Count > 0) { menuItems = response.Data.Select(mi => new MenuItemViewModel { Caption = mi.Title, Url = mi.Url }).ToList(); menuItems.Insert(0, new MenuItemViewModel { Caption = "Main", Url = parentUrl }); } } } } return(View(menuItems)); }
public void ComplexFilterWithInnerFiltersAndOrderBy() { var dataOptions = new DataOptions(); dataOptions.Filter.Connector = FilterConnector.And; dataOptions.Filter.Add("Title", "Test1", FilterOperation.NotContains); dataOptions.Filter.Add("Title", "Test2", FilterOperation.NotContains); var innerFilter1 = new DataFilter(FilterConnector.Or); innerFilter1.Add("CreatedOn", Convert.ToDateTime(TestValueDate), FilterOperation.Greater); innerFilter1.Add("CreatedOn", Convert.ToDateTime(TestValueDate), FilterOperation.Less); innerFilter1.Add("CreatedOn", Convert.ToDateTime(TestValueDate)); var innerFilter2 = new DataFilter(FilterConnector.Or); innerFilter2.Add("ModifiedOn", Convert.ToDateTime(TestValueDate), FilterOperation.Greater); innerFilter2.Add("ModifiedOn", Convert.ToDateTime(TestValueDate), FilterOperation.Less); innerFilter2.Add("ModifiedOn", Convert.ToDateTime(TestValueDate)); dataOptions.Filter.Inner.Add(innerFilter1); dataOptions.Filter.Inner.Add(innerFilter2); dataOptions.Order.Add("CreatedOn", OrderDirection.Desc); dataOptions.Order.Add("Title"); dataOptions.Order.Add("Description", OrderDirection.Desc); var queryCreator = new DataOptionsQueryCreator <PageProperties>(dataOptions); var orderQuery = queryCreator.GetOrderQuery(); var filterQuery = queryCreator.GetFilterQuery(); var filterParameters = queryCreator.GetFilterParameters(); Assert.AreEqual(orderQuery, "CreatedOn desc, Title, Description desc"); var result = "(!Title.Contains(@0) or Title == null) and (!Title.Contains(@1) or Title == null) and (CreatedOn > @2 or CreatedOn < @3 or CreatedOn == @4) and (ModifiedOn > @5 or ModifiedOn < @6 or ModifiedOn == @7)"; Assert.AreEqual(filterQuery, result); Assert.IsNotNull(filterParameters); Assert.AreEqual(filterParameters.Length, 8); Assert.AreEqual(filterParameters[0], "Test1"); Assert.AreEqual(filterParameters[1], "Test2"); Assert.AreEqual(filterParameters[2], Convert.ToDateTime(TestValueDate)); Assert.AreEqual(filterParameters[3], Convert.ToDateTime(TestValueDate)); Assert.AreEqual(filterParameters[4], Convert.ToDateTime(TestValueDate)); Assert.AreEqual(filterParameters[5], Convert.ToDateTime(TestValueDate)); Assert.AreEqual(filterParameters[6], Convert.ToDateTime(TestValueDate)); Assert.AreEqual(filterParameters[7], Convert.ToDateTime(TestValueDate)); }
public virtual ActionResult Index(Guid?categoryId, string tagName) { IList <BlogItem> posts; using (var api = ApiFactory.Create()) { var request = new GetBlogPostsModel { Take = 10, IncludeTags = true }; var orFilter = new DataFilter(FilterConnector.Or); orFilter.Add("ExpirationDate", null); orFilter.Add("ExpirationDate", DateTime.Today, FilterOperation.GreaterOrEqual); request.Order.By.Add(new OrderItem("ActivationDate", OrderDirection.Desc)); request.Order.By.Add(new OrderItem("Id")); request.Filter.Add("ActivationDate", DateTime.Today, FilterOperation.LessOrEqual); request.Filter.Inner.Add(orFilter); if (categoryId.HasValue) { request.FilterByCategories = new List <Guid> { categoryId.Value }; } if (!string.IsNullOrEmpty(tagName)) { request.FilterByTags.Add(tagName); } var pages = api.Blog.BlogPosts.Get(new GetBlogPostsRequest { Data = request }); posts = pages.Data.Items.Select( x => new BlogItem { IntroText = x.IntroText, PublishedOn = x.ActivationDate, Title = x.Title, Url = x.BlogPostUrl, Author = x.AuthorName, Tags = x.Tags }).ToList(); } return(View(posts)); }
public virtual ActionResult Last() { BlogItem post = null; using (var api = ApiFactory.Create()) { var requestLatestNewsModel = new GetBlogPostsModel { Take = 1, IncludeTags = true }; var orFilter = new DataFilter(FilterConnector.Or); orFilter.Add("ExpirationDate", null); orFilter.Add("ExpirationDate", DateTime.Today, FilterOperation.GreaterOrEqual); requestLatestNewsModel.Order.By.Add(new OrderItem("ActivationDate", OrderDirection.Desc)); requestLatestNewsModel.Order.By.Add(new OrderItem("Id")); requestLatestNewsModel.Filter.Add("ActivationDate", DateTime.Today, FilterOperation.LessOrEqual); requestLatestNewsModel.Filter.Inner.Add(orFilter); var request = new GetBlogPostsRequest { Data = requestLatestNewsModel }; var pages = api.Blog.BlogPosts.Get(request); post = pages.Data.Items.Select( x => new BlogItem { IntroText = x.IntroText, PublishedOn = x.ActivationDate, Title = x.Title, Url = x.BlogPostUrl, Author = x.AuthorName, Tags = x.Tags }).SingleOrDefault(); } return(View(post)); }
private DataOptions CreateTestDataOptions() { var options = new DataOptions(5, 3); options.Filter.Add("CreatedOn", new DateTime(2013, 06, 01), FilterOperation.Greater); options.Filter.Add("Title", "Africa", FilterOperation.NotEqual); var subFilter = new DataFilter(FilterConnector.Or); subFilter.Add("Title", "It", FilterOperation.StartsWith); subFilter.Add("Title", "Af", FilterOperation.StartsWith); subFilter.Add("Title", "na", FilterOperation.EndsWith); subFilter.Add("Title", "Spain"); options.Filter.Inner.Add(subFilter); options.Order.Add("CreatedOn"); options.Order.Add("Title", OrderDirection.Desc); return(options); }
public virtual ActionResult Feed() { IList <BlogItem> posts; using (var api = ApiFactory.Create()) { var request = new GetBlogPostsModel { Take = 10, IncludeTags = true }; var orFilter = new DataFilter(FilterConnector.Or); orFilter.Add("ExpirationDate", null); orFilter.Add("ExpirationDate", DateTime.Today, FilterOperation.GreaterOrEqual); request.Order.By.Add(new OrderItem("ActivationDate", OrderDirection.Desc)); request.Order.By.Add(new OrderItem("Id")); request.Filter.Add("ActivationDate", DateTime.Today, FilterOperation.LessOrEqual); var pages = api.Blog.BlogPosts.Get(new GetBlogPostsRequest { Data = request }); posts = pages.Data.Items.Select( x => new BlogItem { IntroText = x.IntroText, PublishedOn = x.ActivationDate, Title = x.Title, Url = x.BlogPostUrl, Author = x.AuthorName, ImageUrl = x.MainImageUrl, Tags = x.Tags }).ToList(); } return(View(posts)); }