public async Task <IEnumerable <AttemptDto> > GetTestResultsForStudentAsync(UserDto student, string topicId) { await _userValidator.ValidateAsync(student); return(_attemptService.GetEntitiesByPrincipalId(student.Id) .Where(a => a.TopicId.Equals(topicId)).ToEnumerable()); }
public async Task <TestModel> GenerateTestForTopicAsync(UserDto student, string topicId) { await _userValidator.ValidateAsync(student); var topic = await _topicService.GetByIdAsync(topicId); if (topic is null) { throw new TestCreationException("There are no topic with this id"); } var attemptsCount = (await GetTestResultsForStudentAsync(student, topicId)).Count(); if (attemptsCount >= topic.MaxAttemptCount) { throw new TestCreationException("You have no available attempts"); } var topicQuestions = await _questionService.GetEntitiesByPrincipalId(topicId).ToListAsync(); if (topicQuestions.Count < topic.QuestionsPerAttempt) { throw new TestCreationException("Topic don't have enough questions for test"); } List <QuestionDto> testQuestions = new(); while (testQuestions.Count < topic.QuestionsPerAttempt) { topicQuestions.Shuffle(); var question = topicQuestions.First(); if (testQuestions.Contains(question)) { continue; } var answers = await _answerService.GetEntitiesByPrincipalId(question.Id).ToListAsync(); answers.ForEach(a => a.IsCorrect = false); answers.Shuffle(); question.Answers = answers; testQuestions.Add(question); } TestModel test = new (){ Student = student, Topic = topic, Questions = testQuestions }; return(test); }
public async Task <ActionResult <IEnumerable <SubjectDto> > > GetByLecturerId(string id) { return(await _subjectService.GetEntitiesByPrincipalId(id).ToListAsync()); }
public async Task <ActionResult <IEnumerable <QuestionResultDto> > > GetByQuestionId(string id) { return(await _questionResultService.GetEntitiesByPrincipalId(id).ToListAsync()); }
public async Task <ActionResult <IEnumerable <AttemptDto> > > GetByStudentId(string id) { return(await _attemptService.GetEntitiesByPrincipalId(id).ToListAsync()); }
public async Task <ActionResult <IEnumerable <TopicDto> > > GetBySubjectId(string id) { return(await _topicService.GetEntitiesByPrincipalId(id).ToListAsync()); }