Exemplo n.º 1
0
        /*public override async Task<List<BriefPollBaseResponse>> GetAllAvailableForUserAsync(string userId)
         * {
         *  var student = await Users.Find(user => user.UserId == userId).SingleAsync();
         *  var query = PollBaseCollection.AsQueryable()
         *      .Where(quiz=>quiz.EligibleGroupsNames.Any(group=>group==student.GroupName)&&quiz.StartDate<DateTime.Now&&quiz.ExpireDate>DateTime.Now)
         *      .Join(Users.AsQueryable(), quiz => quiz.CreatorUserId, creatorUserModel => creatorUserModel.UserId,
         *          (quiz, creatorUserModel) => new BriefQuizResponse
         *          {
         *              Id = quiz.Id,
         *              Title = quiz.Title,
         *              StartDate = quiz.StartDate,
         *              ExpireDate = quiz.ExpireDate,
         *              EligibleGroups = quiz.EligibleGroupsNames,
         *              FirstName = creatorUserModel.FirstName,
         *              LastName = creatorUserModel.LastName,
         *              CreatorUserId = quiz.CreatorUserId,
         *              IsAllowedToReanswer=quiz.IsAllowedToReanswer,
         *              AreStatsPublic=quiz.AreStatsPublic,
         *              //MaxReanswerCount = quiz.MaxReanswerCount,
         *          });
         *  var list=await query.ToListAsync();
         *  var resultList = new List<BriefPollBaseResponse>();
         *  foreach (var response in list)
         *  {
         *      var answersUnit=AnswersUnits.AsQueryable().SingleOrDefault(unit => unit.CreatorUserId == userId && unit.PollBaseId == response.Id);
         *      if (answersUnit != null)
         *      {
         *          if ((bool) !response.IsAllowedToReanswer)
         *              continue;
         *          //if (answersUnit.CurrentReanswerCount >= response.MaxReanswerCount)
         *          //    continue;
         *          //response.CurrentReanswerCount = answersUnit.CurrentReanswerCount;
         *      }
         *
         *      response.HasAnswer = answersUnit!=null;
         *      resultList.Add(response);
         *  }
         *  return resultList;
         * }*/

        public override async Task AddAsync(Quiz quiz)
        {
            quiz.Id               = null;
            quiz.CreationDate     = DateTime.Now;
            quiz.MaxAssessment    = quiz.Questions.Sum(question => question.MaxAssessment);
            quiz.MaxReanswerCount = int.MaxValue;

            foreach (var question in quiz.Questions)
            {
                if (Types.QuizAnswerTypes[question.AnswerType] != QuizAnswerType.TextInput)
                {
                    question.CorrectAnswerOptions = question.CorrectAnswerOptions.OrderBy(i => i).ToList();
                }
            }
            await PollBaseCollection.InsertOneAsync(quiz);
        }
Exemplo n.º 2
0
        public override async Task UpdateAsync(Quiz newQuiz)
        {
            var oldQuiz = await GetByIdAsync(newQuiz.Id);

            newQuiz.Id            = oldQuiz.Id;
            newQuiz.CreationDate  = oldQuiz.CreationDate;
            newQuiz.CreatorUserId = oldQuiz.CreatorUserId;

            newQuiz.MaxAssessment = newQuiz.Questions.Sum(question => question.MaxAssessment);
            foreach (var question in newQuiz.Questions)
            {
                if (Types.QuizAnswerTypes[question.AnswerType] != QuizAnswerType.TextInput)
                {
                    question.CorrectAnswerOptions = question.CorrectAnswerOptions.OrderBy(i => i).ToList();
                }
            }

            await PollBaseCollection.DeleteOneAsync(poll => poll.Id == newQuiz.Id);

            await PollBaseCollection.InsertOneAsync(newQuiz);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Returns Quiz without <see cref="QuizQuestion.CorrectAnswerOptions"/>
 /// </summary>
 public override async Task <Quiz> GetByIdAsync(string id)
 {
     return(await PollBaseCollection.Find(quiz => quiz.Id == id).Project(Builders <Quiz> .Projection.Expression(quiz => Quiz.ExcludeCorrectAnswers(quiz))).FirstOrDefaultAsync());
 }
Exemplo n.º 4
0
 public async Task <Quiz> GetQuizCorrectAnswerOptionsAsync(string id)
 {
     return(await PollBaseCollection.Find(quiz => quiz.Id == id).Project(Builders <Quiz> .Projection.Expression(quiz => Quiz.CorrectAnswersOnly(quiz))).FirstOrDefaultAsync());
 }