private ActionResult RunDetailedSearch(PersonSearchViewModel item, string pageNumber, string sortBy) { var sortDirection = GetSortDirection(item, sortBy); ModelState.Clear(); var results = _Service.Search( searchValueFirstName: item.FirstName, searchValueLastName: item.LastName, searchValuePhoneNumber: item.PhoneNumber, searchValueEmailAddress: item.EmailAddress, searchValueStatus: item.Status, searchValueCreatedBy: item.CreatedBy, searchValueLastModifiedBy: item.LastModifiedBy, searchValueThingy: item.Thingy, sortBy: sortBy, sortByDirection: sortDirection); var pageableResults = new PageableResults <Person>(); pageableResults.Initialize(results); pageableResults.CurrentPage = pageNumber.SafeToInt32(0); item.Results = pageableResults; item.CurrentSortDirection = sortDirection; item.CurrentSortProperty = sortBy; return(View(item)); }
public IQueryable <PersonServiceModel> SearchPerson(PersonSearchViewModel personSearchViewModel) { string egn = personSearchViewModel.Egn ?? ""; string fullName = personSearchViewModel.FullName ?? ""; IQueryable <PersonServiceModel> personAll; if (!egn.Equals("") && !fullName.Equals("")) { personAll = this.context.Persons.Where(p => p.Egn == egn && p.FullName.Contains(fullName)).To <PersonServiceModel>(); } else if (!egn.Equals("") && fullName.Equals("")) { personAll = this.context.Persons.Where(p => p.Egn == egn).To <PersonServiceModel>(); } else if (egn.Equals("") && !fullName.Equals("")) { personAll = this.context.Persons.Where(p => p.FullName.Contains(fullName)).To <PersonServiceModel>(); } else { personAll = this.context.Persons.To <PersonServiceModel>(); } return(personAll); }
public async Task <IActionResult> Search(PersonSearchViewModel personSearchViewModel) { List <PersonServiceModel> personsFoundService = await this.personService.SearchPerson(personSearchViewModel).ToListAsync(); List <PersonViewModel> personsFound = personsFoundService .Select(d => d.To <PersonViewModel>()).ToList(); List <PersonViewModel> personsFoundPage = personsFound.Skip((personSearchViewModel.CurrentPage - 1) * personSearchViewModel.PageSize).Take(personSearchViewModel.PageSize).ToList(); personSearchViewModel.Count = personsFound.Count; personSearchViewModel.PersonsFound = personsFoundPage; return(this.View(personSearchViewModel)); }
public ActionResult Index(PersonSearchViewModel model) { if (model.SearchButton == null) { var emptyresults = new PersonSearchViewModel(); return(View(emptyresults)); } var data = new PersonSearchViewModel(); data.Results = Search(model.SearchCriteria); return(View(data)); }
public ActionResult Search(PersonSearchViewModel item, string pageNumber, string sortBy) { if (item == null) { return(View(new PersonSearchViewModel())); } else if (item.IsSimpleSearch == true) { return(RunSimpleSearch(item, pageNumber, sortBy)); } else { return(RunDetailedSearch(item, pageNumber, sortBy)); } }
public async Task SearchPerson_ByFullNameOnly_ShouldReturnResults() { string errorMessagePrefix = "PersonService SearchPerson(PersonSearchViewModel) method does not work properly."; var context = HealthInsDbContextInMemoryFactory.InitializeContext(); this.personService = new PersonService(context); await SeedData(context); PersonSearchViewModel personSearchViewModel = new PersonSearchViewModel() { FullName = "Ivan" }; var actualResults = this.personService.SearchPerson(personSearchViewModel); Assert.True(actualResults.FirstOrDefault().Id == 2, errorMessagePrefix); }
public async Task <ActionResult> PersonSearch(string search) { PersonSearchViewModel persons = new PersonSearchViewModel(); var baseAddress = new Uri("http://api.themoviedb.org/3/"); using (var httpClient = new HttpClient { BaseAddress = baseAddress }) { httpClient.DefaultRequestHeaders.TryAddWithoutValidation("accept", "application/json"); using (var response = await httpClient.GetAsync($"search/person?api_key=0ac277c3f170caa0df815398709d9bb2&query={search}&language=hu-BR")) { string jsonFile = await response.Content.ReadAsStringAsync(); persons = JsonConvert.DeserializeObject <PersonSearchViewModel>(jsonFile); } } return(View(persons)); }
private ActionResult RunSimpleSearch( PersonSearchViewModel item, string pageNumber, string sortBy) { if (item.SimpleSearchValue.IsNullOrWhitespace() == false) { ModelState.Clear(); string sortDirection; if (sortBy == null) { // the value didn't change because of HTTP POST sortBy = item.CurrentSortProperty; sortDirection = item.CurrentSortDirection; } else { sortDirection = GetSortDirection(item, sortBy); } var results = _Service.SimpleSearch(item.SimpleSearchValue, sortBy, sortDirection); var pageableResults = new PageableResults <Person>(); pageableResults.Initialize(results); pageableResults.CurrentPage = pageNumber.SafeToInt32(0); item.Results = pageableResults; item.CurrentSortDirection = sortDirection; item.CurrentSortProperty = sortBy; } return(View(item)); }
public ActionResult Search() { PersonSearchViewModel psvm = new PersonSearchViewModel(); return(View(psvm)); }
public ActionResult Search() { var viewModel = new PersonSearchViewModel(); return(View(viewModel)); }