public async Task <QuestionGetModel> GetQuestionWithUserAndTagsAsync(QuestionFindModel questionFindModel) { var question = await _questionRepository.GetQuestionWithUserAndTagsAsync(questionFindModel); if (question != null) { question.VotesSum = await _voteService.GetVotesSumAsync(questionFindModel.Id, VoteTargetEnum.Question); } return(question); }
public async Task <QuestionGetModel> GetQuestionWithUserAndTagsAsync(QuestionFindModel questionFindModel) { var q = await _context .Questions .Where(q => q.Id == questionFindModel.Id) .Include(q => q.User) .ThenInclude(u => u.Roles) .Include(q => q.QuestionTags) .ThenInclude(qt => qt.Tag) .Include(q => q.Votes.Where(v => v.UserId == questionFindModel.UserId)) .AsNoTracking() // Below line commented out because it was messing up // votes - all votes would be included no matter // the user id value (or lack of). //.ProjectTo<QuestionGetModel>(_mapper.ConfigurationProvider) .SingleOrDefaultAsync(); return(_mapper.Map <QuestionGetModel>(q)); }