Ejemplo n.º 1
0
        public async Task <ActionResult <CustomerDto> > GetCustomersByID(int id)
        {
            try
            {
                _orm.OpenConn();
                var customerDB = await _orm.GetCustomerById(id);

                var customer = _mapper.Map <CustomerDto>(customerDB);

                if (customerDB == null)
                {
                    return(NotFound());
                }
                //Map customer addresses to customer
                var addressListDB = await _orm.GetCustomerAddressesByCustomerID(id);

                var addressList = _mapper.Map <List <Customer_AddressesDto> >(addressListDB);


                customer.Addresses = addressList;

                await _orm.CloseConn();

                return(Ok(customer));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.GetType().Name + ", " + e.Message));
            }
        }