Esempio n. 1
0
        public async Task <bool> FinishExam(ExamApproacheDTO exam)
        {
            var login   = httpContext.HttpContext.User.Identity.Name;
            var model   = new List <ExamApproacheResult>();
            var answers = await AnswersRepo.GetListAsync();

            int answerCount = 0;

            exam.Questions.ForEach(q => q.Answers.ForEach(a =>
            {
                answerCount++;
                model.Add(new ExamApproacheResult
                {
                    Login      = login,
                    ExamId     = exam.ExamId,
                    QuestionId = q.Id,
                    Points     = answers.FirstOrDefault(aa => aa.Id == a.Id)?.Points ?? 0m,
                    AnswerId   = a.Id,
                    Checked    = a.Checked
                });
            }));
            var result = await ExamApproachesRepo.AddResultsAsync(model);

            return(result == answerCount);
        }
        public async virtual Task <JsonResult> FinishExam(ExamApproacheDTO exam)
        {
            var result = await uow.FinishExam(exam);

            if (result)
            {
                return(Json(new object[] { true, localizer["The exam has ended"] }));
            }
            return(Json(new object[] { false, localizer["Error while ending exam"] }));
        }