public ActionResult Index(PagerParameters pagerParameters, SearchVM search, int id = 0)
        {
            if (!_orchardServices.Authorizer.Authorize(TestPermission))
            {
                return(new HttpUnauthorizedResult());
            }
            dynamic Options = new System.Dynamic.ExpandoObject();

            if (id >= 0)
            {
                Options.Campaign = _contentManager.Get(id);
            }
            else
            {
                // Options.Campaign = ""; // devo inserire la proprietà Campaign altrimenti index va in exception
                Options.Campaign    = new System.Dynamic.ExpandoObject();
                Options.Campaign.Id = id;
            }
            var expression = search.Expression;
            IContentQuery <ContentItem> contentQuery = _contentManager.Query(VersionOptions.Latest).ForType(contentType).OrderByDescending <CommonPartRecord>(cpr => cpr.ModifiedUtc);

            /*Nel caso di flash advertising la campagna è -10, quindi il filtro è sempre valido.*/
            if (id > 0)
            {
                contentQuery = contentQuery.Where <CommunicationAdvertisingPartRecord>(w =>
                                                                                       w.CampaignId.Equals(id)
                                                                                       );
            }
            else
            {
                contentQuery = contentQuery.Join <CommunicationAdvertisingPartRecord>().Where(w =>
                                                                                              w.CampaignId.Equals(0));
            }
            if (!string.IsNullOrEmpty(search.Expression))
            {
                contentQuery = contentQuery.Where <TitlePartRecord>(w => w.Title.Contains(expression));
            }
            Pager pager              = new Pager(_orchardServices.WorkContext.CurrentSite, pagerParameters);
            var   pagerShape         = _orchardServices.New.Pager(pager).TotalItemCount(contentQuery.Count());
            var   pageOfContentItems = contentQuery.Slice(pager.GetStartIndex(), pager.PageSize)
                                       .Select(p => new ContentIndexVM {
                Id          = p.Id,
                Title       = ((dynamic)p).TitlePart.Title,
                ModifiedUtc = ((dynamic)p).CommonPart.ModifiedUtc,
                UserName    = ((dynamic)p).CommonPart.Owner != null ? ((dynamic)p).CommonPart.Owner.UserName : "******",
                ContentItem = p
            }).ToList();
            var model = new SearchIndexVM(pageOfContentItems, search, pagerShape, Options);

            return(View((object)model));
        }
예제 #2
0
        private IContentQuery <CommonPart> LatestDateQuery(
            IContentQuery <CommonPart> query, EventForScheduling eventToCheck, int days)
        {
            var latestDate = _clock.UtcNow - TimeSpan.FromDays(days);

            switch (eventToCheck)
            {
            case EventForScheduling.Creation:
                return(query.Where <CommonPartRecord>(cpr => cpr.CreatedUtc < latestDate));

            case EventForScheduling.LatestUpdate:
            default:
                return(query.Where <CommonPartRecord>(cpr => cpr.ModifiedUtc < latestDate));
            }
        }
        public ActionResult Index(PagerParameters pagerParameters, string searchExpression)
        {
            if (!_orchardServices.Authorizer.Authorize(Permissions.AccessStatistics))
            {
                return(new HttpUnauthorizedResult());
            }

            IContentQuery <ContentItem> contentQuery = _orchardServices.ContentManager.Query()
                                                       .ForType("Questionnaire")
                                                       .OrderByDescending <CommonPartRecord>(cpr => cpr.ModifiedUtc);

            if (!string.IsNullOrEmpty(searchExpression))
            {
                contentQuery = contentQuery.Where <TitlePartRecord>(w => w.Title.Contains(searchExpression));
            }

            Pager pager              = new Pager(_orchardServices.WorkContext.CurrentSite, pagerParameters);
            var   pagerShape         = _orchardServices.New.Pager(pager).TotalItemCount(contentQuery.Count());
            var   pageOfContentItems = contentQuery.Slice(pager.GetStartIndex(), pager.PageSize);

            var model = new QuestionnaireSearchViewModel();

            model.Pager          = pagerShape;
            model.Questionnaires = pageOfContentItems;

            return(View((object)model));
        }
        protected override DriverResult Display(ContainerWidgetPart part, string displayType, dynamic shapeHelper)
        {
            return(ContentShape(
                       "Parts_ContainerWidget",
                       () => {
                var container = part.Record.ContainerId != 0 ? _contentManager.Get(part.Record.ContainerId) : default(ContentItem);

                if (container == null)
                {
                    return null;
                }

                IContentQuery <ContentItem> query = _contentManager
                                                    .Query(VersionOptions.Published)
                                                    .Join <CommonPartRecord>().Where(cr => cr.Container.Id == container.Id);

                if (part.Record.ApplyFilter)
                {
                    query = query.Where(part.Record.FilterByProperty, part.Record.FilterByOperator, part.Record.FilterByValue);
                }

                var pageOfItems = query.Slice(0, part.Record.PageSize).ToList();

                var list = shapeHelper.List();
                list.AddRange(pageOfItems.Select(item => _contentManager.BuildDisplay(item, "Summary")));

                return shapeHelper.Parts_ContainerWidget(ContentItems: list);
            }));
        }
예제 #5
0
        public double GetCountOfPage(int count)
        {
            IContentQuery <FaqPart, FaqPartRecord> query = _contentManager.Query <FaqPart, FaqPartRecord>(VersionOptions.Published);

            if (_typeIdFilter != -1)
            {
                query = query.Where <FaqPartRecord>(t => t.FaqTypeId == _typeIdFilter);
            }

            var publishedNews = query
                                .Where <CommonPartRecord>(p => p.PublishedUtc != null)
                                .OrderBy(p => p.PublishedUtc)
                                .List <FaqPart>();


            return(Math.Ceiling(publishedNews.Count() / (float)count / 1.0));
        }
        public IContentQuery<ContentItem> FilterCulture(IContentQuery<ContentItem> query, string cultureName) {
            var culture = _cultureManager.GetCultureByName(cultureName);
            
            if (culture != null) {
                return query.Where<LocalizationPartRecord>(x => x.CultureId == culture.Id);
            }

            return query;
        }
        public IContentQuery <ContentItem> FilterCulture(IContentQuery <ContentItem> query, string cultureName)
        {
            var culture = _cultureManager.GetCultureByName(cultureName);

            if (culture != null)
            {
                return(query.Where <LocalizationPartRecord>(x => x.CultureId == culture.Id));
            }

            return(query);
        }
예제 #8
0
        public IEnumerable <FaqPart> GetTypedFaqs(int faqTypeId)
        {
            IContentQuery <FaqPart, FaqPartRecord> query = _contentManager.Query <FaqPart, FaqPartRecord>(VersionOptions.Published);

            var publishedNews = query.Where <CommonPartRecord>(p => p.PublishedUtc != null)
                                .OrderByDescending(p => p.PublishedUtc)
                                .Where <FaqPartRecord>(fp => fp.FaqTypeId == faqTypeId)
                                .List <FaqPart>();

            return(publishedNews);
        }
예제 #9
0
        //public List<FaqPart> GetFaqs()
        //{
        //    return _FaqRepository.Table.ToList();
        //}

        public IEnumerable <FaqPart> GetLastFaqs(int?count = null, int?page = null)
        {
            IContentQuery <FaqPart, FaqPartRecord> query = _contentManager.Query <FaqPart, FaqPartRecord>(VersionOptions.Published);

            if (_typeIdFilter != -1)
            {
                query = query.Where <FaqPartRecord>(t => t.FaqTypeId == _typeIdFilter);
            }


            var publishedNews = query
                                .Where <CommonPartRecord>(p => p.PublishedUtc != null)
                                .OrderByDescending(p => p.PublishedUtc)
                                .List <FaqPart>();



            if (page != null)
            {
                if (count != null)
                {
                    var temp = publishedNews.Skip((page.Value - 1) * count.Value)
                               .Take(count.Value);
                    return(temp.ToList());
                }
                else
                {
                    var temp = publishedNews;
                    return(temp.ToList());
                }
            }

            if (count != null)
            {
                return(publishedNews.Take(count.Value));
            }
            return(publishedNews);
        }
        /// <summary>
        /// create express like: ((a=1) or (a=2) or (b=3))
        /// </summary>
        public static IContentQuery <TextContent> WhereOrs(this IContentQuery <TextContent> textContents, Dictionary <string, object> args)
        {
            var        textContent = textContents.FirstOrDefault();
            Repository repository  = textContent == null ? Repository.Current : new Repository(textContent.Repository);
            var        folder      = new TextFolder(repository, textContent.FolderName);

            folder = folder.AsActual();
            var query = folder.CreateQuery();

            foreach (var arg in args)
            {
                query = query.Or(new WhereContainsExpression(null, arg.Key, arg.Value));
            }
            return(textContents.Where((IWhereExpression)query.Expression));
        }
        public ActionResult Index(PagerParameters pagerParameters, SearchVM search, bool ShowVideo = false)
        {
            if (!_orchardServices.Authorizer.Authorize(TestPermission))
            {
                return(new HttpUnauthorizedResult());
            }
            dynamic Options = new System.Dynamic.ExpandoObject();

            Options.ShowVideo = false;
            if (!_orchardServices.Authorizer.Authorize(TestPermission))
            {
                return(new HttpUnauthorizedResult());
            }
            var expression = search.Expression;
            IContentQuery <ContentItem> contentQuery = _orchardServices.ContentManager.Query().ForType(contentType).OrderByDescending <CommonPartRecord>(cpr => cpr.ModifiedUtc);

            //IEnumerable<ContentItem> ListContent = contentQuery.List();
            if (contentQuery.Count() == 0 || ShowVideo)
            {
                if (_orchardServices.ContentManager.Query <TitlePart, TitlePartRecord>("Video").Where(x => x.Title == "HowTo" + contentType).List().Count() > 0)
                {
                    Options.ShowVideo    = true;
                    Options.VideoContent = _orchardServices.ContentManager.Query <TitlePart, TitlePartRecord>("Video").Where(x => x.Title == "HowTo" + contentType).List().Where(y => y.ContentItem.IsPublished()).FirstOrDefault().ContentItem;
                }
            }
            if (!string.IsNullOrEmpty(search.Expression))
            {
                contentQuery = contentQuery.Where <TitlePartRecord>(w => w.Title.Contains(expression));
            }
            Pager pager              = new Pager(_orchardServices.WorkContext.CurrentSite, pagerParameters);
            var   pagerShape         = _orchardServices.New.Pager(pager).TotalItemCount(contentQuery.Count());
            var   pageOfContentItems = contentQuery.Slice(pager.GetStartIndex(), pager.PageSize)
                                       .Select(p => new ContentIndexVM {
                Id          = p.Id,
                Title       = ((dynamic)p).TitlePart.Title,
                ModifiedUtc = ((dynamic)p).CommonPart.ModifiedUtc,
                UserName    = ((dynamic)p).CommonPart.Owner != null ? ((dynamic)p).CommonPart.Owner.UserName : "******",
                ContentItem = p
            }).ToList();

            var model = new SearchIndexVM(pageOfContentItems, search, pagerShape, Options);

            return(View((object)model));
        }
예제 #12
0
        public virtual ActionResult Index(string folderName, string parentUUID, string parentFolder, string search
                                          , IEnumerable <WhereClause> whereClause, int?page, int?pageSize, string sortField = null, string sortDir = null)
        {
            //compatible with the Folder parameter changed to FolderName.
            folderName = folderName ?? this.ControllerContext.RequestContext.GetRequestValue("Folder");

            TextFolder textFolder = new TextFolder(Repository, folderName).AsActual();
            var        schema     = textFolder.GetSchema().AsActual();

            SchemaPath schemaPath = new SchemaPath(schema);

            ViewData["Folder"]      = textFolder;
            ViewData["Schema"]      = schema;
            ViewData["Template"]    = textFolder.GetFormTemplate(FormType.Grid);
            ViewData["WhereClause"] = whereClause;

            SetPermissionData(textFolder);

            IEnumerable <TextFolder> childFolders = new TextFolder[0];

            //Skip the child folders on the embedded folder grid.
            if (string.IsNullOrEmpty(parentFolder))
            {
                if (!page.HasValue || page.Value <= 1)
                {
                    childFolders = TextFolderManager.ChildFolders(textFolder, search).Select(it => it.AsActual());
                }
            }

            IContentQuery <TextContent> query = textFolder.CreateQuery();

            query = SortByField(sortField, sortDir, query);
            bool showTreeStyle = schema.IsTreeStyle;

            //如果有带搜索条件,则不输出树形结构
            if (!string.IsNullOrEmpty(search))
            {
                IWhereExpression exp = new FalseExpression();
                foreach (var item in schema.Columns.Where(it => it.ShowInGrid))
                {
                    exp = new OrElseExpression(exp, (new WhereContainsExpression(null, item.Name, search)));
                }
                if (exp != null)
                {
                    query = query.Where(exp);
                }
                showTreeStyle = false;
            }
            if (whereClause != null && whereClause.Count() > 0)
            {
                var expression = WhereClauseToContentQueryHelper.Parse(whereClause, schema, new MVCValueProviderWrapper(ValueProvider));
                query         = query.Where(expression);
                showTreeStyle = false;
            }
            if (!string.IsNullOrWhiteSpace(parentUUID))
            {
                query = query.WhereEquals("ParentUUID", parentUUID);
            }
            else
            {
                //有两种情况需要考虑要不要查询所有的数据(ParentUUID=null)
                //1.树形结构数据,第一次查询需要过滤ParentUUID==null
                //2.自嵌套的目前结构,也需要过滤ParentUUID==null
                var selfEmbedded = textFolder.EmbeddedFolders != null && textFolder.EmbeddedFolders.Contains(textFolder.FullName, StringComparer.OrdinalIgnoreCase);
                if (showTreeStyle || selfEmbedded)
                {
                    query = query.Where(new OrElseExpression(new WhereEqualsExpression(null, "ParentUUID", null), new WhereEqualsExpression(null, "ParentUUID", "")));
                }
            }

            if (childFolders != null)
            {
                childFolders = childFolders
                               .Select(it => it.AsActual())
                               .Where(it => it.Visible)
                               .Where(it => Kooboo.CMS.Content.Services.ServiceFactory.WorkflowManager.AvailableViewContent(it, User.Identity.Name));
            }
            page     = page ?? 1;
            pageSize = pageSize ?? textFolder.PageSize;

            //var pagedList = query.ToPageList(page.Value, pageSize.Value);

            //IEnumerable<TextContent> contents = pagedList.ToArray();

            //if (Repository.EnableWorkflow == true)
            //{
            //    contents =WorkflowManager.GetPendWorkflowItemForContents(Repository, contents.ToArray(), User.Identity.Name);
            //}

            //var workflowContentPagedList = new PagedList<TextContent>(contents, page.Value, pageSize.Value, pagedList.TotalItemCount);
            //ViewData["ContentPagedList"] = workflowContentPagedList;
            return(View(new TextContentGrid()
            {
                ChildFolders = childFolders.ToArray(),
                ContentQuery = query,
                PageIndex = page.Value,
                PageSize = pageSize.Value,
                ShowTreeStyle = showTreeStyle
            }));
        }
        protected override DriverResult Display(RelatedContentWidgetPart part, string displayType, dynamic shapeHelper)
        {
            List <string> tags = part.TagList
                                 .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                                 .Select(s => s.Trim())
                                 .Where(s => !String.IsNullOrEmpty(s))
                                 .Distinct()
                                 .ToList();

            // If we have no tags.....
            if (tags.Count < 1)
            {
                return(ContentShape("Parts_RelatedContentWidget",
                                    () => shapeHelper.Parts_RelatedContentWidget(
                                        ContentItems: shapeHelper.List()
                                        )));
            }

            // See if we can find the current page/content id to filter it out
            // from the related content if necessary.
            int currentItemId = -1;

            if (part.ExcludeCurrentItemIfMatching)
            {
                currentItemId = TryGetCurrentContentId(-1);
            }

            // Setup a query on the tags part
            IContentQuery <TagsPart, TagsPartRecord> query = _cms.Query <TagsPart, TagsPartRecord>();

            if (part.MustHaveAllTags)
            {
                // Add where conditions for every tag specified
                foreach (string tag in tags)
                {
                    string tag1 = tag;                     // Prevent access to modified closure
                    query.Where(tpr => tpr.Tags.Any(t => t.TagRecord.TagName == tag1));
                }
            }
            else
            {
                // Add where condition for any tag specified
                query.Where(tpr => tpr.Tags.Any(t => tags.Contains(t.TagRecord.TagName)));
            }

            // Finish the query (exclude current, do ordering and slice max items) and execute
            IEnumerable <TagsPart> parts =
                query.Join <CommonPartRecord>()
                .Where(cpr => cpr.Id != currentItemId)
                .OrderByDescending(cpr => cpr.PublishedUtc)
                .Slice(part.MaxItems);

            // Create a list and push our display content items in
            var list = shapeHelper.List();

            list.AddRange(parts.Select(p => _cms.BuildDisplay(p, "Summary")));

            return(ContentShape("Parts_RelatedContentWidget",
                                () => shapeHelper.Parts_RelatedContentWidget(
                                    ShowListOnly: part.ShowListOnly,
                                    ContentItems: list
                                    )));
        }
        public IEnumerable <ContentItem> GetContactList(SearchVM search)
        {
            IEnumerable <ContentItem> contentItems = null;
            List <int> arr = null;

            IContentQuery <ContentItem> contentQuery = _contentManager.Query(VersionOptions.Latest).ForType("CommunicationContact");

            if (!(string.IsNullOrEmpty(search.Expression) && !search.CommercialUseAuthorization.HasValue && !search.ThirdPartyAuthorization.HasValue))
            {
                switch (search.Field)
                {
                case SearchFieldEnum.Name:
                    contentItems = contentQuery.Where <TitlePartRecord>(w => w.Title.Contains(search.Expression)).List();
                    break;

                case SearchFieldEnum.Mail:
                    string myQueryMail = @"select cir.Id
                                    from Orchard.ContentManagement.Records.ContentItemVersionRecord as civr
                                    join civr.ContentItemRecord as cir
                                    join cir.EmailContactPartRecord as EmailPart
                                    join EmailPart.EmailRecord as EmailRecord
                                    where 1 = 1 ";
                    if (!string.IsNullOrEmpty(search.Expression))
                    {
                        myQueryMail += "and EmailRecord.Email like '%' + :mail + '%' ";
                    }
                    if (search.CommercialUseAuthorization.HasValue)
                    {
                        myQueryMail += "and EmailRecord.AccettatoUsoCommerciale = :commuse ";
                    }
                    if (search.ThirdPartyAuthorization.HasValue)
                    {
                        myQueryMail += "and EmailRecord.AutorizzatoTerzeParti = :tpuse ";
                    }
                    myQueryMail += "order by cir.Id";

                    var mailQueryToExecute = _transactionManager.GetSession().CreateQuery(myQueryMail);
                    if (!string.IsNullOrEmpty(search.Expression))
                    {
                        mailQueryToExecute.SetParameter("mail", search.Expression);
                    }
                    if (search.CommercialUseAuthorization.HasValue)
                    {
                        mailQueryToExecute.SetParameter("commuse", search.CommercialUseAuthorization.Value, NHibernateUtil.Boolean);
                    }
                    if (search.ThirdPartyAuthorization.HasValue)
                    {
                        mailQueryToExecute.SetParameter("tpuse", search.ThirdPartyAuthorization.Value, NHibernateUtil.Boolean);
                    }

                    var elencoIdMail = mailQueryToExecute.List <int>();

                    arr          = new List <int>(elencoIdMail);
                    contentItems = contentQuery.Where <CommunicationContactPartRecord>(x => arr.Contains(x.Id)).List();
                    break;

                case SearchFieldEnum.Phone:
                    string myQuerySms = @"select cir.Id
                                    from Orchard.ContentManagement.Records.ContentItemVersionRecord as civr
                                    join civr.ContentItemRecord as cir
                                    join cir.SmsContactPartRecord as SmsPart
                                    join SmsPart.SmsRecord as SmsRecord
                                    where 1 = 1 ";
                    if (!string.IsNullOrEmpty(search.Expression))
                    {
                        myQuerySms += "and SmsRecord.Sms like '%' + :sms + '%' ";
                    }
                    if (search.CommercialUseAuthorization.HasValue)
                    {
                        myQuerySms += "and SmsRecord.AccettatoUsoCommerciale = :commuse ";
                    }
                    if (search.ThirdPartyAuthorization.HasValue)
                    {
                        myQuerySms += "and SmsRecord.AutorizzatoTerzeParti = :tpuse ";
                    }
                    myQuerySms += "order by cir.Id";

                    var smsQueryToExecute = _transactionManager.GetSession().CreateQuery(myQuerySms);
                    if (!string.IsNullOrEmpty(search.Expression))
                    {
                        smsQueryToExecute.SetParameter("sms", search.Expression);
                    }
                    if (search.CommercialUseAuthorization.HasValue)
                    {
                        smsQueryToExecute.SetParameter("commuse", search.CommercialUseAuthorization.Value, NHibernateUtil.Boolean);
                    }
                    if (search.ThirdPartyAuthorization.HasValue)
                    {
                        smsQueryToExecute.SetParameter("tpuse", search.ThirdPartyAuthorization.Value, NHibernateUtil.Boolean);
                    }

                    var elencoIdSms = smsQueryToExecute.List <int>();

                    arr          = new List <int>(elencoIdSms);
                    contentItems = contentQuery.Where <CommunicationContactPartRecord>(x => arr.Contains(x.Id)).List();
                    break;
                }
            }
            else
            {
                contentItems = contentQuery.List();
            };

            return(contentItems);
        }
        public ActionResult IndexSearch(int?page, int?pageSize, SearchVM search)
        {
            if (!_orchardServices.Authorizer.Authorize(Permissions.ShowContacts))
            {
                return(new HttpUnauthorizedResult());
            }
            if (Request.QueryString["submit.Export"] != null)
            {
                return(Export(search));
            }

            // variabili di appoggio
            List <int> arr = null;

            IEnumerable <ContentItem> contentItems = null;
            int     totItems   = 0;
            Pager   pager      = new Pager(_orchardServices.WorkContext.CurrentSite, page, pageSize);
            dynamic Options    = new System.Dynamic.ExpandoObject();
            var     expression = search.Expression;
            IContentQuery <ContentItem> contentQuery = _contentManager.Query(VersionOptions.Latest).ForType(contentType);//.OrderByDescending<CommonPartRecord>(cpr => cpr.ModifiedUtc); //Performance issues on heavy ContentItems numbers #6247

            if (!(string.IsNullOrEmpty(search.Expression) && !search.CommercialUseAuthorization.HasValue && !search.ThirdPartyAuthorization.HasValue))
            {
                switch (search.Field)
                {
                case SearchFieldEnum.Name:
                    contentQuery = contentQuery.Where <TitlePartRecord>(w => w.Title.Contains(expression));
                    totItems     = contentQuery.Count();
                    contentItems = contentQuery.Slice(pager.GetStartIndex(), pager.PageSize);
                    break;

                case SearchFieldEnum.Mail:
                    string myQueryMail = @"select cir.Id
                                    from Orchard.ContentManagement.Records.ContentItemVersionRecord as civr
                                    join civr.ContentItemRecord as cir
                                    join cir.EmailContactPartRecord as EmailPart
                                    join EmailPart.EmailRecord as EmailRecord
                                    where 1 = 1 ";
                    if (!string.IsNullOrEmpty(search.Expression))
                    {
                        myQueryMail += "and EmailRecord.Email like '%' + :mail + '%' ";
                    }
                    if (search.CommercialUseAuthorization.HasValue)
                    {
                        myQueryMail += "and EmailRecord.AccettatoUsoCommerciale = :commuse ";
                    }
                    if (search.ThirdPartyAuthorization.HasValue)
                    {
                        myQueryMail += "and EmailRecord.AutorizzatoTerzeParti = :tpuse ";
                    }
                    myQueryMail += "order by cir.Id";

                    var mailQueryToExecute = _transactionManager.GetSession().CreateQuery(myQueryMail);
                    if (!string.IsNullOrEmpty(search.Expression))
                    {
                        mailQueryToExecute.SetParameter("mail", expression);
                    }
                    if (search.CommercialUseAuthorization.HasValue)
                    {
                        mailQueryToExecute.SetParameter("commuse", search.CommercialUseAuthorization.Value, NHibernateUtil.Boolean);
                    }
                    if (search.ThirdPartyAuthorization.HasValue)
                    {
                        mailQueryToExecute.SetParameter("tpuse", search.ThirdPartyAuthorization.Value, NHibernateUtil.Boolean);
                    }

                    var elencoIdMail = mailQueryToExecute.List();

                    // alternativa
                    //                        string myQueryMail = @"select EmailContactPartRecord_Id
                    //                                            from Laser_Orchard_CommunicationGateway_CommunicationEmailRecord
                    //                                            where Email like '%' + :mail + '%'";
                    //                        var elencoIdMail = _session.For(null)
                    //                            .CreateSQLQuery(myQueryMail)
                    //                            .SetParameter("mail", expression)
                    //                            .List();

                    totItems = elencoIdMail.Count;

                    // tiene conto solo degli item presenti nella pagina da visualizzare
                    arr = new List <int>();
                    for (int idx = 0; (idx < pager.PageSize) && ((idx + pager.GetStartIndex()) < totItems); idx++)
                    {
                        arr.Add((int)(elencoIdMail[idx + pager.GetStartIndex()]));
                    }
                    elencoIdMail = null;
                    contentItems = contentQuery.Where <CommunicationContactPartRecord>(x => arr.Contains(x.Id)).List();
                    break;

                case SearchFieldEnum.Phone:
                    string myQuerySms = @"select cir.Id
                                    from Orchard.ContentManagement.Records.ContentItemVersionRecord as civr
                                    join civr.ContentItemRecord as cir
                                    join cir.SmsContactPartRecord as SmsPart
                                    join SmsPart.SmsRecord as SmsRecord
                                    where 1 = 1 ";
                    if (!string.IsNullOrEmpty(search.Expression))
                    {
                        myQuerySms += "and SmsRecord.Sms like '%' + :sms + '%' ";
                    }
                    if (search.CommercialUseAuthorization.HasValue)
                    {
                        myQuerySms += "and SmsRecord.AccettatoUsoCommerciale = :commuse ";
                    }
                    if (search.ThirdPartyAuthorization.HasValue)
                    {
                        myQuerySms += "and SmsRecord.AutorizzatoTerzeParti = :tpuse ";
                    }
                    myQuerySms += "order by cir.Id";

                    var smsQueryToExecute = _transactionManager.GetSession().CreateQuery(myQuerySms);
                    if (!string.IsNullOrEmpty(search.Expression))
                    {
                        smsQueryToExecute.SetParameter("sms", expression);
                    }
                    if (search.CommercialUseAuthorization.HasValue)
                    {
                        smsQueryToExecute.SetParameter("commuse", search.CommercialUseAuthorization.Value, NHibernateUtil.Boolean);
                    }
                    if (search.ThirdPartyAuthorization.HasValue)
                    {
                        smsQueryToExecute.SetParameter("tpuse", search.ThirdPartyAuthorization.Value, NHibernateUtil.Boolean);
                    }

                    var elencoIdSms = smsQueryToExecute.List();

                    // alternativa
                    //                        string myQuerySms = @"select SmsContactPartRecord_Id
                    //                                            from Laser_Orchard_CommunicationGateway_CommunicationSmsRecord
                    //                                            where sms like '%' + :sms + '%'";
                    //                        var elencoIdSms = _session.For(null)
                    //                            .CreateSQLQuery(myQuerySms)
                    //                            .SetParameter("sms", expression)
                    //                            .List();

                    totItems = elencoIdSms.Count;

                    // tiene conto solo degli item presenti nella pagina da visualizzare
                    arr = new List <int>();
                    for (int idx = 0; (idx < pager.PageSize) && ((idx + pager.GetStartIndex()) < totItems); idx++)
                    {
                        arr.Add((int)(elencoIdSms[idx + pager.GetStartIndex()]));
                    }
                    elencoIdSms  = null;
                    contentItems = contentQuery.Where <CommunicationContactPartRecord>(x => arr.Contains(x.Id)).List();
                    break;
                }
            }
            else
            {
                totItems     = contentQuery.Count();
                contentItems = contentQuery.Slice(pager.GetStartIndex(), pager.PageSize);
            }
            var pagerShape         = _orchardServices.New.Pager(pager).TotalItemCount(totItems);
            var pageOfContentItems = contentItems
                                     .Select(p => new ContentIndexVM {
                Id           = p.Id,
                Title        = ((dynamic)p).TitlePart.Title,
                ModifiedUtc  = ((dynamic)p).CommonPart.ModifiedUtc,
                UserName     = ((dynamic)p).CommonPart.Owner != null ? ((dynamic)p).CommonPart.Owner.UserName : "******",
                PreviewEmail = (((dynamic)p).EmailContactPart.EmailRecord.Count > 0) ? ((dynamic)p).EmailContactPart.EmailRecord[0].Email : "",
                PreviewSms   = (((dynamic)p).SmsContactPart.SmsRecord.Count > 0) ? ((dynamic)p).SmsContactPart.SmsRecord[0].Prefix + "/" + ((dynamic)p).SmsContactPart.SmsRecord[0].Sms : "",
                UserId       = ((dynamic)p).CommunicationContactPart.UserIdentifier
            }).ToList();

            if (pageOfContentItems == null)
            {
                pageOfContentItems = new List <ContentIndexVM>();
            }
            //_orchardServices.New.List();
            AddProviderInfo(pageOfContentItems);
            var model = new SearchIndexVM(pageOfContentItems, search, pagerShape, Options);

            return(View("Index", (object)model));
        }