public List <AnswerViewModel> GetAnswersByQuestionId(int qid) { List <Answer> a = ar.GetAnswersByQuestionId(qid); var config = new MapperConfiguration(cfg => { cfg.CreateMap <Answer, AnswerViewModel>(); cfg.IgnoreUnmapped(); }); IMapper mapper = config.CreateMapper(); List <AnswerViewModel> avm = mapper.Map <List <Answer>, List <AnswerViewModel> >(a); return(avm); }
public async Task <List <AnswerDto> > Handle(GetAnswersByQuestionIdQuery request, CancellationToken cancellationToken) { bool questionExists = await _questionsRepository.QuestionExists(request.QuestionId); if (!questionExists) { throw new InvalidQuestionException(); } var answers = await _answersRepository .GetAnswersByQuestionId(request.QuestionId); var list = new List <AnswerDto>(); foreach (var ans in answers) { list.Add(AnswerDto.FromEntity(ans)); } return(list); }