Ejemplo n.º 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("/"));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get points for test
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public double GetPointForTest(SolvedAutomaticTest model)
        {
            double points = 0;
            bool   flag   = true;

            foreach (var item in model.SolvedQuestions)
            {
                foreach (var item2 in this.context.CloseQuestions.Find(item.CloseQuestionId).Answers.Where(x => x.Correct == true))
                {
                    if (!item.SelectedAnswers.Select(x => x.Id).ToList().Contains(item2.Id))
                    {
                        flag = false;
                    }
                }
                if (flag)
                {
                    points += this.context.CloseQuestions.Find(item.CloseQuestionId).Points;
                }
                flag = true;
            }
            return(points);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Add solved automatic test
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Add(SolvedAutomaticTest model)
 {
     this.context.SolvedAutomaticTests.Add(model);
     this.context.SaveChanges();
     return(model.Id);
 }