Example #1
0
        public async Task <IList <Questao> > GerarTeste(int numeroDeQuestoes, string materia, QuestoesServiceContext context)
        {
            IQuestoesRepository questoesRepository = new QuestoesRepository(context);

            IEnumerable <Questao> questoesFromDb = await questoesRepository.GetListByMateria(materia);

            IList <int> numerosSorteados = new List <int>();

            for (int i = 0; i < numeroDeQuestoes; i++)
            {
                Random  random       = new Random();
                int     numeroRandom = random.Next(questoesFromDb.Count());
                Boolean flag         = false;
                if (!numerosSorteados.Contains(numeroRandom))
                {
                    numerosSorteados.Add(numeroRandom);
                    //flag =
                }
                else
                {
                    numeroRandom = random.Next(questoesFromDb.Count());
                }
                Questoes.Add(questoesFromDb.ElementAt(numeroRandom));
            }

            return(Questoes);
        }
Example #2
0
 public QuestoesRepository(QuestoesServiceContext context)
 {
     _context = context;
 }