public async Task <IEnumerable <Customer> > GetAll(CustomerQueryParameters customerQueryParameters) { IEnumerable <Customer> result; if (customerQueryParameters.HasQuery) { result = await packDbContext.Customers .FromSqlRaw($@" SELECT [Id] ,[Firstname] ,[Lastname] ,[Age] FROM [dbo].[Customers] WHERE Firstname LIKE '%{customerQueryParameters.Query}%' OR Lastname LIKE '%{customerQueryParameters.Query}%' ") .ToListAsync(); } else { result = await packDbContext.Customers.ToListAsync(); } return(result.OrderBy(c => c.Firstname) .Skip(customerQueryParameters.PageCount * (customerQueryParameters.Page - 1)) .Take(customerQueryParameters.PageCount)); }
//[ProducesResponseType(typeof(IList<Customer>), 200)] public IActionResult GetAllCustomers([FromQuery] CustomerQueryParameters customerQueryParameters) { var customerEntities = _customerRepository.GetAll(customerQueryParameters); var customerDtos = customerEntities.Select(c => Mapper.Map <CustomerDTO>(c)); Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(new { totalCount = _customerRepository.Count() })); return(Ok(customerDtos)); }
public IActionResult GetAllCustomers(CustomerQueryParameters customerQueryParameters) { var allCustomers = _customerRepository.GetAll(customerQueryParameters).ToList(); var allCustomersDto = allCustomers.Select(x => Mapper.Map <CustomerDto>(x)); Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(new { totalCount = _customerRepository.Count() })); return(Ok(allCustomersDto)); }
public IActionResult GetAllCustomers(CustomerQueryParameters customerQueryParameters) { _logger.LogInformation(" ----> GetAllCustomers()"); var allCustomers = _customerRepository.GetAll(customerQueryParameters).ToList(); var allCustomersDto = allCustomers.Select(x => AutoMapper.Mapper.Map <CustomerDto>(x)); Response.Headers.Add("X-Pagination", Newtonsoft.Json.JsonConvert.SerializeObject(new { totalCount = _customerRepository.Count() }) ); return(Ok(allCustomersDto)); }
public async Task <IEnumerable <CustomerDto> > ListAll(CustomerQueryParameters customerQueryParameters) { var result = await customerRepository.GetAll(customerQueryParameters); return(result.Select(r => new CustomerDto { Id = r.Id, Age = r.Age, Firstname = r.Firstname, Lastname = r.Lastname })); }
public IQueryable <Customer> GetAll(CustomerQueryParameters customerQueryParameters) { IQueryable <Customer> _allCustomers = _context.Customers.OrderBy(customerQueryParameters.OrderBy, customerQueryParameters.Descending); if (customerQueryParameters.HasQuery) { _allCustomers = _allCustomers .Where(x => x.FirstName.ToLowerInvariant().Contains(customerQueryParameters.Query.ToLowerInvariant()) || x.LastName.ToLowerInvariant().Contains(customerQueryParameters.Query.ToLowerInvariant())); } return(_allCustomers .Skip(customerQueryParameters.PageCount * (customerQueryParameters.Page - 1)) .Take(customerQueryParameters.PageCount)); }
[ProducesResponseType(typeof(List <Customer>), 200)] //[ProducesResponseType(typeof(void), 200)] //public IActionResult GetAllCustomers() // CustomerQueryParameters customerQueryParameters public IActionResult GetAllCustomers(CustomerQueryParameters customerQueryParameters) // CustomerQueryParameters customerQueryParameters { //throw new Exception(" ----> Test Exception"); _logger.LogInformation(" -------> GetAllCustomers()..."); //var allCustomers = _customerRepository.GetAll().ToList(); var allCustomers = _customerRepository.GetAll(customerQueryParameters); var allCustomersDto = allCustomers.Select(x => Mapper.Map <CustomerDto>(x)); Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(new { totalCount = _customerRepository.Count() })); return(Ok(allCustomersDto)); }
public async Task <ActionResult <IEnumerable <Customer> > > GetAllCustomers( [FromQuery] CustomerQueryParameters parameters) { var customers = await _repository.GetAllAsync(parameters); var metadata = new { ((PaginatedList <Customer>)customers).ItemCount, parameters.PageSize, ((PaginatedList <Customer>)customers).PageIndex, ((PaginatedList <Customer>)customers).TotalPages, ((PaginatedList <Customer>)customers).HasNextPage, ((PaginatedList <Customer>)customers).HasPreviousPage }; Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata)); return(Ok(_mapper.Map <IEnumerable <CustomerReadDto> >(customers))); }
public async Task <IActionResult> GetAll([FromQuery] CustomerQueryParameters customerQueryParameters) { try { if (customerQueryParameters == null) { customerQueryParameters = new CustomerQueryParameters(); } logger.LogInformation("GetAll"); var list = await customerReader.ListAll(customerQueryParameters); return(Ok(new { Customers = list })); } catch (Exception ex) { logger.LogError(ex, "GetAll"); return(StatusCode(StatusCodes.Status500InternalServerError)); } }