Пример #1
0
        public async Task <ActionResult <ConsultantViewModel[]> > Get(bool includeAddresses = false, bool includeCompetences = false)
        {
            try
            {
                var results = await repository.GetAllConsultantsAsync(includeAddresses);

                if (includeCompetences)
                {
                    ConsultantViewModel[] consultants = mapper.Map <ConsultantViewModel[]>(results);
                    foreach (ConsultantViewModel consultant in consultants)
                    {
                        Competence[] competences = await repository.GetAllCompetencesForConsultantAsync(consultant.ConsultantId);

                        if (competences == null)
                        {
                            continue;
                        }
                        consultant.Competences = mapper.Map <CompetenceViewModel[]>(competences);
                    }
                    return(consultants);
                }
                return(mapper.Map <ConsultantViewModel[]>(results));
            }
            catch (Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Error in database"));
            }
        }
Пример #2
0
        public async Task <ActionResult <CompetenceViewModel[]> > Get(int id)
        {
            try
            {
                var results = await repository.GetAllCompetencesForConsultantAsync(id);

                return(mapper.Map <CompetenceViewModel[]>(results));
            }
            catch (Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Error in database"));
            }
        }