コード例 #1
0
ファイル: ExamAdd.cs プロジェクト: Zututukulipa/blazorTest2
        public async Task <bool> GenerateAnswers()
        {
            var users = await _users.GetUsers();

            var students  = users.FindAll(s => s.RoleId == 3).ToList();
            var questions = await _service.GetQuestions();

            var allAnswers = await _service.GetAnswers();

            return(await _service.InsertAnswers((from student in students
                                                 from question in questions
                                                 let questionAnswers = allAnswers.FindAll(q => q.QuestionId == question.QuestionId).ToList()
                                                                       where questionAnswers.Count > 0
                                                                       let pickedAnswer = questionAnswers[_random.Next(questionAnswers.Count)]
                                                                                          select new UserAnswers {
                AnswerId = pickedAnswer.AnswerId, UserId = student.UserId
            }).ToList()));
        }