public ActionResult <IEnumerable <CustomerDto> > GetCustomers([FromQuery] string lastName = "")
 {
     if (lastName == "")
     {
         return(CustomerDto.ToCustomerDto(_context.Customers.ToList()));
     }
     return(CustomerDto.ToCustomerDto(_context.Customers.Where(c => c.LastName.Contains(lastName)).ToList()));
 }
        public async Task <ActionResult <CustomerDto> > PostCustomer(CustomerDto customer)
        {
            Customer c = CustomerDto.FromCustomerDto(customer);

            _context.Customers.Add(c);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCustomer", new { id = customer.Id }, CustomerDto.ToCustomerDto(c)));
        }
        public async Task <ActionResult <CustomerDto> > GetCustomer(int id)
        {
            var customer = await _context.Customers.FindAsync(id);

            if (customer == null)
            {
                return(NotFound());
            }

            return(CustomerDto.ToCustomerDto(customer));
        }
        public async Task <ActionResult <CustomerDto> > DeleteCustomer(int id)
        {
            var customer = await _context.Customers.FindAsync(id);

            if (customer == null)
            {
                return(NotFound());
            }

            _context.Customers.Remove(customer);
            await _context.SaveChangesAsync();

            return(CustomerDto.ToCustomerDto(customer));
        }