public virtual async Task <Question> ValidateAsync(Question question) { if (question == null) { throw new ArgumentNullException(nameof(question)); } var user = await Context.GetCurrentUserAsync(); var model = await GetQuestionModelAsync(question.Id); var specification = new QuestionsForStudents() & new QuestionsByTestId(question.TestId) & new QuestionsByStudentId(user.Id, false); if (specification.IsSatisfiedBy(model) == false) { throw ExceptionHelper.CreatePublicException("Указанный вопрос недоступен или уже пройден."); } var hash = await HashComputer.ComputeForQuestionAsync(model); if (string.Equals(hash, question.Hash, StringComparison.InvariantCulture) == false) { throw ExceptionHelper.CreatePublicException("Указанный вопрос недоступен."); } return(Mapper .Map <Question>(model) .SetRight(true)); }
public async Task <PagedData <Question> > GetQuestionsAsync(FilterQuestion filter) { var user = await Context.GetCurrentUserAsync(); if (user.IsAdmin()) { var specification = new QuestionsByTestId(filter.TestId) & new QuestionsByThemeId(filter.ThemeId); var(count, questions) = await _repositoryQuestion.FindPaginatedAsync(specification, filter); return(new PagedData <Question>(Mapper.Map <List <Question> >(questions), count)); } if (user.IsLecturer()) { var specification = new QuestionsByTestId(filter.TestId) & new QuestionsByThemeId(filter.ThemeId) & new QuestionsByLecturerId(user.Id); var(count, questions) = await _repositoryQuestion.FindPaginatedAsync(specification, filter); return(new PagedData <Question>(Mapper.Map <List <Question> >(questions), count)); } if (user.IsStudent()) { var specification = new QuestionsForStudents() & new QuestionsByTestId(filter.TestId) & new QuestionsByThemeId(filter.ThemeId) & new QuestionsByStudentId(user.Id, filter.Passed); var(count, questions) = await _repositoryQuestion.FindPaginatedAsync(specification, filter); return(new PagedData <Question>(Mapper.Map <List <Question> >(questions), count)); } throw ExceptionHelper.NoAccess(); }