Пример #1
0
        public async Task <ActionResult <List <PersonDto> > > Search(
            PersonSearchCriteria criteria,
            CancellationToken token = default)
        {
            var directorsQuery = Context.People.Where(p => p.KnownFor == DepartmentEnums.Directing)
                                 .TagWith($"Searching for {criteria.Query}")
                                 .FullTextSearchIf(string.IsNullOrWhiteSpace(criteria.Query), criteria.Query)
                                 .OrderBy(x => x.Id);

            var totalDirectors = await directorsQuery.CountAsync(token);

            if (criteria.Page > ((totalDirectors / criteria.ItemsPerPage) + 1))
            {
                return(BadRequest("Page doesn't exist"));
            }

            var pagedDirectors = await directorsQuery.Slice(criteria.Page, criteria.ItemsPerPage)
                                 .Project <Person, PersonDto>(Mapper)
                                 .ToListAsync(token);

            var result = new PagedResult <PersonDto>
            {
                Results       = pagedDirectors,
                Page          = criteria.Page,
                TotalPages    = (totalDirectors / criteria.ItemsPerPage) + 1,
                TotalElements = totalDirectors,
            };

            return(Ok(result));
        }
        public void Constructor()
        {
            PersonSearchCriteria searchCriteria;

            searchCriteria = new PersonSearchCriteria();
            Assert.IsNotNull(searchCriteria);
        }
Пример #3
0
        public SearchResult <Person> Search(PersonSearchCriteria searchCriteria)
        {
            var result = searchCriteria.Gender.IsNullOrEmpty()
                ? _peopleStore.Data.Where(p => p.Name.ToLower().StartsWith(searchCriteria.Name.ToLower())).ToList()
                : _peopleStore.Data.Where(p =>
                                          p.Name.ToLower().StartsWith(searchCriteria.Name.ToLower()) &&
                                          p.Gender == searchCriteria.Gender).ToList();

            if (searchCriteria.Index > result.Count)
            {
                return new SearchResult <Person>
                       {
                           Count   = result.Count,
                           Results = new List <Person>()
                       }
            }
            ;

            if (searchCriteria.Index + searchCriteria.Count > result.Count)
            {
                return(new SearchResult <Person>
                {
                    Count = result.Count,
                    Results = result.GetRange(searchCriteria.Index,
                                              result.Count - searchCriteria.Index)
                });
            }

            return(new SearchResult <Person>
            {
                Count = result.Count,
                Results = result.GetRange(searchCriteria.Index, searchCriteria.Count)
            });
        }
    }
        public IHttpActionResult Search([FromUri] PersonSearchCriteria criteria)
        {
            // Search Persons
            var searchResults = EntityManager.SearchPersons(criteria.ToSearchCriteria());

            return(SearchResponse(searchResults));
        }
        public void PersonManager_Search_ShouldCall_RepositorySearch(PersonSearchCriteria personSearchCriteria)
        {
            //Arrange
            Mock <IPersonRepository> personRepository = new Mock <IPersonRepository>();


            SetupUserIdentity();
            SetupPersonRepository(personRepository);

            var criteria = new SearchCriteria();

            criteria.Add(new FilterParameter("PersonId", 123));

            PersonsManager personsManager = new PersonsManager(userManager.Object, cacheStoreManager, mockLogManager.Object, personRepository.Object, transformationManager);

            //Act
            IPaginatedList <BLL_Person> actual = personsManager.Search(criteria);

            int expectedTotalRecordCount = 1;

            //Assert
            personRepository.Verify(p => p.Search(It.IsAny <SearchCriteria>()));

            Assert.AreEqual(expectedTotalRecordCount, actual.TotalRecordCount);
        }
 private PersonSearchCriteria GetSearchCriteria(Boolean refresh)
 {
     if (_searchCriteria.IsNull() || refresh)
     {
         _searchCriteria = new PersonSearchCriteria();
     }
     return(_searchCriteria);
 }
        public List <Person> Execute(PersonSearchCriteria searchCriteria)
        {
            var persons = (from person in _dbContext.Persons
                           where person.IsActive
                           where string.IsNullOrWhiteSpace(searchCriteria.Keyword) ||
                           $" {person.FirstName} {person.LastName} ".Contains(searchCriteria.Keyword)
                           where searchCriteria.IncludedPersonIDs.Count == 0 ||
                           searchCriteria.IncludedPersonIDs.Contains(person.ID)
                           select person);

            return(persons.ToList());
        }
Пример #8
0
        public ActionResult GetPersons(JqGridRequest request, string keyword)
        {
            var searchCriteria = new PersonSearchCriteria();
            var result         = _personReportService.Search(searchCriteria, request.RecordsCount, request.PageIndex);
            var jsonData       = new
            {
                total   = (result.Count + request.RecordsCount - 1) / request.RecordsCount,
                page    = request.PageIndex + 1,
                records = result.Count,
                rows    = result.Items
            };

            return(Json(jsonData, JsonRequestBehavior.AllowGet));
        }
        public void PersonsController_Get_Returns_OKResponseCode(PersonSearchCriteria personSearchCriteria)
        {
            #region Arrange
            SetupUserIdentity();
            SetupPersonRepository(personSearchCriteria, out Mock <IPersonRepository> personRepository, out IPaginatedList <TbPerson> expected);

            var httpRequest = new HttpRequestMessage(new HttpMethod(AppSettings.HTTPGET), $"{AppSettings.BASEURL}{RouteHelper.PersonRoutePrefix}/{personSearchCriteria}");

            PersonsController personsController = CreatePersonsController(httpRequest, personRepository.Object);

            #endregion

            #region Act

            var response = personsController.Search(personSearchCriteria);
            //var response = personsController.Get(It.IsAny<int>());
            var contentResult = response as NegotiatedContentResult <ResponsePaginatedCollection <Person> >;


            #endregion

            #region Assert

            #region Expected Data

            var expectedPerson = new Person()
            {
                PersonId    = (personSearchCriteria.PersonId) == 0 ? userIdentity.UserId : 123,
                FirstName   = "John",
                LastName    = "Smith",
                DisplayName = "John Smith"
            };

            #endregion

            Assertions.AssertOkResponse(contentResult);

            var personsData = contentResult.Content.results;
            for (int i = 0; i <= personsData.Count - 1; i++)
            {
                //Data
                var actualPerson = personsData[i].data;
                Assertions.AssertData(expectedPerson, actualPerson);
            }

            #endregion
        }
 public PersonSearchCriteriaTest()
 {
     _searchCriteria = null;
 }
        private void SetupPersonRepository(PersonSearchCriteria personSearchCriteria, out Mock <IPersonRepository> personRepository, out IPaginatedList <TbPerson> expected)
        {
            //Create mock repository
            personRepository = new Mock <IPersonRepository>();

            //Build response
            List <TbPerson> personDbData = new List <TbPerson> {
                new TbPerson()
                {
                    PersonId   = 123,
                    FirstName  = "John",
                    LastName   = "Smith",
                    CommonName = "John Smith"
                },
                new TbPerson()
                {
                    PersonId   = 124,
                    FirstName  = "John",
                    LastName   = "Smith",
                    CommonName = "",
                    PersonName = "John Smith"
                },
                new TbPerson()
                {
                    PersonId   = 125,
                    FirstName  = "John",
                    LastName   = "Smith",
                    CommonName = "",
                    PersonName = ""
                },
                new TbPerson()
                {
                    PersonId   = userIdentity.UserId,
                    FirstName  = "John",
                    LastName   = "Smith",
                    CommonName = "",
                    PersonName = ""
                }
            };

            expected = new PaginatedList <TbPerson>()
            {
                PageCount        = 10,
                PageIndex        = 0,
                PageSize         = 10,
                TotalRecordCount = 1,
                Items            = new List <TbPerson>()
                {
                    personDbData.Find((p) => p.PersonId == (personSearchCriteria.PersonId == 0 ? userIdentity.NameId : personSearchCriteria.PersonId))
                }
            };


            // Search method
            personRepository.Setup(p => p.Search(It.IsAny <SearchCriteria>())).Returns(expected);

            //Filter & Sort Parameters
            personRepository.Setup(x => x.GetFilterParameters()).Returns(new List <string> {
                "PersonId"
            });

            personRepository.Setup(x => x.GetSortParameters()).Returns(new List <string> {
                "PersonId", "FirstName", "LastName", "CommonName"
            });
        }
Пример #12
0
 public GetPersonDTOBySearchCriteriaDbCommand(PersonSearchCriteria criteria, int pageIndex, int pageSize)
 {
     _criteria  = criteria;
     _pageIndex = pageIndex;
     _pageSize  = pageSize;
 }
Пример #13
0
 private static void SerializePatientSearchCriteria()
 {
     PersonSearchCriteria psc = new PersonSearchCriteria();
     psc.CompareOp = new SystemParameter(1, "LessThan");
     psc.FieldName = "Age";
     psc.FieldValue1 = "50";
     psc.FieldValue2 = "60";
     SerializeMe(psc, "PersonSearchCriteria.xml");
 }
Пример #14
0
 public SearchResult <PersonDTO> Search(PersonSearchCriteria searchCriteria, int pageSize, int pageIndex)
 {
     return(_executor.Execute(new GetPersonDTOBySearchCriteriaDbCommand(searchCriteria, pageIndex, pageSize)));
 }