Beispiel #1
0
        /// <summary>
        /// Executes the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>List with blog post view models</returns>
        public SearchableGridViewModel <SubscriberViewModel> Execute(SearchableGridOptions request)
        {
            SearchableGridViewModel <SubscriberViewModel> model;

            request.SetDefaultSortingOptions("Email");

            var query = Repository
                        .AsQueryable <Subscriber>();

            if (!string.IsNullOrWhiteSpace(request.SearchQuery))
            {
                query = query.Where(a => a.Email.Contains(request.SearchQuery));
            }

            var subscribers = query
                              .Select(subscriber =>
                                      new SubscriberViewModel
            {
                Id      = subscriber.Id,
                Version = subscriber.Version,
                Email   = subscriber.Email
            });

            var count = query.ToRowCountFutureValue();

            subscribers = subscribers.AddSortingAndPaging(request);

            model = new SearchableGridViewModel <SubscriberViewModel>(subscribers.ToList(), request, count.Value);

            return(model);
        }
        /// <summary>
        /// Executes the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>List with blog post view models</returns>
        public SearchableGridViewModel <AuthorViewModel> Execute(SearchableGridOptions request)
        {
            var query   = Repository.AsQueryable <Author>();
            var authors = query.Select(
                author =>
                new AuthorViewModel
            {
                Id      = author.Id,
                Version = author.Version,
                Name    = author.Name,
                Image   = author.Image != null
                                    ?
                          new ImageSelectorViewModel
                {
                    ImageId      = author.Image.Id,
                    ImageVersion = author.Image.Version,
                    ImageUrl     = author.Image.PublicUrl,
                    ThumbnailUrl = author.Image.PublicThumbnailUrl,
                    ImageTooltip = author.Image.Caption
                }
                                    : null
            });

            if (!string.IsNullOrWhiteSpace(request.SearchQuery))
            {
                authors = authors.Where(a => a.Name.Contains(request.SearchQuery));
            }

            request.SetDefaultSortingOptions("Name");
            var count = authors.ToRowCountFutureValue();

            authors = authors.AddSortingAndPaging(request);

            return(new SearchableGridViewModel <AuthorViewModel>(authors.ToList(), request, count.Value));
        }
Beispiel #3
0
        /// <summary>
        /// Executes this command.
        /// </summary>
        /// <param name="request">A filter to search for specific tags.</param>
        /// <returns>A list of tags.</returns>
        public SearchableGridViewModel <TagItemViewModel> Execute(SearchableGridOptions request)
        {
            SearchableGridViewModel <TagItemViewModel> model;

            request.SetDefaultSortingOptions("Name");

            Root.Models.Tag  alias      = null;
            TagItemViewModel modelAlias = null;

            var query = UnitOfWork.Session
                        .QueryOver(() => alias)
                        .Where(() => !alias.IsDeleted);

            if (!string.IsNullOrWhiteSpace(request.SearchQuery))
            {
                var searchQuery = string.Format("%{0}%", request.SearchQuery);
                query = query.Where(Restrictions.InsensitiveLike(NHibernate.Criterion.Projections.Property(() => alias.Name), searchQuery));
            }

            query = query
                    .SelectList(select => select
                                .Select(() => alias.Id).WithAlias(() => modelAlias.Id)
                                .Select(() => alias.Name).WithAlias(() => modelAlias.Name)
                                .Select(() => alias.Version).WithAlias(() => modelAlias.Version))
                    .TransformUsing(Transformers.AliasToBean <TagItemViewModel>());

            var count = query.ToRowCountFutureValue();

            var tags = query.AddSortingAndPaging(request).Future <TagItemViewModel>();

            model = new SearchableGridViewModel <TagItemViewModel>(tags.ToList(), request, count.Value);

            return(model);
        }
Beispiel #4
0
        public SearchableGridViewModel <UserItemViewModel> Execute(SearchableGridOptions request)
        {
            request.SetDefaultSortingOptions("UserName");

            var query = Repository
                        .AsQueryable <Models.User>()
                        .Select(user => new UserItemViewModel
            {
                Id       = user.Id,
                Version  = user.Version,
                UserName = user.UserName,
                FullName = (user.FirstName ?? string.Empty)
                           + (user.FirstName != null && user.LastName != null ? " " : string.Empty)
                           + (user.LastName ?? string.Empty),
                Email = user.Email
            });

            // Search
            if (!string.IsNullOrWhiteSpace(request.SearchQuery))
            {
                query = query.Where(user => user.UserName.Contains(request.SearchQuery) ||
                                    user.Email.Contains(request.SearchQuery) ||
                                    user.FullName.Contains(request.SearchQuery));
            }

            // Total count
            var count = query.ToRowCountFutureValue();

            // Sorting, Paging
            query = query.AddSortingAndPaging(request);

            return(new SearchableGridViewModel <UserItemViewModel>(query.ToFuture().ToList(), request, count.Value));
        }
Beispiel #5
0
        public SearchableGridViewModel <RoleViewModel> Execute(SearchableGridOptions request)
        {
            var roles = Repository
                        .AsQueryable <Models.Role>()
                        .Select(role => new RoleViewModel
            {
                Id           = role.Id,
                Version      = role.Version,
                Name         = role.Name,
                Description  = role.Description,
                IsSystematic = role.IsSystematic
            });

            if (!string.IsNullOrWhiteSpace(request.SearchQuery))
            {
                roles = roles
                        .Where(a => a.Name.Contains(request.SearchQuery.ToLower().ToLowerInvariant()) ||
                               a.Description != null && a.Description.ToLower().Contains(request.SearchQuery.ToLowerInvariant()));
            }

            request.SetDefaultSortingOptions("Name");
            var count = roles.ToRowCountFutureValue();

            roles = roles.AddSortingAndPaging(request);

            return(new SearchableGridViewModel <RoleViewModel>(roles.ToFuture().ToList(), request, count.Value));
        }
Beispiel #6
0
        public SearchableGridViewModel <CategoryViewModel> Execute(SearchableGridOptions request)
        {
            request.SetDefaultSortingOptions("Name");

            var query = Repository
                        .AsQueryable <Models.FaqCategory>()
                        .Select(category => new CategoryViewModel
            {
                Id        = category.Id,
                Version   = category.Version,
                Name      = category.Name,
                Name_en   = category.Name_en,
                SortOrder = category.SortOrder
            });

            //search
            if (!string.IsNullOrWhiteSpace(request.SearchQuery))
            {
                query = query.Where(category => category.Name.Contains(request.SearchQuery) || category.Name_en.Contains(request.SearchQuery));
            }
            //total count
            var count = query.ToRowCountFutureValue();

            //sorting, paging
            query = query.AddSortingAndPaging(request);
            return(new SearchableGridViewModel <CategoryViewModel>(query.ToList(), request, count.Value));
        }
Beispiel #7
0
        public SearchableGridViewModel <FaqViewModel> Execute(SearchableGridOptions request)
        {
            request.SetDefaultSortingOptions("Question");

            var query = Repository
                        .AsQueryable <Models.Faq>()
                        .Select(t => new FaqViewModel
            {
                Id          = t.Id,
                Version     = t.Version,
                CategoryId  = t.CategoryId,
                Question    = t.Question,
                Question_en = t.Question_en,
                Answer      = t.Answer,
                Answer_en   = t.Answer_en,
                SortOrder   = t.SortOrder
            });

            //search
            if (!string.IsNullOrWhiteSpace(request.SearchQuery))
            {
                query = query.Where(t => t.Question.Contains(request.SearchQuery) || t.Question_en.Contains(request.SearchQuery));
            }
            //total count
            var count = query.ToRowCountFutureValue();

            //sorting, paging
            query = query.AddSortingAndPaging(request);
            return(new SearchableGridViewModel <FaqViewModel>(query.ToList(), request, count.Value));
        }
        /// <summary>
        /// Executes the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>List with languages view models</returns>
        public SearchableGridViewModel <LanguageViewModel> Execute(SearchableGridOptions request)
        {
            SearchableGridViewModel <LanguageViewModel> model;

            request.SetDefaultSortingOptions("Name");

            var query = Repository
                        .AsQueryable <Models.Language>();

            if (!string.IsNullOrWhiteSpace(request.SearchQuery))
            {
                query = query.Where(language => language.Name.Contains(request.SearchQuery) || language.Code.Contains(request.SearchQuery));
            }

            var languagesFuture = query
                                  .Select(language =>
                                          new LanguageViewModel
            {
                Id      = language.Id,
                Version = language.Version,
                Name    = language.Name,
                Code    = language.Code
            });

            var count = query.ToRowCountFutureValue();

            languagesFuture = languagesFuture.AddSortingAndPaging(request);

            var languages = languagesFuture.ToList();

            SetLanguageCodes(languages);
            model = new SearchableGridViewModel <LanguageViewModel>(languages, request, count.Value);

            return(model);
        }
        /// <summary>
        /// Executes the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>Result model.</returns>
        public SearchableGridViewModel <SiteSettingPageViewModel> Execute(SearchableGridOptions request)
        {
            request.SetDefaultSortingOptions("Title");

            PageProperties           alias      = null;
            SiteSettingPageViewModel modelAlias = null;

            var query = UnitOfWork.Session
                        .QueryOver(() => alias)
                        .Where(() => !alias.IsDeleted && alias.Status != PageStatus.Preview);

            if (!string.IsNullOrWhiteSpace(request.SearchQuery))
            {
                var searchQuery = string.Format("%{0}%", request.SearchQuery);
                query = query.Where(Restrictions.Disjunction()
                                    .Add(Restrictions.InsensitiveLike(NHibernate.Criterion.Projections.Property(() => alias.Title), searchQuery))
                                    .Add(Restrictions.InsensitiveLike(NHibernate.Criterion.Projections.Property(() => alias.PageUrl), searchQuery))
                                    .Add(Restrictions.InsensitiveLike(Projections.Property(() => alias.MetaTitle), searchQuery))
                                    .Add(Restrictions.InsensitiveLike(NHibernate.Criterion.Projections.Property(() => alias.MetaDescription), searchQuery))
                                    .Add(Restrictions.InsensitiveLike(NHibernate.Criterion.Projections.Property(() => alias.MetaKeywords), searchQuery)));
            }

            IProjection hasSeoProjection = NHibernate.Criterion.Projections.Conditional(
                Restrictions.Disjunction()
                .Add(RestrictionsExtensions.IsNullOrWhiteSpace(NHibernate.Criterion.Projections.Property(() => alias.MetaTitle)))
                .Add(RestrictionsExtensions.IsNullOrWhiteSpace(NHibernate.Criterion.Projections.Property(() => alias.MetaKeywords)))
                .Add(RestrictionsExtensions.IsNullOrWhiteSpace(NHibernate.Criterion.Projections.Property(() => alias.MetaDescription))),
                NHibernate.Criterion.Projections.Constant(false, NHibernateUtil.Boolean),
                NHibernate.Criterion.Projections.Constant(true, NHibernateUtil.Boolean));

            query = query
                    .SelectList(select => select
                                .Select(() => alias.Id).WithAlias(() => modelAlias.Id)
                                .Select(() => alias.Version).WithAlias(() => modelAlias.Version)
                                .Select(() => alias.Title).WithAlias(() => modelAlias.Title)
                                .Select(() => alias.Status).WithAlias(() => modelAlias.PageStatus)
                                .Select(hasSeoProjection).WithAlias(() => modelAlias.HasSEO)
                                .Select(() => alias.CreatedOn).WithAlias(() => modelAlias.CreatedOn)
                                .Select(() => alias.ModifiedOn).WithAlias(() => modelAlias.ModifiedOn)
                                .Select(() => alias.PageUrl).WithAlias(() => modelAlias.Url))
                    .TransformUsing(Transformers.AliasToBean <SiteSettingPageViewModel>());

            var count = query.ToRowCountFutureValue();

            var pages = query.AddSortingAndPaging(request).Future <SiteSettingPageViewModel>();

            return(new SearchableGridViewModel <SiteSettingPageViewModel>(pages.ToList(), request, count.Value));
        }
Beispiel #10
0
        public IList <RoleItemViewModel> Execute(SearchableGridOptions gridOptions)
        {
            var roles = Repository
                        .AsQueryable <Models.Role>()
                        .Select(t => new RoleItemViewModel()
            {
                Id       = t.Id,
                Version  = t.Version,
                RoleName = t.Name
            });

            if (gridOptions != null)
            {
                gridOptions.SetDefaultSortingOptions("RoleName");
            }

            return(roles.AddSortingAndPaging(gridOptions).ToFuture().ToList());
        }
Beispiel #11
0
        public IList <UserItemViewModel> Execute(SearchableGridOptions gridOptions)
        {
            // var role = new List<Models.Role>().Add(new Models.Role(){ Name = "name" });
            var users = Repository.AsQueryable <Models.Users>()
                        .Select(t => new UserItemViewModel()
            {
                Id       = t.Id,
                Version  = t.Version,
                UserName = t.UserName,
            });

            if (gridOptions != null)
            {
                gridOptions.SetDefaultSortingOptions("UserName");
            }


            return(users.AddSortingAndPaging(gridOptions).ToFuture().ToList());
        }
Beispiel #12
0
        /// <summary>
        /// Executes the specified request.
        /// </summary>
        /// <param name="options">The request.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public SearchableGridViewModel <SiteSettingRedirectViewModel> Execute(SearchableGridOptions options)
        {
            SearchableGridViewModel <SiteSettingRedirectViewModel> model;

            options.SetDefaultSortingOptions("PageUrl");

            Models.Redirect alias = null;
            SiteSettingRedirectViewModel modelAlias = null;

            var query = UnitOfWork.Session.QueryOver(() => alias).Where(() => !alias.IsDeleted);

            if (!string.IsNullOrWhiteSpace(options.SearchQuery))
            {
                var searchQuery = string.Format("%{0}%", options.SearchQuery);
                query =
                    query.Where(
                        Restrictions.InsensitiveLike(Projections.Property(() => alias.PageUrl), searchQuery) ||
                        Restrictions.InsensitiveLike(Projections.Property(() => alias.RedirectUrl), searchQuery));
            }

            query =
                query.SelectList(
                    select =>
                    select.Select(() => alias.Id)
                    .WithAlias(() => modelAlias.Id)
                    .Select(() => alias.PageUrl)
                    .WithAlias(() => modelAlias.PageUrl)
                    .Select(() => alias.RedirectUrl)
                    .WithAlias(() => modelAlias.RedirectUrl)
                    .Select(() => alias.Version)
                    .WithAlias(() => modelAlias.Version)).TransformUsing(Transformers.AliasToBean <SiteSettingRedirectViewModel>());

            var count = query.ToRowCountFutureValue();

            var redirects = query.AddSortingAndPaging(options).Future <SiteSettingRedirectViewModel>();

            model = new SearchableGridViewModel <SiteSettingRedirectViewModel>(redirects.ToList(), options, count.Value);

            return(model);
        }
        /// <summary>
        /// Executes the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>A list of blog posts</returns>
        public SearchableGridViewModel <SiteSettingBlogPostViewModel> Execute(SearchableGridOptions request)
        {
            SearchableGridViewModel <SiteSettingBlogPostViewModel> model;

            request.SetDefaultSortingOptions("Title");

            BlogPost alias = null;
            SiteSettingBlogPostViewModel modelAlias = null;

            var query = UnitOfWork.Session
                        .QueryOver(() => alias)
                        .Where(() => !alias.IsDeleted && alias.Status != PageStatus.Preview);

            if (!string.IsNullOrWhiteSpace(request.SearchQuery))
            {
                var searchQuery = string.Format("%{0}%", request.SearchQuery);
                query = query.Where(Restrictions.InsensitiveLike(Projections.Property(() => alias.Title), searchQuery));
            }

            query = query
                    .SelectList(select => select
                                .Select(() => alias.Id).WithAlias(() => modelAlias.Id)
                                .Select(() => alias.Title).WithAlias(() => modelAlias.Title)
                                .Select(() => alias.CreatedOn).WithAlias(() => modelAlias.CreatedOn)
                                .Select(() => alias.ModifiedOn).WithAlias(() => modelAlias.ModifiedOn)
                                .Select(() => alias.ModifiedByUser).WithAlias(() => modelAlias.ModifiedByUser)
                                .Select(() => alias.Status).WithAlias(() => modelAlias.PageStatus)
                                .Select(() => alias.Version).WithAlias(() => modelAlias.Version)
                                .Select(() => alias.PageUrl).WithAlias(() => modelAlias.PageUrl))
                    .TransformUsing(Transformers.AliasToBean <SiteSettingBlogPostViewModel>());

            var count = query.ToRowCountFutureValue();

            var blogPosts = query.AddSortingAndPaging(request).Future <SiteSettingBlogPostViewModel>();

            model = new SearchableGridViewModel <SiteSettingBlogPostViewModel>(blogPosts.ToList(), request, count.Value);

            return(model);
        }
        /// <summary>
        /// Executes the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>List with blog post view models</returns>
        public SearchableGridViewModel <AuthorViewModel> Execute(SearchableGridOptions request)
        {
            var query   = Repository.AsQueryable <Author>();
            var authors = query.Select(
                author =>
                new AuthorViewModel
            {
                Id          = author.Id,
                Version     = author.Version,
                Name        = author.Name,
                Description = author.Description,
                Image       = author.Image != null && !author.Image.IsDeleted
                                    ?
                              new ImageSelectorViewModel
                {
                    ImageId      = author.Image.Id,
                    ImageVersion = author.Image.Version,
                    ImageUrl     = fileUrlResolver.EnsureFullPathUrl(author.Image.PublicUrl),
                    ThumbnailUrl = fileUrlResolver.EnsureFullPathUrl(author.Image.PublicThumbnailUrl),
                    ImageTooltip = author.Image.Caption,
                    FolderId     = author.Image.Folder != null ? author.Image.Folder.Id : (System.Guid?)null
                }
                : null
            });

            if (!string.IsNullOrWhiteSpace(request.SearchQuery))
            {
                authors = authors.Where(a => a.Name.Contains(request.SearchQuery));
            }

            request.SetDefaultSortingOptions("Name");
            var count = authors.ToRowCountFutureValue();

            authors = authors.AddSortingAndPaging(request);

            return(new SearchableGridViewModel <AuthorViewModel>(authors.ToList(), request, count.Value));
        }