public ActionResult CheckTest(int id)
        {
            if (BelongToCurrentUser(id, this.User.Identity.GetUserId()))
            {
                var test      = this.solvedManualTestService.GetById(id);
                var viewModel = new SolvedManualTestCheckViewModel
                {
                    Id                   = test.Id,
                    Student              = test.Student,
                    MaxPoints            = this.manualTestService.MaxPoints(test.Test.Id),
                    SolvedCloseQuestions = test.SolvedCloseQuestions.ToList(),
                    SolvedOpenQuestions  = test.SolvedOpenQuestions.ToList(),
                    TestTitle            = test.Test.Title,
                    Rate                 = test.Test.Rate
                };

                foreach (var item in viewModel.SolvedOpenQuestions)
                {
                    item.OpenQuestion.Images = this.cloudinaryService.AddPathToQuestionImageName(item.OpenQuestion.Images);
                }

                foreach (var item in viewModel.SolvedCloseQuestions)
                {
                    item.CloseQuestion.Images = this.cloudinaryService.AddPathToQuestionImageName(item.CloseQuestion.Images);
                    foreach (var an in item.CloseQuestion.Answers)
                    {
                        an.Images = this.cloudinaryService.AddPathToQuestionImageName(an.Images);
                    }
                }
                return(View(viewModel));
            }
            return(Redirect("/CheckManualTest/Tests"));
        }
Beispiel #2
0
        public ActionResult CheckTest(SolvedManualTestCheckViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (model.SolvedOpenQuestions != null)
            {
                foreach (var item in model.SolvedOpenQuestions)
                {
                    this.solvedOpenQuestionService.SetPoints(item.Id, item.Points);
                }
            }
            var    solvedTest = this.solvedManualTestForLevelService.GetById(model.Id);
            double yourPoints = this.solvedManualTestForLevelService.GetPointForTest(solvedTest.Id);
            double allPoints  = this.manualTestService.MaxPoints(solvedTest.TestId);
            var    testRate   = solvedTest.Test.Rate;
            double mark       = this.testService.CalculateMark(allPoints, yourPoints, testRate);
            var    level      = this.courseLevelService.GetById(model.CourseLevelId);

            this.markService.Add(new Mark
            {
                CourseId    = solvedTest.CourseLevel.CourseId,
                Date        = DateTime.Now,
                MarkNum     = mark,
                StudentId   = model.Student.Id,
                Description = "^c999d7d108874d94abbc95ffb2118a99^ " + level.Name
            });
            if (mark >= 3.00)
            {
                this.notificationService.Add(new Notification
                {
                    UserId  = model.Student.ApplicationUserId,
                    Content = "^ca779cae33834c0fbd4491b45e066343^" + level.Name + "(" + solvedTest.CourseLevel.Course.Name + "-" + mark + ")",
                    Link    = "/Mark/Marks"
                });
                this.courseLevelService.AddCourseLevelToStudent(level.Id, model.Student.Id);
            }
            else
            {
                this.notificationService.Add(new Notification
                {
                    UserId  = model.Student.ApplicationUserId,
                    Content = "^d482501cd64540118d525ea74747a692^(" + solvedTest.CourseLevel.Course.Name + " - " + mark + ")",
                    Link    = "/Mark/Marks"
                });
            }
            Response.Cookies.Clear();
            this.solvedManualTestForLevelService.Remove(solvedTest.Id);
            return(Redirect("/CheckManualTestForLevel/Tests"));
        }
        public ActionResult CheckTest(SolvedManualTestCheckViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (model.SolvedOpenQuestions != null)
            {
                foreach (var item in model.SolvedOpenQuestions)
                {
                    this.solvedOpenQuestionService.SetPoints(item.Id, item.Points);
                }
            }
            var    solvedTest = this.solvedManualTestService.GetById(model.Id);
            double yourPoints = this.solvedManualTestService.GetPointForTest(solvedTest.Id);
            double allPoints  = this.manualTestService.MaxPoints(solvedTest.TestId);
            var    testRate   = solvedTest.Test.Rate;
            double mark       = this.testService.CalculateMark(allPoints, yourPoints, testRate);

            this.solvedManualTestService.SetMark(solvedTest.Id, mark);
            this.markService.Add(new Mark
            {
                CourseId  = solvedTest.CourseId.Value,
                Date      = DateTime.Now,
                MarkNum   = mark,
                StudentId = model.Student.Id
            });
            this.notificationService.Add(new Notification
            {
                UserId  = model.Student.ApplicationUserId,
                Content = "^d482501cd64540118d525ea74747a692^(" + solvedTest.Course.Name + " - " + mark + ")",
                Link    = "/Mark/Marks"
            });
            this.solvedManualTestService.SetChecked(solvedTest.Id);
            return(Redirect("/CheckManualTest/Tests"));
        }