Пример #1
0
        public ActionResult StartTest(int id)
        {
            var test = this.levelTestForSolvingService.GetById(id);

            this.ControllerContext.HttpContext.Response.Cookies.Add(new HttpCookie("levelId")
            {
                Value = test.CourseLevelId.ToString()
            });
            var student = this.studentService.GetStudentByAppUserId(this.User.Identity.GetUserId());

            if (test.StudentId == student.Id)
            {
                var sTest =
                    new SolvedAutomaticTest
                {
                    StudentId       = student.Id,
                    StartTime       = DateTime.Now,
                    CourseId        = test.CourseLevel.CourseId,
                    TestId          = test.CourseLevel.AutomaticTestId.Value,
                    SolvedQuestions = OtherFunctions
                                      .Shuffle <CloseQuestion>(test.CourseLevel.AutomaticTest.CloseQuestions.ToList())
                                      .ToList()
                                      .ConvertAll(x => new SolvedCloseQuestion
                    {
                        CloseQuestionId = x.Id
                    }),
                    Course = new Course {
                        Name = test.CourseLevel.Course.Name
                    }
                };

                HttpCookie cookie = new HttpCookie("testForLevel");
                cookie.Value = JsonConvert.SerializeObject(sTest);
                this.ControllerContext.HttpContext.Response.Cookies.Add(cookie);

                var newTest = new StartAutoTestViewModel
                {
                    Id            = test.Id,
                    TeacherName   = test.CourseLevel.AutomaticTest.Teacher.ApplicationUser.FirstName + " " + test.CourseLevel.AutomaticTest.Teacher.ApplicationUser.LastName,
                    Title         = test.CourseLevel.AutomaticTest.Title,
                    Time          = test.CourseLevel.AutomaticTest.Time,
                    QuestionCount = test.CourseLevel.AutomaticTest.CloseQuestions.Count
                };
                this.levelTestForSolvingService.Remove(id);
                return(View(newTest));
            }

            return(Redirect("/"));
        }
Пример #2
0
        public ActionResult StartTest(int id)
        {
            var test    = this.autoTestForSolvingService.GetById(id);
            var student = this.studentService.GetStudentByAppUserId(this.User.Identity.GetUserId());

            if (test.StudentId == student.Id)
            {
                var sId = this.solvedAutomaticTestService.Add(
                    new SolvedAutomaticTest
                {
                    StudentId       = student.Id,
                    StartTime       = DateTime.Now,
                    CourseId        = test.CourseId,
                    TestId          = test.TestId.Value,
                    SolvedQuestions = OtherFunctions
                                      .Shuffle <CloseQuestion>(test.Test.CloseQuestions.ToList())
                                      .ToList()
                                      .ConvertAll(x => new SolvedCloseQuestion
                    {
                        CloseQuestionId = x.Id
                    })
                });
                var newTest = new StartAutoTestViewModel
                {
                    Id            = test.Id,
                    TeacherName   = test.Test.Teacher.ApplicationUser.FirstName + " " + test.Test.Teacher.ApplicationUser.LastName,
                    Title         = test.Test.Title,
                    Time          = test.Test.Time,
                    SolvedTestId  = sId,
                    QuestionCount = test.Test.CloseQuestions.Count
                };
                this.studentService.RemoveAutoTestToSolve(student.Id, id, test.CourseId);
                return(View(newTest));
            }
            return(Redirect("/"));
        }