public PagedResponse <CategoriesDto> Execute(CategoriesSearch search) { var query = _context.Categories.AsQueryable(); if (!string.IsNullOrEmpty(search.Name) || !string.IsNullOrWhiteSpace(search.Name)) { query = query.Where(x => x.Name.ToLower().Contains(search.Name.ToLower())); } query = query.Where(x => x.IsActive == true); var skipCount = search.PerPage * (search.Page - 1); var response = new PagedResponse <CategoriesDto> { CurrentPage = search.Page, ItemsPerPage = search.PerPage, TotalCount = query.Count(), Items = query.Skip(skipCount).Take(search.PerPage).Select(x => new CategoriesDto { Id = x.Id, Name = x.Name }).ToList() }; return(response); }
public IEnumerable <CategoryDto> Execute(CategoriesSearch request) { var categories = Context.Categories.AsQueryable(); if (request.Name != null) { categories = categories.Where(c => c.Name.ToLower().Contains(request.Name.ToLower())); } if (request.OnlyActive != null) { categories = categories.Where(c => c.IsActive == request.OnlyActive); } if (request.OnlyActive == null) { categories = categories.Where(c => c.IsActive); } return(categories.Select(c => new CategoryDto { Id = c.Id, Name = c.Name })); }
public IActionResult Get([FromQuery] CategoriesSearch search, [FromServices] IGetCategoriesQuery query) { return(Ok(executor.ExecuteQuery(query, search))); }
public IActionResult Get([FromQuery] CategoriesSearch query) { return(Ok(_getCommands.Execute(query))); }