예제 #1
0
        public async Task <ActionResult <ConsultantViewModel> > Get(int id, bool includeAddress = false, bool includeCompetences = false)
        {
            try
            {
                Consultant result = await repository.GetConsultantAsync(id, includeAddress);

                if (result == null)
                {
                    return(NotFound());
                }
                if (includeCompetences)
                {
                    ConsultantViewModel consultant  = mapper.Map <ConsultantViewModel>(result);
                    Competence[]        competences = await repository.GetAllCompetencesForConsultantAsync(consultant.ConsultantId);

                    if (competences != null)
                    {
                        consultant.Competences = mapper.Map <CompetenceViewModel[]>(competences);
                    }
                    return(consultant);
                }
                return(mapper.Map <ConsultantViewModel>(result));
            }
            catch (Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Error in database"));
            }
        }
예제 #2
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"));
            }
        }