public IEnumerable <QuestionDto> SearchQuestions([FromBody] SearchQuestionsQuery query) { IEnumerable <QuestionDto> results = null; try { QuestionsRepository repository = new QuestionsRepository(_appDbContext); var questionDtos = repository.GetQuestionsByQuery(query, _clientData); results = repository.IncludeSkills(questionDtos); } catch (Exception e) { _log.LogError(e, "Error searching questions"); } return(results); }
public IEnumerable <QuestionDto> GetQuestionsByQuery(SearchQuestionsQuery query, AppUser user) { IEnumerable <Question> questions = _entities.Where(q => q.AccessModifier == (int)AccessModifier.Public && (query.Title != null && query.Title.Length > 0 ? q.Title.Contains(query.Title) : true) && (query.MinRank != null ? q.Rank >= query.MinRank : true) && (query.MaxRank != null ? q.Rank <= query.MaxRank : true)) .Include(q => q.CandidateQuestions); if (query.SkillIds != null && query.SkillIds.Count > 0) { questions = questions.Where(q => (Utils.ConvertStringIdsToList(q.TestedSkills)). Join(query.SkillIds, qSid => qSid, sId => sId, (qSid, sId) => sId).Count() > 0); } var questionDtos = Mapper.Map <IEnumerable <Question>, IEnumerable <QuestionDto> >(questions); ComputeQuestionsState(user, questions, questionDtos); return(questionDtos); }