Beispiel #1
0
        public GetBlogPostsResponse Get(GetBlogPostsRequest request)
        {
            request.Data.SetDefaultOrder("Title");

            var query = repository
                .AsQueryable<Module.Blog.Models.BlogPost>();

            if (!request.Data.IncludeArchived)
            {
                query = query.Where(b => !b.IsArchived);
            }

            if (!request.Data.IncludeUnpublished)
            {
                query = query.Where(b => b.Status == PageStatus.Published);
            }

            query = query.ApplyTagsFilter(
                request.Data,
                tagName => { return b => b.PageTags.Any(pageTag => pageTag.Tag.Name == tagName && !pageTag.IsDeleted && !pageTag.Tag.IsDeleted); });

            var listResponse = query
                .Select(blogPost => new BlogPostModel
                    {
                        Id = blogPost.Id,
                        Version = blogPost.Version,
                        CreatedBy = blogPost.CreatedByUser,
                        CreatedOn = blogPost.CreatedOn,
                        LastModifiedBy = blogPost.ModifiedByUser,
                        LastModifiedOn = blogPost.ModifiedOn,

                        BlogPostUrl = blogPost.PageUrl,
                        Title = blogPost.Title,
                        IntroText = blogPost.Description,
                        IsPublished = blogPost.Status == PageStatus.Published,
                        PublishedOn = blogPost.PublishedOn,
                        LayoutId = blogPost.Layout != null && !blogPost.Layout.IsDeleted ? blogPost.Layout.Id : Guid.Empty,
                        CategoryId = blogPost.Category != null && !blogPost.Category.IsDeleted ? blogPost.Category.Id : (Guid?)null,
                        CategoryName = blogPost.Category != null && !blogPost.Category.IsDeleted ? blogPost.Category.Name : null,
                        AuthorId = blogPost.Author != null && !blogPost.Author.IsDeleted ? blogPost.Author.Id : (Guid?)null,
                        AuthorName = blogPost.Author != null && !blogPost.Author.IsDeleted ? blogPost.Author.Name : null,
                        MainImageId = blogPost.Image != null && !blogPost.Image.IsDeleted ? blogPost.Image.Id : (Guid?)null,
                        MainImageUrl = blogPost.Image != null && !blogPost.Image.IsDeleted ? blogPost.Image.PublicUrl : null,
                        MainImageThumbnauilUrl = blogPost.Image != null && !blogPost.Image.IsDeleted ? blogPost.Image.PublicThumbnailUrl : null,
                        MainImageCaption = blogPost.Image != null && !blogPost.Image.IsDeleted ? blogPost.Image.Caption : null,
                        ActivationDate = blogPost.ActivationDate,
                        ExpirationDate = blogPost.ExpirationDate,
                        IsArchived = blogPost.IsArchived
                    })
                    .ToDataListResponse(request);

            return new GetBlogPostsResponse
                       {
                           Data = listResponse
                       };
        }
Beispiel #2
0
        public GetBlogPostsResponse Get(GetBlogPostsRequest request)
        {
            request.Data.SetDefaultOrder("Title");

            var query = repository
                        .AsQueryable <Module.Blog.Models.BlogPost>();

            if (!request.Data.IncludeArchived)
            {
                query = query.Where(b => !b.IsArchived);
            }

            if (!request.Data.IncludeUnpublished)
            {
                query = query.Where(b => b.Status == PageStatus.Published);
            }

            query = query.ApplyTagsFilter(
                request.Data,
                tagName => { return(b => b.PageTags.Any(tag => tag.Tag.Name == tagName)); });

            var listResponse = query
                               .Select(blogPost => new BlogPostModel
            {
                Id             = blogPost.Id,
                Version        = blogPost.Version,
                CreatedBy      = blogPost.CreatedByUser,
                CreatedOn      = blogPost.CreatedOn,
                LastModifiedBy = blogPost.ModifiedByUser,
                LastModifiedOn = blogPost.ModifiedOn,

                BlogPostUrl            = blogPost.PageUrl,
                Title                  = blogPost.Title,
                IntroText              = blogPost.Description,
                IsPublished            = blogPost.Status == PageStatus.Published,
                PublishedOn            = blogPost.PublishedOn,
                LayoutId               = blogPost.Layout.Id,
                CategoryId             = blogPost.Category.Id,
                CategoryName           = blogPost.Category.Name,
                AuthorId               = blogPost.Author.Id,
                AuthorName             = blogPost.Author.Name,
                MainImageId            = blogPost.Image.Id,
                MainImageUrl           = blogPost.Image.PublicUrl,
                MainImageThumbnauilUrl = blogPost.Image.PublicThumbnailUrl,
                MainImageCaption       = blogPost.Image.Caption,
                ActivationDate         = blogPost.ActivationDate,
                ExpirationDate         = blogPost.ExpirationDate,
                IsArchived             = blogPost.IsArchived
            }).ToDataListResponse(request);

            return(new GetBlogPostsResponse
            {
                Data = listResponse
            });
        }
Beispiel #3
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));
        }
Beispiel #4
0
        /// <summary>
        /// Gets the list of blog entities.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>
        /// The list of blog entities
        /// </returns>
        /// <exception cref="CmsApiException"></exception>
        public DataListResponse <BlogPost> GetBlogPosts(GetBlogPostsRequest request)
        {
            try
            {
                var query = Repository
                            .AsQueryable <BlogPost>()
                            .ApplyFilters(request);

                if (!request.IncludeUnpublished)
                {
                    query = query.Where(b => b.Status == PageStatus.Published);
                }

                if (!request.IncludePrivate)
                {
                    query = query.Where(b => b.IsPublic);
                }

                if (!request.IncludeNotActive)
                {
                    query = query.Where(b => b.ActivationDate < DateTime.Now && (!b.ExpirationDate.HasValue || DateTime.Now < b.ExpirationDate.Value));
                }

                var totalCount = query.ToRowCountFutureValue(request);

                query = query
                        .AddOrderAndPaging(request)
                        .Fetch(b => b.Author);

                return(query.ToDataListResponse(totalCount));
            }
            catch (Exception inner)
            {
                const string message = "Failed to get blog posts list.";
                Logger.Error(message, inner);

                throw new CmsApiException(message, inner);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Gets the list of blog entities.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>
        /// The list of blog entities
        /// </returns>
        /// <exception cref="CmsApiException"></exception>
        public DataListResponse<BlogPost> GetBlogPosts(GetBlogPostsRequest request)
        {
            try
            {
                var query = Repository
                    .AsQueryable<BlogPost>()
                    .ApplyFilters(request);

                if (!request.IncludeUnpublished)
                {
                    query = query.Where(b => b.Status == PageStatus.Published);
                }

                if (!request.IncludePrivate)
                {
                    query = query.Where(b => b.IsPublic);
                }

                if (!request.IncludeNotActive)
                {
                    query = query.Where(b => b.ActivationDate < DateTime.Now && (!b.ExpirationDate.HasValue || DateTime.Now < b.ExpirationDate.Value));
                }

                var totalCount = query.ToRowCountFutureValue(request);

                query = query
                    .AddOrderAndPaging(request)
                    .Fetch(b => b.Author);

                return query.ToDataListResponse(totalCount);
            }
            catch (Exception inner)
            {
                const string message = "Failed to get blog posts list.";
                Logger.Error(message, inner);

                throw new CmsApiException(message, inner);
            }
        }
        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);            
        }
Beispiel #7
0
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns><c>GetBlogPostsResponse</c> with a list of blog posts.</returns>
        public GetBlogPostsResponse Get(GetBlogPostsRequest request)
        {
            request.Data.SetDefaultOrder("Title");

            var query = repository
                        .AsQueryable <Module.Blog.Models.BlogPost>();

            if (!request.Data.IncludeArchived)
            {
                query = query.Where(b => !b.IsArchived);
            }

            if (!request.Data.IncludeUnpublished)
            {
                query = query.Where(b => b.Status == PageStatus.Published);
            }

            if (request.User != null && !string.IsNullOrWhiteSpace(request.User.Name))
            {
                var principal = new ApiPrincipal(request.User);
                IEnumerable <Guid> deniedPages = accessControlService.GetPrincipalDeniedObjects <PageProperties>(principal, false);
                foreach (var deniedPageId in deniedPages)
                {
                    var id = deniedPageId;
                    query = query.Where(f => f.Id != id);
                }
            }

            query = query.ApplyPageTagsFilter(request.Data)
                    .ApplyCategoriesFilter(categoryService, request.Data);

            var listResponse = query
                               .Select(blogPost => new BlogPostModel
            {
                Id             = blogPost.Id,
                Version        = blogPost.Version,
                CreatedBy      = blogPost.CreatedByUser,
                CreatedOn      = blogPost.CreatedOn,
                LastModifiedBy = blogPost.ModifiedByUser,
                LastModifiedOn = blogPost.ModifiedOn,

                BlogPostUrl                = blogPost.PageUrl,
                Title                      = blogPost.Title,
                IntroText                  = blogPost.Description,
                IsPublished                = blogPost.Status == PageStatus.Published,
                PublishedOn                = blogPost.PublishedOn,
                LayoutId                   = blogPost.Layout != null && !blogPost.Layout.IsDeleted ? blogPost.Layout.Id : (Guid?)null,
                MasterPageId               = blogPost.MasterPage != null && !blogPost.MasterPage.IsDeleted ? blogPost.MasterPage.Id : (Guid?)null,
                AuthorId                   = blogPost.Author != null && !blogPost.Author.IsDeleted ? blogPost.Author.Id : (Guid?)null,
                AuthorName                 = blogPost.Author != null && !blogPost.Author.IsDeleted ? blogPost.Author.Name : null,
                MainImageId                = blogPost.Image != null && !blogPost.Image.IsDeleted ? blogPost.Image.Id : (Guid?)null,
                MainImageUrl               = blogPost.Image != null && !blogPost.Image.IsDeleted ? blogPost.Image.PublicUrl : null,
                MainImageThumbnauilUrl     = blogPost.Image != null && !blogPost.Image.IsDeleted ? blogPost.Image.PublicThumbnailUrl : null,
                MainImageThumbnailUrl      = blogPost.Image != null && !blogPost.Image.IsDeleted ? blogPost.Image.PublicThumbnailUrl : null,
                MainImageCaption           = blogPost.Image != null && !blogPost.Image.IsDeleted ? blogPost.Image.Caption : null,
                SecondaryImageId           = blogPost.SecondaryImage != null && !blogPost.SecondaryImage.IsDeleted ? blogPost.SecondaryImage.Id : (Guid?)null,
                SecondaryImageUrl          = blogPost.SecondaryImage != null && !blogPost.SecondaryImage.IsDeleted ? blogPost.SecondaryImage.PublicUrl : null,
                SecondaryImageThumbnailUrl = blogPost.SecondaryImage != null && !blogPost.SecondaryImage.IsDeleted ? blogPost.SecondaryImage.PublicThumbnailUrl : null,
                SecondaryImageCaption      = blogPost.SecondaryImage != null && !blogPost.SecondaryImage.IsDeleted ? blogPost.SecondaryImage.Caption : null,
                FeaturedImageId            = blogPost.FeaturedImage != null && !blogPost.FeaturedImage.IsDeleted ? blogPost.FeaturedImage.Id : (Guid?)null,
                FeaturedImageUrl           = blogPost.FeaturedImage != null && !blogPost.FeaturedImage.IsDeleted ? blogPost.FeaturedImage.PublicUrl : null,
                FeaturedImageThumbnailUrl  = blogPost.FeaturedImage != null && !blogPost.FeaturedImage.IsDeleted ? blogPost.FeaturedImage.PublicThumbnailUrl : null,
                FeaturedImageCaption       = blogPost.FeaturedImage != null && !blogPost.FeaturedImage.IsDeleted ? blogPost.FeaturedImage.Caption : null,
                ActivationDate             = blogPost.ActivationDate,
                ExpirationDate             = blogPost.ExpirationDate,
                IsArchived                 = blogPost.IsArchived,
                LanguageId                 = blogPost.Language != null ? blogPost.Language.Id : (Guid?)null,
                LanguageCode               = blogPost.Language != null ? blogPost.Language.Code : null,
                LanguageGroupIdentifier    = blogPost.LanguageGroupIdentifier,
                ContentId                  = blogPost.PageContents.Where(pc => !pc.Content.IsDeleted && pc.Content is BlogPostContent)
                                             .Select(pc => pc.Content.Id)
                                             .FirstOrDefault()
            })
                               .ToDataListResponse(request);

            foreach (var model in listResponse.Items)
            {
                model.MainImageUrl           = fileUrlResolver.EnsureFullPathUrl(model.MainImageUrl);
                model.MainImageThumbnauilUrl = fileUrlResolver.EnsureFullPathUrl(model.MainImageThumbnauilUrl);
                model.MainImageThumbnailUrl  = fileUrlResolver.EnsureFullPathUrl(model.MainImageThumbnailUrl);

                model.SecondaryImageUrl          = fileUrlResolver.EnsureFullPathUrl(model.SecondaryImageUrl);
                model.SecondaryImageThumbnailUrl = fileUrlResolver.EnsureFullPathUrl(model.SecondaryImageThumbnailUrl);

                model.FeaturedImageUrl          = fileUrlResolver.EnsureFullPathUrl(model.FeaturedImageUrl);
                model.FeaturedImageThumbnailUrl = fileUrlResolver.EnsureFullPathUrl(model.FeaturedImageThumbnailUrl);
            }

            if (listResponse.Items.Count > 0 && (request.Data.IncludeTags || request.Data.IncludeAccessRules))
            {
                LoadTags(listResponse, request.Data.IncludeTags, request.Data.IncludeAccessRules);
            }


            if (request.Data.IncludeCategories)
            {
                listResponse.Items.ForEach(page =>
                {
                    page.Categories = (from pagePr in repository.AsQueryable <Module.Blog.Models.BlogPost>()
                                       from category in pagePr.Categories
                                       where pagePr.Id == page.Id && !category.IsDeleted
                                       select new CategoryModel
                    {
                        Id = category.Category.Id,
                        Version = category.Version,
                        CreatedBy = category.CreatedByUser,
                        CreatedOn = category.CreatedOn,
                        LastModifiedBy = category.ModifiedByUser,
                        LastModifiedOn = category.ModifiedOn,
                        Name = category.Category.Name
                    }).ToList();
                });
            }

            return(new GetBlogPostsResponse
            {
                Data = listResponse
            });
        }
Beispiel #8
0
        public GetBlogPostsResponse Get(GetBlogPostsRequest request)
        {
            request.Data.SetDefaultOrder("Title");

            var query = repository
                        .AsQueryable <Module.Blog.Models.BlogPost>();

            if (!request.Data.IncludeArchived)
            {
                query = query.Where(b => !b.IsArchived);
            }

            if (!request.Data.IncludeUnpublished)
            {
                query = query.Where(b => b.Status == PageStatus.Published);
            }

            query = query.ApplyPageTagsFilter(request.Data);

            var listResponse = query
                               .Select(blogPost => new BlogPostModel
            {
                Id             = blogPost.Id,
                Version        = blogPost.Version,
                CreatedBy      = blogPost.CreatedByUser,
                CreatedOn      = blogPost.CreatedOn,
                LastModifiedBy = blogPost.ModifiedByUser,
                LastModifiedOn = blogPost.ModifiedOn,

                BlogPostUrl            = blogPost.PageUrl,
                Title                  = blogPost.Title,
                IntroText              = blogPost.Description,
                IsPublished            = blogPost.Status == PageStatus.Published,
                PublishedOn            = blogPost.PublishedOn,
                LayoutId               = blogPost.Layout != null && !blogPost.Layout.IsDeleted ? blogPost.Layout.Id : Guid.Empty,
                CategoryId             = blogPost.Category != null && !blogPost.Category.IsDeleted ? blogPost.Category.Id : (Guid?)null,
                CategoryName           = blogPost.Category != null && !blogPost.Category.IsDeleted ? blogPost.Category.Name : null,
                AuthorId               = blogPost.Author != null && !blogPost.Author.IsDeleted ? blogPost.Author.Id : (Guid?)null,
                AuthorName             = blogPost.Author != null && !blogPost.Author.IsDeleted ? blogPost.Author.Name : null,
                MainImageId            = blogPost.Image != null && !blogPost.Image.IsDeleted ? blogPost.Image.Id : (Guid?)null,
                MainImageUrl           = blogPost.Image != null && !blogPost.Image.IsDeleted ? blogPost.Image.PublicUrl : null,
                MainImageThumbnauilUrl = blogPost.Image != null && !blogPost.Image.IsDeleted ? blogPost.Image.PublicThumbnailUrl : null,
                MainImageCaption       = blogPost.Image != null && !blogPost.Image.IsDeleted ? blogPost.Image.Caption : null,
                ActivationDate         = blogPost.ActivationDate,
                ExpirationDate         = blogPost.ExpirationDate,
                IsArchived             = blogPost.IsArchived
            })
                               .ToDataListResponse(request);

            foreach (var model in listResponse.Items)
            {
                model.MainImageUrl           = fileUrlResolver.EnsureFullPathUrl(model.MainImageUrl);
                model.MainImageThumbnauilUrl = fileUrlResolver.EnsureFullPathUrl(model.MainImageThumbnauilUrl);
            }

            if (request.Data.IncludeTags)
            {
                LoadTags(listResponse);
            }

            return(new GetBlogPostsResponse
            {
                Data = listResponse
            });
        }
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns><c>GetBlogPostsResponse</c> with a list of blog posts.</returns>
        public GetBlogPostsResponse Get(GetBlogPostsRequest request)
        {
            request.Data.SetDefaultOrder("Title");

            var query = repository
                .AsQueryable<Module.Blog.Models.BlogPost>();

            if (!request.Data.IncludeArchived)
            {
                query = query.Where(b => !b.IsArchived);
            }

            if (!request.Data.IncludeUnpublished)
            {
                query = query.Where(b => b.Status == PageStatus.Published);
            }

            if (request.User != null && !string.IsNullOrWhiteSpace(request.User.Name))
            {
                var principal = new ApiPrincipal(request.User);
                IEnumerable<Guid> deniedPages = accessControlService.GetPrincipalDeniedObjects<PageProperties>(principal, false);
                foreach (var deniedPageId in deniedPages)
                {
                    var id = deniedPageId;
                    query = query.Where(f => f.Id != id);
                }
            }

            query = query.ApplyPageTagsFilter(request.Data);

            var listResponse = query
                .Select(blogPost => new BlogPostModel
                    {
                        Id = blogPost.Id,
                        Version = blogPost.Version,
                        CreatedBy = blogPost.CreatedByUser,
                        CreatedOn = blogPost.CreatedOn,
                        LastModifiedBy = blogPost.ModifiedByUser,
                        LastModifiedOn = blogPost.ModifiedOn,

                        BlogPostUrl = blogPost.PageUrl,
                        Title = blogPost.Title,
                        IntroText = blogPost.Description,
                        IsPublished = blogPost.Status == PageStatus.Published,
                        PublishedOn = blogPost.PublishedOn,
                        LayoutId = blogPost.Layout != null && !blogPost.Layout.IsDeleted ? blogPost.Layout.Id : (Guid?)null,
                        MasterPageId = blogPost.MasterPage != null && !blogPost.MasterPage.IsDeleted ? blogPost.MasterPage.Id : (Guid?)null,
                        CategoryId = blogPost.Category != null && !blogPost.Category.IsDeleted ? blogPost.Category.Id : (Guid?)null,
                        CategoryName = blogPost.Category != null && !blogPost.Category.IsDeleted ? blogPost.Category.Name : null,
                        AuthorId = blogPost.Author != null && !blogPost.Author.IsDeleted ? blogPost.Author.Id : (Guid?)null,
                        AuthorName = blogPost.Author != null && !blogPost.Author.IsDeleted ? blogPost.Author.Name : null,
                        MainImageId = blogPost.Image != null && !blogPost.Image.IsDeleted ? blogPost.Image.Id : (Guid?)null,
                        MainImageUrl = blogPost.Image != null && !blogPost.Image.IsDeleted ? blogPost.Image.PublicUrl : null,
                        MainImageThumbnauilUrl = blogPost.Image != null && !blogPost.Image.IsDeleted ? blogPost.Image.PublicThumbnailUrl : null,
                        MainImageCaption = blogPost.Image != null && !blogPost.Image.IsDeleted ? blogPost.Image.Caption : null,
                        ActivationDate = blogPost.ActivationDate,
                        ExpirationDate = blogPost.ExpirationDate,
                        IsArchived = blogPost.IsArchived
                    })
                    .ToDataListResponse(request);

            foreach (var model in listResponse.Items)
            {
                model.MainImageUrl = fileUrlResolver.EnsureFullPathUrl(model.MainImageUrl);
                model.MainImageThumbnauilUrl = fileUrlResolver.EnsureFullPathUrl(model.MainImageThumbnauilUrl);
            }

            if (listResponse.Items.Count > 0 && (request.Data.IncludeTags || request.Data.IncludeAccessRules))
            {
                LoadTags(listResponse, request.Data.IncludeTags, request.Data.IncludeAccessRules);
            }

            return new GetBlogPostsResponse
                       {
                           Data = listResponse
                       };
        }