public string Search([FromBody] PersonSearchModel search) { var term = search.Name; var peopleModel = new List <PersonModel>(); try { var people = _bll.GetPeopleByName(term); peopleModel = people.Select(i => new PersonModel { First = i.First, Last = i.Last, Address = i.Address, Age = i.Age, Interest = i.Interests, Picture = i.Picture }).ToList <PersonModel>();; return(JsonConvert.SerializeObject(new Response { State = RequestState.Success, Msg = "", Data = peopleModel })); } catch (Exception ex) { return(JsonConvert.SerializeObject(new Response { State = RequestState.Failed, Msg = ex.Message, Data = null })); } }
public static IEnumerable <Orphan> GetFiltered(this IEnumerable <Orphan> persons, PersonSearchModel searchModel) { if (searchModel != null) { _searchModel = searchModel; if (!string.IsNullOrEmpty(searchModel.FullNameString)) { persons = persons.Where(x => IsContain(x.FullName)); } if (searchModel.RatingNumber > 0) { persons = persons.Where(x => x.Rating == searchModel.RatingNumber); } if (searchModel.AgeNumber >= 0) { DateTime data = DateTime.Now; persons = persons.Where(x => (data.Year - x.Birthday.Year) >= searchModel.AgeNumber); } } return(persons); }
public ActionResult GetAllPaged(PersonSearchModel model) { var select = db.Persons.Select(s => new { s.PersonId, s.FirstName, s.LastName, s.NationalID, s.MobileNo, s.Tel, s.FatherName, s.IDNumber, s.Email, s.Address, EducationalLevelTitle = s.EducationalLevel.Title, s.State, s.Description }); AllItems = JsonConvert.DeserializeObject <List <PersonModel> >(JsonConvert.SerializeObject(select)); var filtered = AllItems; if (model.FirstName != null) { filtered = filtered.Where(x => x.FirstName.Contains(model.FirstName)).ToList(); } if (model.LastName != null) { filtered = filtered.Where(x => x.LastName.Contains(model.LastName)).ToList(); } if (model.Description != null) { filtered = filtered.Where(x => x.Description.Contains(model.Description)).ToList(); } PagedList <PersonModel> result = new PagedList <PersonModel>(); result.Items = filtered.Skip((model.PageIndex * model.PageSize)).Take(model.PageSize).ToList(); result.PageIndex = model.PageIndex; result.PageSize = model.PageSize; result.TotalItemsCount = filtered.Count; return(Ok(result)); }
public async Task <IActionResult> PersonSearch([FromQuery] PersonSearchModel personSearch) { var filter = PersonSearchToFilterDto.Instance.Map(personSearch); var allPersons = await personService.GetAllPersons(1, 30, filter); return(Json(allPersons)); }
public ActionResult SearchResults(PersonSearchModel searchModel) { var query = new PersonSearchModelQueryAdapter(searchModel); var people = _personRepository.Query(query); return(View("Index", people)); }
public ResponseModel <List <T> > SearchPeople(PersonSearchModel searchModel) { try { var personsEntityList = new List <PersonsEntity>(); if (searchModel.AccountNumber != null) { var personCode = _context.Account.Where(i => i.AccountNumber.Contains(searchModel.AccountNumber)).Select(i => i.PersonCode).ToList(); personsEntityList.AddRange(_context.Person.Where(i => personCode.Contains(i.Code)).ToList()); } if (searchModel.IdNumber != null) { personsEntityList.AddRange(_context.Person.Where(i => i.IdNumber.Contains(searchModel.IdNumber)).ToList()); } if (searchModel.Surname != null) { personsEntityList.AddRange(_context.Person.Where(i => i.Surname.Contains(searchModel.Surname)).ToList()); } var personsModelList = _mapper.Map <List <PersonsEntity>, List <T> >(personsEntityList); var response = SuccessResponseWithObject(personsModelList); return(response); } catch (Exception ex) { return(FailResponse(1, "Error Returning Records", ex.GetBaseException().ToString())); } }
public async Task Search_CallsServiceCorrectly() { var matchingPeople = _fixture.CreateMany <Person>(5).ToList(); _mockService.Setup(svc => svc.GetPeopleMatchingSearchTermAsync(It.IsAny <string>())) .ReturnsAsync(matchingPeople); var mappedResponse = _fixture.CreateMany <PersonViewModel>(5).ToList(); _mockMapper .Setup(m => m.Map <List <PersonViewModel> >(It.IsAny <List <Person> >())) .Returns(mappedResponse); var searchModel = new PersonSearchModel { SearchTerm = "Adm" }; var result = await SUT.Search(searchModel); _mockService.Verify(svc => svc.GetPeopleMatchingSearchTermAsync(searchModel.SearchTerm), Times.Once); _mockMapper.Verify(m => m.Map <List <PersonViewModel> >(matchingPeople), Times.Once); var partialViewResult = result.ShouldBeAssignableTo <PartialViewResult>(); partialViewResult.Model.ShouldBe(mappedResponse); partialViewResult.ViewName.ShouldBe("_List"); }
public async Task <IActionResult> Index(PersonSearchModel searchModel) { IEnumerable <CharityMaker> charityMakers = _unitOfWorkAsync.CharityMakers.GetAll(); charityMakers = CharityMakerFilter.GetFiltered(charityMakers, searchModel); return(View(charityMakers)); }
public async Task <IActionResult> Grid(PersonSearchModel model) { model = InitializeModel(model); var result = await _customerApiClient.GetPersons(model); PopulateValuesFromLookup(result); return(PartialView(result)); }
public async Task <IActionResult> Search(PersonSearchModel searchModel) { var peopleMatchingSearchTerm = await _personService.GetPeopleMatchingSearchTermAsync(searchModel.SearchTerm); var viewModel = _mapper.Map <List <PersonViewModel> >(peopleMatchingSearchTerm); return(PartialView("_List", viewModel)); }
public async Task <IActionResult> Get([FromQuery] PersonSearchModel searchModel) { var people = await _peopleRepository.FindManyAsync( new string[] { "Emails", "Address", "Phones" }, searchModel.GetSearchExpressions()); return(ActionResultUtil.WrapOrNotFound(people)); }
public JsonResult InitUnitTestSearchModel() { PersonSearchModel searchModel = new PersonSearchModel() { Name = string.Empty }; return(Json(searchModel, JsonRequestBehavior.AllowGet)); }
public async Task <IActionResult> GetAllPersons([FromQuery] PersonSearchModel personSearch = null, PageQueryParameters pageQueryParameters = null) { var filter = PersonSearchToFilterDto.Instance.Map(personSearch); var allPersons = await personService.GetAllPersons(pageQueryParameters.PageNumber, pageQueryParameters.PageSize, filter); var listOfPersonsVM = new PaginatedList <PersonDTO>(allPersons); return(View(listOfPersonsVM)); }
private void PopulateValuesFromLookup(PersonSearchModel result) { var lookups = _facadeApiClient.GetLookup().Result; foreach (var personDto in result.PersonSearchResult) { UpdateCustomProperty(personDto, lookups); } }
public IEnumerable <FamousPersonInfo> Search(PersonSearchModel searchModel) { //初始化查询sql语句 var sqlBuilder = new StringBuilder("select famousperson.* from famousperson join persontyperelation on famousperson.famousPersonId=persontyperelation.famouspersonId where "); //初始化查询参数 var searchParams = new List <object>(); //处理参数 DealStringQueryParam("PersonName", searchModel.PersonName, sqlBuilder, searchParams); DealStringQueryParam("Province", searchModel.Province, sqlBuilder, searchParams); DealStringQueryParam("Nation", searchModel.Nation, sqlBuilder, searchParams); DealStringQueryParam("BornPlace", searchModel.BornPlace, sqlBuilder, searchParams); DealStringQueryParam("DeadPlace", searchModel.DeadPlace, sqlBuilder, searchParams); if (searchModel.FamousPersonTypeId != null) { sqlBuilder.Append("persontyperelation.FamousPersonTypeId ={0} and "); searchParams.Add(searchModel.FamousPersonTypeId); } if (searchModel.MinBornDate != null) { sqlBuilder.Append("BornDate >={0} and "); searchParams.Add(searchModel.MinBornDate); } if (searchModel.MaxBornDate != null) { sqlBuilder.Append("BornDate <={0} and "); searchParams.Add(searchModel.MaxBornDate); } if (searchModel.MinDeadDate != null) { sqlBuilder.Append("DeadDate >={0} and "); searchParams.Add(searchModel.MinDeadDate); } if (searchModel.MaxDeadDate != null) { sqlBuilder.Append("DeadDate <={0} and "); searchParams.Add(searchModel.MaxDeadDate); } var personInfos = new List <FamousPersonInfo>(); //无任何查询参数 返回无元素的数组 if (searchParams.Count == 0) { return(personInfos); } //移除最后多余的"and " sqlBuilder.Remove(sqlBuilder.Length - 5, 4); //sql查询 var persons = famousPersonRepository.FindBySQL(sqlBuilder.ToString(), searchParams.ToArray()); foreach (var person in persons) { var typeIds = personTypeRelationRepository.FindByWhereAndSelect(p => p.FamousPersonId == person.FamousPersonId, p => p.FamousPersonTypeId).ToList(); personInfos.Add(FamousPersonConverter.ConvertToDto(person, (IEnumerable <int>)typeIds)); } return(personInfos); }
public async Task <IActionResult> Index(PersonSearchModel searchModel) { IEnumerable <Volunteer> volunteers = _unitOfWorkAsync.Volunteers.GetAll(); volunteers = VolunteerFilter.GetFiltered(volunteers, searchModel); GetViewData(); return(View(volunteers)); }
public ActionResult <IEnumerable <PersonDetailsModel> > Index(long companyId, string searchTerm = null) { var search = new PersonSearchModel(); search.Term = searchTerm; var response = manager.GetIndexModel(companyId, search); return(Ok(response)); }
public IActionResult Search(PersonSearchModel personSearchModel) { ViewData["Title"] = "Search People"; if (personSearchModel.PersonSearch != null) { personSearchModel.Persons = AutoMap.Mapper.Map(PersonData.GetPersons(personSearchModel.PersonSearch), new List <PersonModel>()); } personSearchModel.States = BuildStates(); return(View(personSearchModel)); }
public static List <Person> SearchPersons(PersonSearchModel searchModel) { var result = personService.GetAllPersons(searchModel.ShowDeletedPerson); if (!string.IsNullOrEmpty(searchModel.SearchPersonText)) { var searchText = searchModel.SearchPersonText.ToLower(); result = result.Where(o => o.FullName.ToLower().Contains(searchText) || o.Position.ToLower().Contains(searchText)).ToList(); } return(result); }
public IActionResult SearchPeople([FromBody] PersonSearchModel searchRequest) { try { var searchResults = _service.SearchPeople(searchRequest); return(Ok(searchResults)); } catch (Exception ex) { return(StatusCode((int)HttpStatusCode.InternalServerError, "A problem happened while handling your request.")); } }
public IEnumerable <PersonDetailsModel> GetIndexModel(long companyId, PersonSearchModel search) { var company = dc.Companies.Find(X => X.Id == companyId); if (company == null) { throw new KeyNotFoundException(); } else { var items = dc.People.AsQueryable().Where(X => X.CompanyId == company.Id); if (search != null) { if (!string.IsNullOrEmpty(search.Term)) { var words = search.Term.ToUpper().Split(" "); foreach (string word in words) { items = items.Where(X => X.Forename.ToUpper().Contains(word) || X.Surname.ToUpper().Contains(word) || X.MobileNumber.ToUpper().Contains(word) || X.TelephoneNumber.ToUpper().Contains(word) || X.Email.ToUpper().Contains(word) || X.JobTitle.ToUpper().Contains(word)); } } } var response = new List <PersonDetailsModel>(); foreach (var item in items) { response.Add(new PersonDetailsModel { PersonId = item.Id, Forename = item.Forename, Surname = item.Surname, TelephoneNumber = item.TelephoneNumber, MobileNumber = item.MobileNumber, Email = item.Email, JobTitle = item.JobTitle }); } return(response); } }
public void PersonTests_ReturnSearchedPeople(string idNumber, string surname, string accountNo, int expectedResult) { //Arrange var searchModel = new PersonSearchModel { IdNumber = idNumber, Surname = surname, AccountNumber = accountNo }; //Act var returnedRecord = _service.SearchPeople(searchModel); //Assert Assert.IsTrue(returnedRecord.ReturnObject.Count() == expectedResult); }
public JsonResult GetPersonForAutoComplete(string query) { var personSearchModel = new PersonSearchModel { PageSize = 20, FilterText = query, SortColumn = "Forename" }; personSearchModel = _customerApiClient.GetPersons(personSearchModel).Result; return(Json(personSearchModel.PersonSearchResult.Select(p => new { p.Id, p.Forename, p.Surname, dateofbirth = p.DateOfBirth?.ToShortDateString() ?? "" }))); }
public JsonResult UnitTestResultModel(PersonSearchModel searchModel) { PersonResultModel resultModel = new PersonResultModel(); if (!string.IsNullOrEmpty(searchModel.Name)) { resultModel.Entries.AddRange(PersonEntries.Where(p => p.FirstName.Contains(searchModel.Name) || p.LastName.Contains(searchModel.Name))); } else { resultModel.Entries.AddRange(PersonEntries); } return(Json(resultModel, JsonRequestBehavior.AllowGet)); }
public async Task <PersonSearchModel> GetPersons(PersonSearchModel model) { var url = ODataApiUri + "/Person?" + GetFilterString(model); var result = await GetOdataResultFromApi(url); var searchResultCount = 0; if (result.Count != null) { int.TryParse(result.Count.ToString(), out searchResultCount); } model.TotalRows = searchResultCount; model.PersonSearchResult.Clear(); model.PersonSearchResult.AddRange(result.Items.Select(item => JsonConvert.DeserializeObject <PersonDto>(item.ToString()))); return(model); }
public async Task <ObservableCollection <FamousPerson> > SearchAsync(PersonSearchModel searchModel) { using (var httpClient = new HttpClient()) { var response = await httpClient.PostAsJsonAsync(SearchUrl, searchModel); if (response.IsSuccessStatusCode) { return(await response.Content.ReadAsAsync <ObservableCollection <FamousPerson> >()); } else { var apiErrorModel = await response.Content.ReadAsAsync <ApiErrorModel>(); throw new ApiErrorException(apiErrorModel); } } }
public static IEnumerable <Representative> GetFiltered(this IEnumerable <Representative> persons, PersonSearchModel searchModel) { if (searchModel != null) { _searchModel = searchModel; if (!string.IsNullOrEmpty(searchModel.FullNameString)) { persons = persons.Where(x => IsContain(x.FullName)); } if (searchModel.RatingNumber > 0) { persons = persons.Where(x => x.Rating == searchModel.RatingNumber); } } return(persons); }
public async Task <IActionResult> Index(int id, PersonSearchModel searchModel) { IEnumerable <Orphan> orphans = _unitOfWorkAsync.Orphans.GetAll(); orphans = OrphanFilter.GetFiltered(orphans, searchModel); if (id == 0) { return(View(orphans)); } if (id > 0) { orphans = orphans.Where(x => x.Orphanage.ID.Equals(id)).ToList(); } GetViewData(); return(View(orphans)); }
public async Task <IActionResult> Index(int id, PersonSearchModel searchModel) { IEnumerable <Representative> representatives = _unitOfWorkAsync.Representatives.GetAll(); representatives = RepresentativeFilter.GetFiltered(representatives, searchModel); if (id == 0) { return(View(representatives)); } if (id > 0) { representatives = representatives.Where(x => x.Orphanage.ID.Equals(id)); } return(View(representatives)); }
public async Task <IActionResult> HouseholdMember(PersonSearchModel model) { var person = await _customerApiClient.GetPerson(model.PersonId); model.PersonId = 0; model.MainContactPersonId = person.MainContactPersonId ?? 0; if (model.MainContactPersonId > 0) { InitializeSearchModel(model, "HouseholdMemberGrid", "Id", "Desc"); model = await _customerApiClient.GetPersons(model); var householdMembers = model.PersonSearchResult.Where(x => x.Id != person.Id).ToList(); model.PersonSearchResult.Clear(); model.PersonSearchResult.AddRange(householdMembers); PopulateValuesFromLookup(model); } return(PartialView(model)); }
public void Verify_Search_WithPaging_Should_ReturnAListOfPeopleWithDataMatchingSearchParameters() { // Arrange Mock<IDbSet<Person>> mockSetPeople; var mockContext = PeopleMockingSetup.DoMockingSetupForContext(true, out mockSetPeople); var repository = new PeopleRepository(mockContext.Object); var searchModel = new PersonSearchModel { Paging = new Paging { Skip = 1, Take = 1 } }; // Act var people = repository.Search(searchModel/*.Object*/).ToArray(); // Assert Assert.Equal(1, people.Length); Assert.Equal(2, people[0].Id); Assert.Equal("/TEST/NIVEN-LARRY", people[0].ApiDetailUrl); // Stephen King was filtered out because he was Skipped }
public void Verify_Search_WithModifiedSince_Should_ReturnAListOfPeopleWithDataMatchingSearchParameters() { // Arrange Mock<IDbSet<Person>> mockSetPeople; var mockContext = PeopleMockingSetup.DoMockingSetupForContext(true, out mockSetPeople, true); var repository = new PeopleRepository(mockContext.Object); var createDate = new System.DateTime(2015, 05, 28, 10, 45, 00).AddDays(1).AddMinutes(-1); //var searchModel = new Mock<IPersonSearchModel>(); //searchModel.Setup(m => m.ModifiedSince).Returns(() => createDate); var searchModel = new PersonSearchModel { ModifiedSince = createDate }; // Act var people = repository.Search(searchModel/*.Object*/).ToArray(); // Assert Assert.Equal(1, people.Length); Assert.Equal(2, people[0].Id); Assert.Equal("/TEST/NIVEN-LARRY", people[0].ApiDetailUrl); // Stephen King was filtered out because he was created before the modified since date }