Example #1
0
        public ActionResult CreateTest()
        {
            GetCurrentUserInViewBag();

            Questions          psychTest = new Questions();
            PsychTestViewModel pvm       = new PsychTestViewModel();

            var questionTag = GetAllQuestionTags();

            pvm.QuestionTags = GetSelectListItems(questionTag);

            if (psychTest.QuestionTag != null)
            {
                pvm.QuestionTag = psychTest.QuestionTag.Trim();
            }

            pvm.QuestionID = psychTest.QuestionID;
            pvm.Question   = psychTest.Question;

            if (psychTest.IsQuestionPositive != null)
            {
                pvm.IsQuestionPositive = (bool)psychTest.IsQuestionPositive;
            }



            return(View(pvm));
        }
Example #2
0
        public ActionResult Student()
        {
            GetCurrentUserInViewBag();

            var currentUserId = User.Identity.GetUserId();

            List <PsychTestViewModel> PsychTestList = new List <PsychTestViewModel>();

            //get lahat ng questions sa Questions table
            var datalist = db.Questions
                           .OrderBy(x => x.QuestionID)
                           .ToList();


            foreach (var item in datalist)
            {
                PsychTestViewModel pvm = new PsychTestViewModel();

                //lagay sa vm yung value sa db
                pvm.QuestionID = item.QuestionID;
                pvm.Question   = item.Question;
                PsychTestList.Add(pvm);
            }

            //get lahat ng answers sa Answers table
            var answers = db.Answers
                          .OrderBy(x => x.QuestionID)
                          .ToList();


            foreach (var item in answers)
            {
                //check if may row na may laman ang userID, questionID, answerid, answer
                var check = db.Answers
                            .Where(x => x.AnswerID == item.AnswerID && x.QuestionID == item.QuestionID && x.UserID == currentUserId && x.Answer == item.Answer)
                            .ToList();

                if (check.Count() != 0)
                {
                    TempData["Message"] = "You have already completed this test!";
                    return(RedirectToAction("Index", "Home"));
                }
            }

            return(View(PsychTestList));
        }
Example #3
0
        public ContentResult GetData1()
        {
            var currentUserId             = User.Identity.GetUserId();
            List <PsychTestViewModel> pvm = new List <PsychTestViewModel>();
            var results = db.Answers.ToList();

            foreach (Answers answers in results)
            {
                PsychTestViewModel viewmodel = new PsychTestViewModel();
                viewmodel.QuestionID = answers.QuestionID;
                viewmodel.Answer     = answers.Answer;

                pvm.Add(viewmodel);
            }

            return(Content(JsonConvert.SerializeObject(pvm), "application/json"));
        }
Example #4
0
        public ActionResult Edit(int?QuestionID, PsychTestViewModel ptvm)
        {
            GetCurrentUserInViewBag();
            Questions Questions = db.Questions.Find(QuestionID);

            if (Questions == null)
            {
                return(HttpNotFound());
            }

            if (ModelState.IsValid)
            {
                Questions.Question = ptvm.Question;

                var questionTag = GetAllQuestionTags();
                ptvm.QuestionTags = GetSelectListItems(questionTag);

                if (ptvm.QuestionTag != null)
                {
                    Questions.QuestionTag = ptvm.QuestionTag;
                }

                bool IsQuestionPositive = false;
                if (ptvm.IsQuestionPositive == true)
                {
                    IsQuestionPositive = true;
                }
                else
                {
                    IsQuestionPositive = false;
                }

                Questions.IsQuestionPositive = IsQuestionPositive;


                db.SaveChanges();

                TempData["Message"] = "Question " + Questions.QuestionID + " successfully updated!";
            }
            else
            {
                TempData["Error"] = "Question " + Questions.QuestionID + " not updated!";
            }

            return(RedirectToAction("Index"));
        }
Example #5
0
        public ActionResult CreateTest([Bind(Include = "QuestionID,Question,QuestionTag")] PsychTestViewModel psychTestViewModel)
        {
            GetCurrentUserInViewBag();

            Questions Questions = new Questions();

            if (ModelState.IsValid)
            {
                //put question in Questions Table
                var questionTag = GetAllQuestionTags();
                psychTestViewModel.QuestionTags = GetSelectListItems(questionTag);

                if (psychTestViewModel.QuestionTag != null)
                {
                    Questions.QuestionTag = psychTestViewModel.QuestionTag;
                }

                Questions.QuestionID = psychTestViewModel.QuestionID;
                Questions.Question   = psychTestViewModel.Question;

                bool IsQuestionPositive = false;
                if (psychTestViewModel.IsQuestionPositive == true)
                {
                    IsQuestionPositive = true;
                }
                else
                {
                    IsQuestionPositive = false;
                }

                Questions.IsQuestionPositive = IsQuestionPositive;


                db.Questions.Add(Questions);
                db.SaveChanges();

                TempData["Message"] = "Question " + Questions.QuestionID + " successfully added!";
            }
            else
            {
                TempData["Error"] = "Question " + Questions.QuestionID + " not added!";
            }

            return(RedirectToAction("Index"));
        }
Example #6
0
        // GET: PsychologicalTest/Edit
        public ActionResult Edit(int?QuestionID)
        {
            GetCurrentUserInViewBag();

            if (QuestionID == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Questions Questions = db.Questions.Find(QuestionID);

            if (Questions == null)
            {
                return(HttpNotFound());
            }

            PsychTestViewModel ptvm = new PsychTestViewModel();

            ptvm.Question = Questions.Question;
            var questionTag = GetAllQuestionTags();

            ptvm.QuestionTags = GetSelectListItems(questionTag);

            if (Questions.QuestionTag != null)
            {
                ptvm.QuestionTag = Questions.QuestionTag.Trim();
            }

            if (Questions.IsQuestionPositive != null)
            {
                ptvm.IsQuestionPositive = (bool)Questions.IsQuestionPositive;
            }



            return(View(ptvm));
        }
Example #7
0
        // GET: PsychologicalTest/StudentList
        public ActionResult StudentList(string searchStringName, string currentFilter, int?page)
        {
            GetCurrentUserInViewBag();

            try
            {
                int intPage           = 1;
                int intPageSize       = 10;
                int intTotalPageCount = 0;

                if (searchStringName != null)
                {
                    intPage = 1;
                }
                else
                {
                    if (currentFilter != null)
                    {
                        searchStringName = currentFilter;
                        intPage          = page ?? 1;
                    }
                    else
                    {
                        searchStringName = "";
                        intPage          = page ?? 1;
                    }
                }

                ViewBag.CurrentFilter = searchStringName;
                List <TestViewModel> StudentInventorylist = new List <TestViewModel>();
                int intSkip = (intPage - 1) * intPageSize;
                intTotalPageCount = db.Students
                                    .Where(x => x.StudentFirstName.Contains(searchStringName))
                                    .Count();

                var datalist = db.Students
                               .Where(x => x.StudentLastName.Contains(searchStringName) || x.StudentFirstName.Contains(searchStringName))
                               .OrderBy(x => x.StudentLastName)
                               .Skip(intSkip)
                               .Take(intPageSize)
                               .ToList();

                int noAnswer = 0;
                List <TestViewModel> StudentInventorylist3 = new List <TestViewModel>();

                foreach (var item in datalist)
                {
                    TestViewModel pvm = new TestViewModel();
                    pvm.StudentFirstName  = item.StudentFirstName;
                    pvm.StudentMiddleName = item.StudentMiddleName;
                    pvm.StudentLastName   = item.StudentLastName;
                    pvm.UserID            = item.UserID;
                    pvm.StudentID         = item.StudentID;
                    StudentInventorylist.Add(pvm);

                    //see how many students have no psych test
                    var dlist =
                        (from ans in db.Answers
                         where ans.UserID == pvm.UserID
                         select new { Answer = ans.Answer });

                    int countOfTotalStudents = datalist.Count();

                    if (dlist.Count() == 0)
                    {
                        noAnswer++;

                        ViewBag.ListOfStudents = "List of students who haven't taken the Psychological Test";

                        //write yung names ng student where nag dlist.count == 0
                        TestViewModel tvm = new TestViewModel();
                        tvm.StudentFirstName  = pvm.StudentFirstName;
                        tvm.StudentMiddleName = pvm.StudentMiddleName;
                        tvm.StudentLastName   = pvm.StudentLastName;
                        tvm.UserID            = pvm.UserID;
                        tvm.StudentID         = pvm.StudentID;
                        StudentInventorylist3.Add(tvm);

                        ViewBag.studentlist = StudentInventorylist3;

                        int countOfStudentsWithNoPsychTest = noAnswer;
                        ViewBag.CountOfTotalStudents           = countOfTotalStudents;
                        ViewBag.CountOfStudentsWithNoPsychTest = countOfTotalStudents - countOfStudentsWithNoPsychTest;
                    }
                    else
                    {
                        int countOfStudentsWithNoPsychTest = noAnswer;

                        ViewBag.CountOfTotalStudents           = countOfTotalStudents;
                        ViewBag.CountOfStudentsWithNoPsychTest = countOfTotalStudents - countOfStudentsWithNoPsychTest;
                    }
                }

                //display questions sa table
                var datalistQuestions = db.Questions.ToList();
                List <PsychTestViewModel> questionlist = new List <PsychTestViewModel>();

                foreach (var question in datalistQuestions)
                {
                    PsychTestViewModel ptvm = new PsychTestViewModel();
                    ptvm.QuestionID = question.QuestionID;
                    ptvm.Question   = question.Question;

                    questionlist.Add(ptvm);
                }

                ViewBag.questionlist = questionlist;

                // Set the number of pages
                var _UserAsIPagedList =
                    new StaticPagedList <TestViewModel>
                    (
                        StudentInventorylist, intPage, intPageSize, intTotalPageCount
                    );

                return(View(_UserAsIPagedList));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, "Error: " + ex);
                List <TestViewModel> StudentInventorylist = new List <TestViewModel>();

                return(View(StudentInventorylist.ToPagedList(1, 25)));
            }
        }
Example #8
0
        // GET: PsychologicalTest/Responses
        //[Authorize(Roles = "Counselor")]
        public ActionResult Responses(string UserID)
        {
            GetCurrentUserInViewBag();

            List <PsychTestViewModel> PsychTestList = new List <PsychTestViewModel>();

            var datalist =
                (from ans in db.Answers
                 join question in db.Questions
                 on ans.QuestionID equals question.QuestionID
                 where ans.UserID == UserID
                 select new { Answer = ans.Answer, QuestionID = question.QuestionID, Question = question.Question });

            if (datalist.Count() == 0)
            {
                TempData["Error"] = "This user has not completed the test yet!";
            }
            else
            {
                var testCompletionDate = db.Answers
                                         .Where(a => a.UserID == UserID)
                                         .OrderByDescending(x => x.TestCompletionDate)
                                         .Select(y => y.TestCompletionDate)
                                         .First().ToString();

                ViewBag.TestCompletionDate = testCompletionDate;

                foreach (var item in datalist)
                {
                    PsychTestViewModel pvm = new PsychTestViewModel();

                    pvm.QuestionID = item.QuestionID;
                    pvm.Question   = item.Question;
                    pvm.Answer     = item.Answer;
                    PsychTestList.Add(pvm);
                }

                var answers = db.Answers
                              .OrderBy(x => x.QuestionID)
                              .ToList();

                var u = db.Students.FirstOrDefault(d => d.UserID == UserID);

                if ((u.StudentFirstName != null) && (u.StudentLastName != null))
                {
                    ViewBag.Student = u.StudentFirstName.Trim() + " " + " " + u.StudentLastName.Trim();
                }
                else
                {
                    ViewBag.Student = "Error: User has no name record.";
                }

                //loop through selectlist para dynamic si questiontag?
                //PHYSICAL
                var totalNumberOfNegativeQuestions = from question in db.Questions
                                                     where question.IsQuestionPositive == false
                                                     select new { Tag = question.IsQuestionPositive };

                //PHYSICAL
                var numberOfPhysicalQuestions = from question in db.Questions
                                                where question.QuestionTag == "Physical"
                                                select new { Tag = question.QuestionTag };


                var disagreeInPosPhysicalQuery =
                    (from ans in db.Answers
                     join question in db.Questions
                     on ans.QuestionID equals question.QuestionID
                     where ans.UserID == UserID && ans.Answer == 3 && question.QuestionTag == "Physical" && question.IsQuestionPositive == true
                     select new { Answer = ans.Answer });


                //query Number of AGREE(Negative) in PHYSICAL
                var agreeInNegPhysicalQuery =
                    (from ans in db.Answers
                     join question in db.Questions on ans.QuestionID equals question.QuestionID
                     where ans.UserID == UserID && ans.Answer == 1 && question.QuestionTag == "Physical" && question.IsQuestionPositive == false
                     select new { Answer = ans.Answer });


                //EMOTIONAL
                var numberOfEmotionalQuestions = from question in db.Questions
                                                 where question.QuestionTag == "Emotional"
                                                 select new { Tag = question.QuestionTag };


                var disagreeInPosEmotionalQuery =
                    (from ans in db.Answers
                     join question in db.Questions
                     on ans.QuestionID equals question.QuestionID
                     where ans.UserID == UserID && ans.Answer == 3 && question.QuestionTag == "Emotional" && question.IsQuestionPositive == true
                     select new { Answer = ans.Answer });

                //query Number of AGREE(Negative) in Emotional
                var agreeInNegEmotionalQuery = from ans in db.Answers
                                               join question in db.Questions on ans.QuestionID equals question.QuestionID
                                               where ans.UserID == UserID && ans.Answer == 1 && question.QuestionTag == "Emotional" && question.IsQuestionPositive == false
                                               select new { Answer = ans.Answer };


                //Social
                var numberOfSocialQuestions = from question in db.Questions
                                              where question.QuestionTag == "Social"
                                              select new { Tag = question.QuestionTag };

                //query Number of DISAGREE(Positive) in Social
                var disagreeInPosSocialQuery =
                    (from ans in db.Answers
                     join question in db.Questions
                     on ans.QuestionID equals question.QuestionID
                     where ans.UserID == UserID && ans.Answer == 3 && question.QuestionTag == "Social" && question.IsQuestionPositive == true
                     select new { Answer = ans.Answer });

                //query Number of AGREE(Negative) in Social
                var agreeInNegSocialQuery = from ans in db.Answers
                                            join question in db.Questions on ans.QuestionID equals question.QuestionID
                                            where ans.UserID == UserID && ans.Answer == 1 && question.QuestionTag == "Social" && question.IsQuestionPositive == false
                                            select new { Answer = ans.Answer };

                int NumberOfPhysicalQuestions      = numberOfPhysicalQuestions.Count();
                int TotalNumberOfNegativeQuestions = totalNumberOfNegativeQuestions.Count();
                int DiagreeInPosPhysicalQuery      = disagreeInPosPhysicalQuery.Count();
                int AgreeInNegPhysicalQuery        = agreeInNegPhysicalQuery.Count();
                int TotalNegativeAnswersInPhysical = DiagreeInPosPhysicalQuery + AgreeInNegPhysicalQuery;

                int NumberOfEmotionalQuestions      = numberOfEmotionalQuestions.Count();
                int DisagreeInPosEmotionalQuery     = disagreeInPosEmotionalQuery.Count();
                int AgreeInNegEmotionalQuery        = agreeInNegEmotionalQuery.Count();
                int TotalNegativeAnswersInEmotional = DisagreeInPosEmotionalQuery + AgreeInNegEmotionalQuery;

                int NumberOfSocialQuestions      = numberOfSocialQuestions.Count();
                int DisagreeInPosSocialQuery     = disagreeInPosSocialQuery.Count();
                int AgreeInNegSocialQuery        = agreeInNegSocialQuery.Count();
                int TotalNegativeAnswersInSocial = DisagreeInPosEmotionalQuery + AgreeInNegEmotionalQuery;

                int TotalNumberOfNegativeAnswers = TotalNegativeAnswersInPhysical + TotalNegativeAnswersInEmotional + TotalNegativeAnswersInSocial;

                //PHYSICAL
                int percentageOfPhysicalIssues = ((TotalNegativeAnswersInPhysical) * 200 + TotalNumberOfNegativeAnswers) / (TotalNumberOfNegativeAnswers * 2);
                //If positive ang question, 1 = good, 2= meh, 3 = bad
                //If negative ang question, 1 = bad, 2 = meh, 3 = good

                ViewBag.numOfPhysicalIssues        = TotalNegativeAnswersInPhysical;
                ViewBag.countOfPhysicalIssues      = NumberOfPhysicalQuestions;
                ViewBag.percentageOfPhysicalIssues = percentageOfPhysicalIssues;

                //EMOTIONAL
                int percentageOfEmotionalIssues = ((TotalNegativeAnswersInEmotional) * 200 + TotalNumberOfNegativeAnswers) / (TotalNumberOfNegativeAnswers * 2);
                ViewBag.numOfEmotionalIssues        = TotalNegativeAnswersInEmotional;
                ViewBag.countOfEmotionalIssues      = NumberOfEmotionalQuestions;
                ViewBag.percentageOfEmotionalIssues = percentageOfEmotionalIssues;

                //SOCIAL
                int percentageOfSocialIssues = ((TotalNegativeAnswersInSocial) * 200 + TotalNumberOfNegativeAnswers) / (TotalNumberOfNegativeAnswers * 2);
                ViewBag.numOfSocialIssues        = TotalNegativeAnswersInSocial;
                ViewBag.countOfSocialIssues      = NumberOfSocialQuestions;
                ViewBag.percentageOfSocialIssues = percentageOfSocialIssues;

                return(View(PsychTestList));
            }

            return(RedirectToAction("StudentList", "PsychTest"));
        }
Example #9
0
        public ActionResult Index(string searchStringQuestion, string currentFilter, int?page)
        {
            GetCurrentUserInViewBag();

            try
            {
                int intPage           = 1;
                int intPageSize       = 10;
                int intTotalPageCount = 0;

                if (searchStringQuestion != null)
                {
                    intPage = 1;
                }
                else
                {
                    if (currentFilter != null)
                    {
                        searchStringQuestion = currentFilter;
                        intPage = page ?? 1;
                    }
                    else
                    {
                        searchStringQuestion = "";
                        intPage = page ?? 1;
                    }
                }

                ViewBag.CurrentFilter = searchStringQuestion;
                List <PsychTestViewModel> PsychTestList = new List <PsychTestViewModel>();
                int intSkip = (intPage - 1) * intPageSize;
                intTotalPageCount = db.Questions
                                    .Where(x => x.Question.Contains(searchStringQuestion))
                                    .Count();

                var datalist = db.Questions
                               .Where(x => x.Question.Contains(searchStringQuestion))
                               .OrderBy(x => x.QuestionID)
                               .Skip(intSkip)
                               .Take(intPageSize)
                               .ToList();

                foreach (var item in datalist)
                {
                    PsychTestViewModel pvm = new PsychTestViewModel();
                    pvm.QuestionID = item.QuestionID;
                    pvm.Question   = item.Question;
                    PsychTestList.Add(pvm);
                }

                // Set the number of pages
                var _UserAsIPagedList =
                    new StaticPagedList <PsychTestViewModel>
                    (
                        PsychTestList, intPage, intPageSize, intTotalPageCount
                    );

                return(View(_UserAsIPagedList));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, "Error: " + ex);
                List <PsychTestViewModel> PsychTestList = new List <PsychTestViewModel>();

                return(View(PsychTestList.ToPagedList(1, 25)));
            }
        }