예제 #1
0
        public async Task <ActionResult> ThemeAllResults(Guid themeId, int page = 1, int pageSize = 10)
        {
            var results = await _resultAdminService.GetSubjectThemeResultsAsync(themeId, page, pageSize);

            var theme = await _themeAdminService.GetThemeByIdAsync(themeId);

            List <Breadcrumb> breadcrumb = new List <Breadcrumb>()
            {
                new Breadcrumb("Home", "Index", "Home", new { Area = "" }),
                new Breadcrumb("Subjects", "Index", "Subject", new { Area = "Admin" }),
                new Breadcrumb("Subject themes", "Index", "Theme", new { Area = "Admin", subjectId = theme.SubjectId }),
                new Breadcrumb("Results of the theme")
            };

            var viewModel = new SubjectThemeResultViewModel
            {
                ThemeId    = themeId,
                PageInfo   = results,
                Results    = results.Results,
                Breadcrumb = breadcrumb
            };

            ViewBag.Title       = $"Results of the theme \"{theme.Title}\"";
            ViewBag.SecondTitle = "All groups";
            return(View(viewModel));
        }
예제 #2
0
        public async Task <ActionResult> Solve(Guid themeId, int questionNumber = 1)
        {
            var theme = await _themeAdminService.GetThemeByIdAsync(themeId);

            if (theme.QuestionsCount == 0)
            {
                Session["Token"]       = null;
                Session["TokenExpire"] = null;
                Session["Answers"]     = null;
                return(RedirectToAction("Index", "Theme", new { subjectId = theme.SubjectId }));
            }

            var sessionToken       = Session["Token"];
            var sessionTokenExpire = (DateTime)Session["TokenExpiration"];

            if (sessionToken == null)
            {
                TempData["invalidToken"] = "You have an invalid token. Please try to run test again.";
                return(RedirectToAction("AutoResult", "Result", new { themeId = theme.Id }));
            }

            if (sessionTokenExpire < DateTime.UtcNow)
            {
                return(RedirectToAction("AutoResult", "Result", new { themeId = theme.Id }));
            }

            var sessionModel = (SessionModel)Session["Answers"];

            var question = (await _questionAdminService.GetAllQuestionsByThemeIdAsync(themeId))
                           .Skip(questionNumber - 1)
                           .Take(1)
                           .Select(x => new QuestionViewModel
            {
                TotalQuestionsCount = theme.QuestionsCount,
                QuestionNumber      = questionNumber,
                QuestionId          = x.Id,
                Image      = x.ImageUrl,
                Title      = x.Title,
                ThemeId    = x.ThemeId,
                ThemeTitle = x.ThemeTitle,
                Options    = x.Answers.Select(y => new ChoiceModel
                {
                    AnswerId        = y.Id,
                    Title           = y.Title,
                    IsCorrectAnswer = sessionModel.Answers.Any(z => z.SelectedAnswerId == y.Id)
                })
                             .ToList()
            })
                           .FirstOrDefault();

            question.Options.Shuffle();

            return(View(question));
        }
예제 #3
0
        public async Task <ActionResult> Index(Guid themeId, int page = 1, int pageSize = 10)
        {
            var questions = await _questionAdminService.GetAllQuestionsByThemeIdAsync(page, pageSize, themeId);

            var theme = await _themeAdminService.GetThemeByIdAsync(themeId);

            List <Breadcrumb> breadcrumb = new List <Breadcrumb>()
            {
                new Breadcrumb("Home", "Index", "Home", new { Area = "" }),
                new Breadcrumb("Subjects", "Index", "Subject", new { Area = "Admin" }),
                new Breadcrumb("Subject themes", "Index", "Theme", new { Area = "Admin", subjectId = theme.SubjectId }),
                new Breadcrumb("Questions of the theme")
            };

            QuestionIndexViewModel questionIndexViewModel = new QuestionIndexViewModel
            {
                PageInfo   = questions,
                ThemeId    = themeId,
                Questions  = questions.Results,
                Breadcrumb = breadcrumb
            };

            ViewBag.Title           = $"List of questions to the theme \"{theme.Title}\" of the subject \"{theme.SubjectTitle}\"";
            ViewBag.HeadFirstTitle  = $"List of questions to the theme \"{theme.Title}\"";
            ViewBag.HeadSecondTitle = $"Subject \"{theme.SubjectTitle}\"";
            return(View(questionIndexViewModel));
        }
예제 #4
0
        public async Task <ActionResult> Edit(Guid id)
        {
            var theme = await _themeAdminService.GetThemeByIdAsync(id);

            EditThemeRequest editThemeRequest = theme.ToEditThemeRequest();

            ViewBag.Title = $"Edit theme \"{theme.Title}\"";
            return(View(editThemeRequest));
        }
예제 #5
0
        public async Task <ActionResult> CreateSession(Guid subjectId, Guid themeId)
        {
            var userId = GetCurrentUserId();
            var theme  = await _themeAdminService.GetThemeByIdAsync(themeId);

            var token           = Session["Token"];
            var tokenExpiration = Session["TokenExpiration"];

            if (token == null || tokenExpiration == null)
            {
                Session["Token"]           = userId;
                Session["TokenExpiration"] = DateTime.UtcNow.AddMinutes(theme.TimeLine);
                Session["Answers"]         = new SessionModel
                {
                    Answers = new List <AnswerViewModel>()
                };
            }

            return(RedirectToAction("Solve", "Theme", new { subjectId, themeId }));
        }