コード例 #1
0
 public ActionResult <PagedResponse <GenderDto> > Get([FromQuery] GenderSearch genderSearch)
 {
     try
     {
         var genders = this.getGendersCommand.Execute(genderSearch);
         return(Ok(genders));
     }
     catch (Exception)
     {
         return(StatusCode(500));
     }
 }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 public IActionResult Get([FromQuery] GenderSearch search, [FromServices] IGetGenders query)
 {
     return(Ok(_executor.ExecuteQuery(query, search)));
 }
コード例 #5
0
        public PagedResponse <GenderDto> Execute(GenderSearch search)
        {
            var query = _context.Genders.AsQueryable();

            return(query.MakePaged <GenderDto, Gender>(search, _mapper));
        }