예제 #1
0
        public async Task <IEnumerable <PersonForListDto> > GetAll(PersonFilterDto personFilter)
        {
            var persons = await _uow.Repository <Domain.Entities.Person>().FindAsyncWithPagination(new PersonFilterPaginatedSpecification(personFilter));

            _context.HttpContext.Response.AddPagination(persons.CurrentPage, persons.PageSize, persons.TotalCount, persons.TotalPages);

            var personsToReturn = _mapper.Map <IEnumerable <PersonForListDto> >(persons);

            await _photoService.IncludeMainPhoto(personsToReturn, (int)EntityTypes.Person);

            return(personsToReturn);
        }
예제 #2
0
        public int CalculeteTotalElements(PersonFilterDto filter)
        {
            var sql        = new StringBuilder(" SELECT COUNT(id) FROM persons ");
            var parameters = new Dictionary <string, object>();

            if (!string.IsNullOrEmpty(filter.Name))
            {
                sql.Append(" WHERE UPPER(name) LIKE UPPER(@name)");
                parameters.Add("name", "%" + filter.Name + "%");
            }

            return(_connection.ExecuteScalar <int>(sql.ToString(), parameters));
        }
예제 #3
0
        public IEnumerable <Person> Find(PersonFilterDto filter)
        {
            var sql        = new StringBuilder(" SELECT * FROM persons ");
            var parameters = new Dictionary <string, object>();

            if (!string.IsNullOrEmpty(filter.Name))
            {
                sql.Append(" WHERE UPPER(name) LIKE UPPER(@name)");
                parameters.Add("name", "%" + filter.Name + "%");
            }

            sql.Append(" LIMIT @page, @size ");
            parameters.Add("page", filter.Page != 0 ? filter.Page * filter.Size : filter.Page);
            parameters.Add("size", filter.Size == 0 ? 5 : filter.Size);

            return(_connection.Query <Person>(sql.ToString(), parameters));
        }
 public ResponsePaginationDto <Person> Search(PersonFilterDto filter)
 {
     return(new ResponsePaginationDto <Person>(_repository.CalculeteTotalElements(filter), _repository.Find(filter)));
 }
 public ActionResult <ResponsePaginationDto <Person> > Search([Required][FromQuery] PersonFilterDto filter)
 {
     return(Ok(_service.Search(filter)));
 }
예제 #6
0
 public PersonFilterPaginatedSpecification(PersonFilterDto personFilter)
     : base(x => string.IsNullOrWhiteSpace(personFilter.Name) ||
            (x.FirstName + " " + x.LastName).ToLower().Contains(personFilter.Name.ToLower()))
 {
     ApplyPaging(personFilter.Skip, personFilter.Take, personFilter.PageNumber);
 }
예제 #7
0
 public async Task <IActionResult> GetAll([FromQuery] PersonFilterDto personFilter)
 {
     return(Ok(await _personService.GetAll(personFilter)));
 }