Exemplo n.º 1
0
        public async Task <ActionResult> TakeQuiz(Guid?Id)
        {
            if (Id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Evaluation evaluation = await Db.Evaluations.Where(x => x.Id == Id).FirstOrDefaultAsync <Evaluation>();

            if (evaluation == null)
            {
                return(HttpNotFound());
            }
            EvaluationBL evaluationBL = new EvaluationBL();

            if (evaluationBL.UserCanBeEvaluated(evaluation, CurrentUser.Id))
            {
                DateTime dateTime = evaluation.EvaluationUsers.Where(x => x.UserId == CurrentUser.Id).FirstOrDefault().TakenDate;
                dateTime = dateTime.ToUniversalTime();
                TimeZoneInfo estTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Venezuela Standard Time");
                dateTime = TimeZoneInfo.ConvertTimeFromUtc(dateTime, estTimeZone);
                ViewBag.InitialDateTime = DateTime.UtcNow;
                TimeZoneInfo estTimeZone2 = TimeZoneInfo.FindSystemTimeZoneById("Venezuela Standard Time");
                ViewBag.InitialDateTime = TimeZoneInfo.ConvertTimeFromUtc(ViewBag.InitialDateTime, estTimeZone2);
                await Db.SaveChangesAsync();

                return(View("TakeQuiz", evaluationBL.GetQuiz(evaluation, dateTime)));
            }
            await Db.SaveChangesAsync();

            Flash.Error("Error", "Esta evaluación ya ha sido presentada o Ha ocurrido un error al intentar presentar la evaluación");
            return(RedirectToAction("Evaluations"));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> TakeQuiz(QuizViewModel quiz)
        {
            Evaluation evaluation = await Db.Evaluations.Where(x => x.Id == quiz.Id).FirstOrDefaultAsync();

            if (evaluation == null)
            {
                return(HttpNotFound());
            }
            EvaluationBL evaluationBL = new EvaluationBL();

            try
            {
                List <Answer> answers = null;
                if (quiz.RunoutTime)
                {
                    quiz.Questions = quiz.Questions.Where(x => x.Options != null).ToList();
                    answers        = quiz.Questions.Select(x => new Answer {
                        QuestionOptionId = x.Options.SelectedAnswer
                    }).ToList();
                }

                if (ModelState.IsValid)
                {
                    if (evaluationBL.UserCanBeEvaluated(evaluation, CurrentUser.Id, answers))
                    {
                        evaluationBL.TakeQuiz(evaluation, quiz, CurrentUser.Id);
                        await Db.SaveChangesAsync();

                        Flash.Success("Ok", "El Quiz ha sido presentado exitosamente");
                        QuizViewModel reviewedQuiz = evaluationBL.ReviewQuiz(evaluation, CurrentUser.Id);
                        return(View("ReviewQuiz", reviewedQuiz));
                    }
                    else
                    {
                        await Db.SaveChangesAsync();

                        Flash.Error("Error", "Ha caducado el tiempo para presentar el quiz");
                        return(RedirectToAction("Evaluations"));
                    }
                }
                else
                {
                    Flash.Error("Error", "Ha ocurrido un error al intentar presentar la evaluación");
                    return(RedirectToAction("Evaluations"));
                }
            }
            catch (Exception)
            {
                Flash.Error("Error", "Ha ocurrido un error al intentar presentar la evaluación");
                return(RedirectToAction("Evaluations"));
            }
        }