public IActionResult Index(SearchIndexVM searchVM) { if (ModelState.IsValid) { var result = !searchVM.IsOfflineSearch ? searchService.SearchOnline(searchVM.Words) : searchService.SearchLocally(searchVM.Words); //TODO: enginesIds logger.LogInformation(result.Message); if (result.Succeedeed) { SearchResult searchResult = result.Result as SearchResult; List <ResultVM> resultVMs = searchResult.Results.Select(r => new ResultVM { Link = r.Link, Description = r.Description, Title = r.Title } ).ToList(); AllResultsVM allResults = new AllResultsVM { Error = "", Results = resultVMs, Words = searchVM.Words, EngineName = searchResult.EngineName }; TempData.Put("allResults", allResults); return(RedirectToAction("Results")); } else { ModelState.AddModelError(string.Empty, $"{result.Message}\n{result.Result?.ToString()}"); } } return(View()); }
public ActionResult SearchIndex() { TempData.Keep("LoginName"); SearchIndexVM list = new SearchIndexVM(); List <Entry> entrylist = (List <Entry>)Session["searchList"]; list.EntriesList = entrylist; return(View(list)); }
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 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 ActionResult Search(SearchVM searchVM) { if (ModelState.IsValid) { TempData.Keep("LoginName"); EntryBL entryBL = new EntryBL(); SearchIndexVM sIndexVM = new SearchIndexVM(); sIndexVM.EntriesList = entryBL.List().Where(u => u.Developer == searchVM.Developer).ToList(); sIndexVM.EntriesList = sIndexVM.EntriesList.Where(u => u.Film == searchVM.Film).ToList(); Session["searchList"] = sIndexVM.EntriesList; return(RedirectToAction("SearchIndex", "Entry")); } return(View(searchVM)); }
public async Task <IActionResult> Index() { var vm = new SearchIndexVM(); var restaurants = await restRepo.GetAllRestaurantsAsync(); vm.Restaurants = new List <SelectListItem>(); foreach (var r in restaurants) { vm.Restaurants.Add(new SelectListItem { Text = r.Name, Value = r.Id.ToString() }); } return(View(vm)); }
public ActionResult Index(PagerParameters pagerParameters, SearchVM search) { dynamic Options = new System.Dynamic.ExpandoObject(); Options.ShowVideo = false; if (!_orchardServices.Authorizer.Authorize(TestPermission)) { return(new HttpUnauthorizedResult()); } var expression = search.Expression; string[] listcontentstype = new string[] { contentType, "Query" }; //IEnumerable<ContentItem> ListContent1 = _orchardServices.ContentManager.Query(VersionOptions.Latest).ForType(listcontentstype).List().Where(x => x.ContentType == contentType || ((dynamic)x).QueryUserFilterExtensionPart.UserQuery.Value == true); // IEnumerable<ContentItem> ListContent= _orchardServices.ContentManager.Query(VersionOptions.Latest).ForType(listcontentstype).OrderByDescending<CommonPartRecord>(cpr => cpr.ModifiedUtc).List().Where(x => x.ContentType == contentType || ((dynamic)x).QueryUserFilterExtensionPart.UserQuery.Value == true); IEnumerable <ContentItem> ListContent = _customQuery.ListContent(); 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 <TitlePart>().Title, ModifiedUtc = p.As <CommonPart>().ModifiedUtc, UserName = p.As <CommonPart>().Owner.UserName, ContentType = p.ContentType, OneShotQuery = (p.Parts.FirstOrDefault(x => x.PartDefinition.Name == "QueryUserFilterExtensionPart") != null) ? ((dynamic)p).QueryUserFilterExtensionPart.OneShotQuery.Value ?? false : false }); 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); //_orchardServices.New.List(); //list.AddRange(listVM.Skip(pager.GetStartIndex()) // .Take(pager.PageSize) // ); var model = new SearchIndexVM(list, search, pagerShape, Options); return(View((object)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)); }
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)); }