Example #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));
        }
        public static EagerlyLoadQueryResult <T> IncludeMediaLibraryPickerFields <T>(this IContentQuery <T> query) where T : class, IContent
        {
            var manager = query.ContentManager;
            var eagerlyLoadQueryResult = new EagerlyLoadQueryResult <T>(query.List(), manager);

            return(eagerlyLoadQueryResult.IncludeMediaLibraryPickerFields());
        }
        public static EagerlyLoadQueryResult <T> IncludeContainerContentItems <T>(this IContentQuery <T> query, int maximumLevel = 0) where T : class, IContent
        {
            var manager = query.ContentManager;
            var eagerlyLoadQueryResult = new EagerlyLoadQueryResult <T>(query.List(), manager);

            return(eagerlyLoadQueryResult.IncludeContainerContentItems(maximumLevel));
        }
Example #4
0
        private void OrchardRegister(TwitterAccountVM fvm)
        {
            IContentQuery <ContentItem> contentQuery = _orchardServices.ContentManager.Query().ForType(contentType);
            Int32 currentiduser = _orchardServices.WorkContext.CurrentUser.Id;

            Int32 elementi = contentQuery.List().Where(x => x.As <TwitterAccountPart>().IdUser == currentiduser && x.As <TwitterAccountPart>().DisplayAs == fvm.DisplayAs).Count();

            if (elementi > 0)
            {
                _notifier.Add(NotifyType.Warning, T("User Twitter Account can't be added, is duplicated"));
            }
            else
            {
                var newContent = _orchardServices.ContentManager.New(contentType);
                _orchardServices.ContentManager.Create(newContent);
                newContent.As <TwitterAccountPart>().AccountType     = "User";
                newContent.As <TwitterAccountPart>().IdUser          = currentiduser;
                newContent.As <TwitterAccountPart>().DisplayAs       = fvm.DisplayAs;
                newContent.As <TwitterAccountPart>().SocialName      = "Twitter";
                newContent.As <TwitterAccountPart>().UserToken       = fvm.UserToken;
                newContent.As <TwitterAccountPart>().Valid           = true;
                newContent.As <TwitterAccountPart>().Shared          = false;
                newContent.As <TwitterAccountPart>().UserTokenSecret = fvm.UserTokenSecret;
                _notifier.Add(NotifyType.Warning, T("User Twitter Account added"));
            }
        }
        public static EagerlyLoadQueryResult <T> IncludeTaxonomyFields <T>(this IContentQuery <T> query, bool loadTermsContainter) where T : class, IContent
        {
            var manager = query.ContentManager;

            query = query.Join <TermsPartRecord>().WithQueryHints(new QueryHints().ExpandRecords("TermsPartRecord.Terms"));

            var eagerlyLoadQueryResult = new EagerlyLoadQueryResult <T>(query.List(), manager);

            return(eagerlyLoadQueryResult.IncludeTaxonomyFields(loadTermsContainter));
        }
Example #6
0
        public ActionResult Index()
        {
            // Get the currently active list of poll content items (ie. where IsShown == true and IsOpen == true)
            // Return an IEnumerable of PollParts to view, and iterate over it there as itemlinks
            IContentQuery <PollPart, PollPartRecord> query = _pollService.GetPolls(true, true);
            IEnumerable <PollPart> activePolls             = query.List <PollPart>();

            var pollSelectList = _songService.MusicPolls();

            var model = new PollIndexViewModel()
            {
                Polls            = activePolls,
                ShowEnterSongBtn = (pollSelectList.Count() >= 1)
            };

            return(View(model));
        }
        public ActionResult Remove(Int32 id)
        {
            if (!_orchardServices.Authorizer.Authorize(TestPermission))
            {
                return(new HttpUnauthorizedResult());
            }
            ContentItem content = _orchardServices.ContentManager.Get(id);
            IContentQuery <ContentItem> contentQuery = _orchardServices.ContentManager.Query().ForType("CommunicationAdvertising");

            IEnumerable <ContentItem> ListContent = contentQuery.List().Where(x => (((dynamic)x).CommunicationAdvertisingPart.CampaignId.Equals(id)));

            if (ListContent.Count() == 0)
            {
                _orchardServices.ContentManager.Remove(content);
            }
            else
            {
                _notifier.Add(NotifyType.Warning, T("Can't remove campaign with advertise"));
            }

            return(RedirectToAction("Index", "CampaignAdmin"));
        }
Example #8
0
        private void OrchardRegister(FacebookAccountVM fvm)
        {
            string displayas   = "";
            string AccountType = "";

            if (string.IsNullOrEmpty(fvm.PageName))
            {
                string json = new WebClient().DownloadString("https://graph.facebook.com/me?access_token=" + fvm.UserToken);
                displayas   = (JObject.Parse(json))["name"].ToString();
                AccountType = "User";
            }
            else
            {
                displayas   = fvm.PageName;
                AccountType = "Page";
            }

            IContentQuery <ContentItem> contentQuery = _orchardServices.ContentManager.Query().ForType(contentType);
            Int32 currentiduser = _orchardServices.WorkContext.CurrentUser.Id;

            fvm.IdPage = fvm.IdPage ?? "";
            Int32 elementi = contentQuery.List().Where(x => x.As <FacebookAccountPart>().IdUser == currentiduser && (x.As <FacebookAccountPart>().DisplayAs == displayas)).Count();

            if (elementi > 0)
            {
                if (string.IsNullOrEmpty(fvm.IdPage))
                {
                    _notifier.Add(NotifyType.Warning, T("User Facebook Account can't be added, is duplicated"));
                }
                else
                {
                    _notifier.Add(NotifyType.Warning, T("Facebook Page {0} can't be added, is duplicated", fvm.PageName));
                }
            }
            else
            {
                var newContent = _orchardServices.ContentManager.New(contentType);
                _orchardServices.ContentManager.Create(newContent);
                newContent.As <FacebookAccountPart>().IdUser         = currentiduser;
                newContent.As <FacebookAccountPart>().AccountType    = AccountType;
                newContent.As <FacebookAccountPart>().DisplayAs      = displayas;
                newContent.As <FacebookAccountPart>().SocialName     = "Facebook";
                newContent.As <FacebookAccountPart>().UserToken      = fvm.UserToken;
                newContent.As <FacebookAccountPart>().Valid          = false;
                newContent.As <FacebookAccountPart>().PageName       = fvm.PageName;
                newContent.As <FacebookAccountPart>().PageToken      = fvm.PageToken;
                newContent.As <FacebookAccountPart>().IdPage         = fvm.IdPage ?? "";
                newContent.As <FacebookAccountPart>().Shared         = false;
                newContent.As <FacebookAccountPart>().UserIdFacebook = fvm.UserIdFacebook ?? "";
                newContent.As <FacebookAccountPart>().UserName       = fvm.UserName ?? "";

                if (string.IsNullOrEmpty(fvm.IdPage))
                {
                    _notifier.Add(NotifyType.Warning, T("User Facebook Account added"));
                }
                else
                {
                    _notifier.Add(NotifyType.Warning, T("Facebook Page {0} added", fvm.PageName));
                }
            }
        }
        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);
        }