Exemplo n.º 1
0
        public ActionResult Index(PagerParameters pagerParameters, SearchVM search, bool ShowVideo = false)
        {
            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);
            Int32 currentiduser = _orchardServices.WorkContext.CurrentUser.Id;
            IEnumerable <ContentItem> ListContent;
            bool hasAdminPermission = _orchardServices.Authorizer.Authorize(Permissions.AdminTwitterAccount);

            if (hasAdminPermission)
            {
                ListContent = contentQuery.List();
            }
            else
            {
                ListContent = contentQuery.List().Where(x => x.As <TwitterAccountPart>().IdUser == currentiduser);
            }

            if (!string.IsNullOrEmpty(search.Expression))
            {
                ListContent = from content in ListContent
                              where
                              ((content.As <TitlePart>().Title ?? "").Contains(expression, StringComparison.InvariantCultureIgnoreCase))
                              select content;
            }
            IEnumerable <ContentIndexVM> listVM = ListContent.Select(p => new ContentIndexVM {
                Id          = p.Id,
                Title       = p.As <TwitterAccountPart>().AccountType + " - " + p.As <TwitterAccountPart>().DisplayAs,// string.IsNullOrEmpty(p.As<TwitterAccountPart>().PageName) ? "User Account" : " Page -> " + p.As<TwitterAccountPart>().PageName,
                ModifiedUtc = p.As <CommonPart>().ModifiedUtc,
                UserName    = p.As <CommonPart>().Owner.UserName,
                Option      = new {
                    Valid  = p.As <TwitterAccountPart>().Valid,
                    Shared = p.As <TwitterAccountPart>().Shared,
                    Image  = Url.Content("~/Media/" + _shellSettings.Name + "/twitter_" + p.As <TwitterAccountPart>().DisplayAs + ".jpg")
                }
            });
            Pager   pager      = new Pager(_orchardServices.WorkContext.CurrentSite, pagerParameters);
            dynamic pagerShape = _orchardServices.New.Pager(pager).TotalItemCount(listVM.Count());
            var     list       = listVM.Skip(pager.GetStartIndex())
                                 .Take(pager.PageSize);
            var model = new SearchIndexVM(list, search, pagerShape, Options);

            return(View((object)model));
        }