Esempio n. 1
0
        public async Task <ActionResult <AddressViewModel> > Get(int id, bool includeConsultant = false)
        {
            try
            {
                Address result = await repository.GetAddressAsync(id);

                if (result == null)
                {
                    return(NotFound());
                }
                if (includeConsultant)
                {
                    AddressViewModel address          = mapper.Map <AddressViewModel>(result);
                    Consultant       resultConsultant = await repository.GetConsultantAsync(result.ConsultantId, false);

                    //TODO When repo is called from here it always returns with addresses
                    resultConsultant.Addresses = null;
                    address.consultant         = mapper.Map <ConsultantViewModel>(resultConsultant);;
                    return(address);
                }
                else
                {
                    return(mapper.Map <AddressViewModel>(result));
                }
            }
            catch (Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Error in database"));
            }
        }