Ejemplo n.º 1
0
        public ActionResult Create(NHiberanteDal.DTO.TestDto test, int itemid)
        {
            test.Author       = _profileService.GetByName(User.Identity.Name);
            test.CreationDate = DateTime.Now;
            test.EditDate     = DateTime.Now;

            //if (ModelState.IsValid)
            //{
            var newId = 0;

            if (test.TestType.ID == 2)
            {
                newId = _testService.AddTestToCourse(itemid, test);
            }
            else if (test.TestType.ID == 1)
            {
                newId = _testService.AddTestToLearningMaterial(itemid, test);
            }
            if (newId > 0)
            {
                return(RedirectToAction("Edit", new { id = newId }));
            }
            else
            {
                //todo log error
            }
            //}
            // bug : problem with null TestTypes in View , recreate TestTypes list before sending model to view
            return(View(test));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Method used to calculate final score
        /// </summary>
        /// <param name="test">Instance of test model with questions and answers</param>
        /// <param name="maxValue">Maximum value threshold eg with 100 ( we would had 0-100 mark )</param>
        /// <returns></returns>
        private double CalculateMark(NHiberanteDal.DTO.TestDto test, int maxValue)
        {
            var    allQuestionsWithAnswers = test.Questions.Where(q => q.Answers != null).ToList();
            double correctAnswers          = allQuestionsWithAnswers.Where(q => q.Answers.Any(a => a.IsSelected && a.Correct)).Count();

            return((correctAnswers / allQuestionsWithAnswers.Count) * maxValue);
        }
Ejemplo n.º 3
0
        public ActionResult DoTest(NHiberanteDal.DTO.TestDto testModel)
        {
            if (ModelState.IsValid)
            {
                var mark    = CalculateMark(testModel, 100);
                var profile = _profileService.GetByName(User.Identity.Name);

                profile.FinishedTests.Add(new NHiberanteDal.DTO.FinishedTestModelDto()
                {
                    DateFinished = DateTime.Now,
                    Mark         = mark,
                    TestId       = testModel.ID,
                    TestName     = testModel.Name
                });
                var courseId = _journalService.GetCourseIdForTest(testModel.ID);
                var journal  = profile.Journals.Where(j => j.Course.ID == courseId).FirstOrDefault();
                if (journal != null)
                {
                    journal.Marks.Add(new NHiberanteDal.DTO.JournalMarkModelDto
                    {
                        DateAdded = DateTime.Now,
                        Name      = testModel.Name ?? "None",
                        Value     = mark.ToString()
                    });
                }
                _profileService.UpdateProfile(profile);
                return(View("Score", mark));
            }
            return(View(testModel));
        }
Ejemplo n.º 4
0
 public ActionResult Create(int id,int typeId)
 {
     var test = new NHiberanteDal.DTO.TestDto();
     var testTypes = _testService.GetTestTypes();
     test.TestType = testTypes.Where(c => c.ID == typeId).SingleOrDefault();
     ViewBag.ItemId = id;
     return View(test);
 }
Ejemplo n.º 5
0
        public ActionResult Create(int id, int typeId)
        {
            var test      = new NHiberanteDal.DTO.TestDto();
            var testTypes = _testService.GetTestTypes();

            test.TestType  = testTypes.Where(c => c.ID == typeId).SingleOrDefault();
            ViewBag.ItemId = id;
            return(View(test));
        }
Ejemplo n.º 6
0
 public ActionResult Edit(NHiberanteDal.DTO.TestDto test)
 {
     if (ModelState.IsValid)
     {
         _testService.UpdateTest(test);
         return(RedirectToAction("Details", new { id = test.ID }));
     }
     return(View(test));
 }