public static PagedList <T> ToPageList <T>(this IContentQuery <T> contentQuery, int pageIndex, int pageSize, bool enablePaging = true)
     where T : ContentBase
 {
     if (enablePaging == true)
     {
         if (pageIndex < 1)
         {
             pageIndex = 1;
         }
         var itemIndex      = (pageIndex - 1) * pageSize;
         var totalItemCount = contentQuery.Count();
         var pageOfItems    = contentQuery.Skip(itemIndex).Take(pageSize);
         return(new PagedList <T>(pageOfItems, pageIndex, pageSize, totalItemCount));
     }
     else
     {
         var totalItemCount = contentQuery.Count();
         var pageOfItems    = contentQuery.Take(totalItemCount);
         return(new PagedList <T>(pageOfItems, 1, totalItemCount, totalItemCount));
     }
 }
Example #2
0
        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
                    );
            }));
        }
Example #3
0
        public ActionResult Index(PagerParameters pagerParameters)
        {
            Pager pager = new Pager(_siteService.GetSiteSettings(), pagerParameters);
            IContentQuery <ContactPart, ContactPartRecord> contacts = _contactService.GetContacts();
            var pagerShape      = Shape.Pager(pager).TotalItemCount(contacts.Count());
            var contactRequests = contacts
                                  .OrderByDescending <ContactPartRecord, DateTime?>(cpr => cpr.ContactDateUtc)
                                  .Slice(pager.GetStartIndex(), pager.PageSize)
                                  .ToList(); // TODO: see if we need to return something other than the raw contact items here

            var model = new ContactRequestListViewModel
            {
                ContactRequests = contactRequests,
                Pager           = pagerShape
            };

            return(View(model));
        }
        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));
        }
Example #5
0
        private static object GetData(DataRuleSetting dataRuleSetting, IContentQuery <TextContent> contentQuery)
        {
            if (dataRuleSetting.CachingDuration > 0)
            {
                var policy = new CacheItemPolicy()
                {
                    SlidingExpiration = TimeSpan.FromSeconds(dataRuleSetting.CachingDuration)
                };
                switch (dataRuleSetting.TakeOperation)
                {
                case TakeOperation.First:
                    var lazyFirst = contentQuery.LazyFirstOrDefault();
                    return(GetCacheData(dataRuleSetting.TakeOperation, contentQuery, policy, () => lazyFirst.Value));

                case TakeOperation.Count:
                    var lazyCount = contentQuery.LazyCount();
                    return(GetCacheData(dataRuleSetting.TakeOperation, contentQuery, policy, () => lazyCount.Value));

                case TakeOperation.List:
                default:
                    return(GetCacheData(dataRuleSetting.TakeOperation, contentQuery, policy, () => contentQuery.ToArray()));
                }
            }
            else
            {
                switch (dataRuleSetting.TakeOperation)
                {
                case TakeOperation.First:
                    return(contentQuery.FirstOrDefault());

                case TakeOperation.Count:
                    return(contentQuery.Count());

                case TakeOperation.List:
                default:
                    return(contentQuery.ToArray());
                }
            }
        }
        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));
        }
Example #7
0
        public override NCMIS.ObjectModel.PathedCmisObjectList GetChildren(string repositoryId, string folderId, int?maxItems, int skipCount, string orderBy, string filter, IncludeRelationships includeRelationships, string renditionFilter, bool includeAllowableActions, bool includePathSegment)
        {
            Kooboo.CMS.Content.Models.Repository repository = new Models.Repository(repositoryId);
            IObjectService folderService = ObjectService.GetService(typeof(Folder));
            string         objectId      = folderId;

            folderService.TryPraseObjectId(objectId, out folderId);

            FolderType folderType = CmisFolderHelper.IdentifyFolderType(repository, folderId);

            PathedCmisObjectList           pathedList = new PathedCmisObjectList();
            IEnumerable <PathedCmisObject> children   = folderService.GetChildren(repositoryId, objectId, filter, includeRelationships)
                                                        .Select(it => new PathedCmisObject()
            {
                Object = it
            });

            var count = children.Count();

            pathedList.NumItems     = count.ToString();
            pathedList.HasMoreItems = false;

            //IEnumerable<ContentBase> contents = new ContentBase[0];
            if (folderType == FolderType.Content_Folder || folderType == FolderType.Media_Folder)
            {
                var folder = CmisFolderHelper.Parse(repository, folderId).AsActual();
                IContentQuery <ContentBase> contentQuery = null;
                if (folder is TextFolder)
                {
                    var textFolder = (TextFolder)folder;
                    var schema     = new Schema(repository, textFolder.SchemaName).AsActual();
                    contentQuery = textFolder.CreateQuery();
                    if (!string.IsNullOrEmpty(filter))
                    {
                        foreach (var item in schema.Columns)
                        {
                            contentQuery = contentQuery.Or(new WhereContainsExpression(null, item.Name, filter));
                        }
                    }
                }
                else
                {
                    var mediaFolder = (TextFolder)folder;
                    contentQuery = mediaFolder.CreateQuery();
                    if (!string.IsNullOrEmpty(filter))
                    {
                        contentQuery = contentQuery.WhereContains("FileName", filter);
                    }
                }
                if (!string.IsNullOrEmpty(orderBy))
                {
                    contentQuery = contentQuery.OrderBy(orderBy);
                }

                count = contentQuery.Count();
                var take = maxItems.HasValue ? maxItems.Value : count;
                pathedList.NumItems     = count.ToString();
                pathedList.HasMoreItems = count > count + take;

                children = children.Concat(contentQuery.Select(it => new PathedCmisObject()
                {
                    Object = ObjectConvertor.ToCmis((TextContent)(it), includeRelationships != IncludeRelationships.None)
                }).Take(take));
            }

            pathedList.Objects = children.ToArray();

            return(pathedList);
        }
Example #8
0
 private static object GetData(DataRuleSetting dataRuleSetting, IContentQuery<TextContent> contentQuery)
 {
     if (dataRuleSetting.CachingDuration > 0)
     {
         var policy = new CacheItemPolicy() { SlidingExpiration = TimeSpan.FromSeconds(dataRuleSetting.CachingDuration) };
         switch (dataRuleSetting.TakeOperation)
         {
             case TakeOperation.First:
                 var lazyFirst = contentQuery.LazyFirstOrDefault();
                 return GetCacheData(dataRuleSetting.TakeOperation, contentQuery, policy, () => lazyFirst.Value);
             case TakeOperation.Count:
                 var lazyCount = contentQuery.LazyCount();
                 return GetCacheData(dataRuleSetting.TakeOperation, contentQuery, policy, () => lazyCount.Value);
             case TakeOperation.List:
             default:
                 return GetCacheData(dataRuleSetting.TakeOperation, contentQuery, policy, () => contentQuery.ToArray());
         }
     }
     else
     {
         switch (dataRuleSetting.TakeOperation)
         {
             case TakeOperation.First:
                 return contentQuery.FirstOrDefault();
             case TakeOperation.Count:
                 return contentQuery.Count();
             case TakeOperation.List:
             default:
                 return contentQuery.ToArray();
         }
     }
 }
Example #9
0
 public static Lazy <int> LazyCount <T>(this IContentQuery <T> contentQuery)
     where T : ContentBase
 {
     contentQuery = contentQuery.Create(new CallExpression(contentQuery.Expression, CallType.Count));
     return(new Lazy <int>(() => (int)contentQuery.Count()));
 }
        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));
        }
        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));
        }