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); })); }
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)); }
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)); }
protected override DriverResult Display(ContainerPart part, string displayType, dynamic shapeHelper) { if (!part.ItemsShown) { return(null); } return(ContentShape("Parts_Container_Contained", () => { var container = part.ContentItem; IContentQuery <ContentItem> query = _contentManager .Query(VersionOptions.Published) .Join <CommonPartRecord>().Where(cr => cr.Container.Id == container.Id); var descendingOrder = part.OrderByDirection == (int)OrderByDirection.Descending; query = query.OrderBy(part.OrderByProperty, descendingOrder); var metadata = container.ContentManager.GetItemMetadata(container); if (metadata != null) { _feedManager.Register(metadata.DisplayText, "rss", new RouteValueDictionary { { "containerid", container.Id } }); } var pager = new Pager(_siteService.GetSiteSettings(), part.PagerParameters); pager.PageSize = part.PagerParameters.PageSize != null && part.Paginated ? pager.PageSize : part.PageSize; var pagerShape = shapeHelper.Pager(pager).TotalItemCount(query.Count()); var startIndex = part.Paginated ? pager.GetStartIndex() : 0; var pageOfItems = query.Slice(startIndex, pager.PageSize).ToList(); var listShape = shapeHelper.List(); listShape.AddRange(pageOfItems.Select(item => _contentManager.BuildDisplay(item, "Summary"))); listShape.Classes.Add("content-items"); listShape.Classes.Add("list-items"); return shapeHelper.Parts_Container_Contained( List: listShape, Pager: part.Paginated ? pagerShape : null ); })); }
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)); }
public static IEnumerable <T> Slice <T>(this IContentQuery <T> query, int count) where T : IContent { return(query.Slice(0, count)); }
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)); }