public ActionResult <PagedResponse <GenderDto> > Get([FromQuery] GenderSearch genderSearch) { try { var genders = this.getGendersCommand.Execute(genderSearch); return(Ok(genders)); } catch (Exception) { return(StatusCode(500)); } }
public PagedResponse <GenderDto> Execute(GenderSearch request) { var query = this.Context.Genders .Where(g => !g.IsDeleted) .AsQueryable(); if (request.Name != null) { query = query.Where( g => g.Name.ToLower() .Contains(request.Name.ToLower())); } if (request.IsActive != null) { query = query.Where( g => g.IsActive == request.IsActive); } int totalCount = query.Count(); // number of pages/buttons int numberOfPages = (int)Math.Ceiling((double)totalCount / request.PerPage); query = query.Skip(request.PageNumber * request.PerPage - request.PerPage).Take(request.PerPage); // second way .Skip((request.PageNumber - 1)* request.PerPage).Take(request.PerPage); var result = new PagedResponse <GenderDto> { TotalNumber = totalCount, PagesNumber = numberOfPages, CurrentPage = request.PageNumber, Data = query.Select(g => new GenderDto { Id = g.Id, Name = g.Name, IsActive = g.IsActive }) }; return(result); }
public PagedResponse <GenderDto> Execute(GenderSearch search) { var query = _context.Genders.AsQueryable(); if (!string.IsNullOrEmpty(search.Name) || !string.IsNullOrWhiteSpace(search.Name)) { query = query.Where(x => x.Name.ToLower().Contains(search.Name.ToLower())); } var skipCount = search.PerPage * (search.Page - 1); var response = new PagedResponse <GenderDto> { CurrentPage = search.Page, ItemsPerPage = search.PerPage, TotalCount = query.Count(), Items = _mapper.Map <List <GenderDto> >(query.Skip(skipCount).Take(search.PerPage).ToList()) }; return(response); }
public IActionResult Get([FromQuery] GenderSearch search, [FromServices] IGetGenders query) { return(Ok(_executor.ExecuteQuery(query, search))); }
public PagedResponse <GenderDto> Execute(GenderSearch search) { var query = _context.Genders.AsQueryable(); return(query.MakePaged <GenderDto, Gender>(search, _mapper)); }