Example #1
0
        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);
        }
        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);
        }
Example #3
0
        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.Filter.Add("CategoryId", 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);
        }
Example #4
0
        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);            
        }
Example #5
0
        public void ComplexFilterWithInnerFilters()
        {
            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", TestValueDate, FilterOperation.Greater);
            innerFilter1.Add("CreatedOn", TestValueDate, FilterOperation.Less);
            innerFilter1.Add("CreatedOn", TestValueDate);

            var innerFilter2 = new DataFilter(FilterConnector.Or);
            innerFilter2.Add("ModifiedOn", TestValueDate, FilterOperation.Greater);
            innerFilter2.Add("ModifiedOn", TestValueDate, FilterOperation.Less);
            innerFilter2.Add("ModifiedOn", TestValueDate);

            dataOptions.Filter.Inner.Add(innerFilter1);
            dataOptions.Filter.Inner.Add(innerFilter2);

            var queryCreator = new DataOptionsQueryCreator<PageProperties>(dataOptions);
            var orderQuery = queryCreator.GetOrderQuery();
            var filterQuery = queryCreator.GetFilterQuery();
            var filterParameters = queryCreator.GetFilterParameters();

            Assert.AreEqual(orderQuery, string.Empty);

            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));
        }
Example #6
0
        public virtual ActionResult Feed(Guid? categoryId, string tagName, string year, string month)
        {
            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);

                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,
                            ImageUrl = x.MainImageUrl,
                            Tags = x.Tags
                        }).ToList();
            }

            //search by year
            if (!string.IsNullOrEmpty(year) && string.IsNullOrEmpty(month))
            {

                var p = new List<BlogItem>();

                foreach (var x in posts)
                {
                    if (x.PublishedOn.Year.ToString() == year)
                    {
                        p.Add(x);
                    }

                }

                return View(p);

            }

            //search by month
            if (!string.IsNullOrEmpty(year) && !string.IsNullOrEmpty(month))
            {

                var m = new List<BlogItem>();
                var y = new List<BlogItem>();

                foreach (var x in posts)
                {
                    if (x.PublishedOn.Year.ToString() == year)
                    {
                        y.Add(x);
                    }

                }

                foreach (var x in y)
                {
                    if (x.PublishedOn.Month.ToString() == month)
                    {
                        m.Add(x);
                    }

                }

                return View(m);

            }
            return View(posts);
        }
Example #7
0
        public virtual ActionResult Feed(string keywordsForSearch)
        {
            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();
            }

            if (!string.IsNullOrEmpty(keywordsForSearch))
            {
                List<BlogItem> searchlist = new List<BlogItem>();

                //search in title
                var v = posts.Where(r => r.Title.Contains(keywordsForSearch)).ToList();
                if (v.Count > 0)
                {
                    foreach (var x in v)
                    {
                        searchlist.Add(x);

                    }
                }

                //search by introtext
                var v1 = posts.Where(r => r.IntroText.Contains(keywordsForSearch)).ToList();
                if (v1.Count > 0)
                {
                    foreach (var x1 in v1)
                    {
                        searchlist.Add(x1);

                    }
                }

                //var v2 = posts.Where(r => r.Url.Contains(keywordsForSearch)).ToList();

                //if(v2.Count >0 ){

                //    foreach (var x2 in v2)
                //    {

                //        searchlist.Add(x2);
                //    }
                //}

                //creating distinct list
                List<string> Distinct_searchlist = new List<string>();
                List<BlogItem> new_distinct_blogitems = new List<BlogItem>();

                foreach (var s in searchlist)
                {
                    if (!Distinct_searchlist.Contains(s.Title))
                    {
                        Distinct_searchlist.Add(s.Title);
                        new_distinct_blogitems.Add(s);

                    }

                }

                return View(new_distinct_blogitems);

            }

            return View(posts);
        }
Example #8
0
        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);
            }
        }
Example #9
0
        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;
        }