public IActionResult GetAllCustomers(CustomerQueryParametrs customerQueryParametrs)
        {
            _logger.LogInformation("------> GetAllCustomers()");

            var allCustomersDto = from customer in _customerRepository.GetAll(customerQueryParametrs).ToList()
                                  select Mapper.Map <CustomerDto>(customer);

            Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(new { totalCount = _customerRepository.CountAsync().Result }));
            return(Ok(allCustomersDto));
        }
Example #2
0
        public IQueryable <Customer> GetAll(CustomerQueryParametrs customerQueryParametrs)
        {
            IQueryable <Customer> allCustomers = _context.Customers.OrderBy(c => c.Firstname);

            if (customerQueryParametrs.HasQuery)
            {
                allCustomers = allCustomers.Where(c =>
                                                  (String.Equals(c.Firstname, customerQueryParametrs.Query, StringComparison.InvariantCultureIgnoreCase)) ||
                                                  (String.Equals(c.Firstname, customerQueryParametrs.Query, StringComparison.InvariantCultureIgnoreCase)));
            }

            return(allCustomers
                   .Skip(customerQueryParametrs.PageCount * (customerQueryParametrs.Page - 1))
                   .Take(customerQueryParametrs.PageCount));
        }