Esempio n. 1
0
        public ActionResult ViewQuiz(int id)
        {
            UserViewModel vmUser = session.getSessionUser();

            if (vmUser == null)
            {
                if (!val.getUserCredentials(Request))
                {
                    return(RedirectToAction("Login", "Home"));
                }
                vmUser = session.getSessionUser();
            }
            if (!val.checkUserAuth(vmUser, hrGroup))
            {
                return(RedirectToAction("Index", "Home", new { error = "Invalid User Credentials" }));
            }
            UserQuizViewModel uqvm = new UserQuizViewModel();

            uqvm = GetQuizById(id);
            Queries query = new Queries();
            List <UserQuizQuestionAnswer> uqqas = query.getQuizByUserIdQuizId(query.getUserBySam(vmUser.SAMAccountName).id, id);

            if (uqqas.Count > 0)
            {
                uqvm.isTaken = true;
                ViewModelConverter vmConverter = new ViewModelConverter();
                uqvm.juqqas = new List <JUserQuizQuestionAnswer>();
                foreach (UserQuizQuestionAnswer uqqa in uqqas)
                {
                    uqvm.juqqas.Add(vmConverter.UserQuizQuestionAnswerToJModel(uqqa));
                }
            }
            return(Json(uqvm, JsonRequestBehavior.AllowGet));
        }
Esempio n. 2
0
        public ActionResult EditTraining(int id)
        {
            Queries           query    = new Queries();
            UserQuizViewModel uqvmQuiz = GetQuizById(id);

            return(Json(uqvmQuiz, JsonRequestBehavior.AllowGet));
        }
Esempio n. 3
0
        public ActionResult Quiz(int id = 0)
        {
            UserViewModel vmUser = session.getSessionUser();

            if (vmUser == null)
            {
                if (!val.getUserCredentials(Request))
                {
                    return(RedirectToAction("Login", "Home"));
                }
                vmUser = session.getSessionUser();
            }
            Queries query = new Queries();

            if (id == 0)
            {
                return(RedirectToAction("Index", "home", new { error = "Cannot Locate Quiz" }));
            }
            else if (!vmUser.userGroups.Contains(query.getGroupById(query.getQuizById(id).groupId).name))
            {
                return(RedirectToAction("Index", "home", new { error = "Invalid Quiz" }));
            }
            UserQuizViewModel uqvmQuiz = GetQuizById(id);

            uqvmQuiz.isHR      = vmUser.isHR;
            uqvmQuiz.isManager = vmUser.isManager;
            return(View(uqvmQuiz));
        }
Esempio n. 4
0
        public ActionResult Index(UserQuizViewModel model)
        {
            if (ModelState.IsValid)
            {
                User user = new User
                {
                    Name  = model.Name,
                    Email = model.Email
                };
                db.Users.Add(user);
                db.SaveChanges();

                UserQuiz userQuiz = new UserQuiz
                {
                    QuizID = model.Quiz.ID,
                    UserID = user.ID
                };
                db.UserQuizs.Add(userQuiz);
                db.SaveChanges();

                foreach (var question in model.QuizQuestionAndAnswer)
                {
                    UserQuizAnswer userQuizAnswer = null;

                    if (question.AnswerType == "TX")
                    {
                        userQuizAnswer = new UserQuizAnswer
                        {
                            QuizAnswerID = question.Answers[0].ID,
                            UserQuizText = question.UserAnswer,
                            UserQuizID   = userQuiz.ID
                        };
                    }
                    else
                    {
                        userQuizAnswer = new UserQuizAnswer
                        {
                            QuizAnswerID = Convert.ToInt32(question.UserAnswer),
                            UserQuizID   = userQuiz.ID
                        };
                    }
                    db.UserQuizAnswers.Add(userQuizAnswer);
                    db.SaveChanges();
                }

                return(RedirectToAction("Results", new { id = user.ID }));
            }

            return(View(model));
        }
Esempio n. 5
0
        public UserQuizViewModel GetQuizById(int quizId)
        {
            Queries query = new Queries();
            Quize   quiz  = query.getQuizById(quizId);

            UserQuizViewModel    uqvmQuiz = new UserQuizViewModel();
            List <Quize>         quizzes  = query.getQuizByTitle(quiz.title);
            List <UserQuizGroup> groups   = new List <UserQuizGroup>();

            foreach (Quize q in quizzes)
            {
                groups.Add(uqvmQuiz.GroupToUserQuizGroup(query.getGroupById(q.groupId)));
            }
            uqvmQuiz.groups      = groups;
            uqvmQuiz.QuizId      = quizId;
            uqvmQuiz.title       = quiz.title;
            uqvmQuiz.description = quiz.description;
            uqvmQuiz.media       = quiz.media;
            uqvmQuiz.startDate   = quiz.startDate;
            uqvmQuiz.preferDate  = quiz.preferDate;
            uqvmQuiz.expiredDate = quiz.expiredDate;
            uqvmQuiz.questions   = new List <UserQuizVMQuestion>();

            List <Question> questions = query.getQuestionsByQuizId(quiz.id);

            foreach (Question question in questions)
            {
                UserQuizVMQuestion uqvmQuestion = new UserQuizVMQuestion();
                uqvmQuestion.id      = question.id;
                uqvmQuestion.text    = question.questionText;
                uqvmQuestion.type    = question.questionType;
                uqvmQuestion.answers = new List <UserQuizVMAnswer>();
                List <Answer> answers = query.getAnswersByQuestionId(question.id);

                foreach (Answer answer in answers)
                {
                    UserQuizVMAnswer uqvmAnswer = new UserQuizVMAnswer();
                    uqvmAnswer.id         = answer.id;
                    uqvmAnswer.answerText = answer.answerText;
                    uqvmAnswer.isCorrect  = answer.isCorrect;
                    uqvmQuestion.answers.Add(uqvmAnswer);
                }
                uqvmQuiz.questions.Add(uqvmQuestion);
            }
            return(uqvmQuiz);
        }
Esempio n. 6
0
        public List <UserQuizQuestionAnswer> GradeSubmittedQuiz(UserQuizViewModel quiz, List <UserQuizQuestionAnswer> uqqas)
        {
            int questionCount = quiz.questions.Count();

            for (int i = 0; i < questionCount; i++)
            {
                if (quiz.questions[i].type != "shortAnswer")
                {
                    for (var j = 0; j < quiz.questions[i].answers.Count(); j++)
                    {
                        if (quiz.questions[i].answers[j].isCorrect && quiz.questions[i].answers[j].id == uqqas[i].answerId)
                        {
                            uqqas[i].isChecked  = true;
                            uqqas[i].isApproved = true;
                        }
                    }
                }
            }
            return(uqqas);
        }
Esempio n. 7
0
        public ActionResult updateTraining(int id = 0)
        {
            UserViewModel vmUser = session.getSessionUser();

            if (vmUser == null)
            {
                if (!val.getUserCredentials(Request))
                {
                    return(RedirectToAction("Login", "Home"));
                }
                vmUser = session.getSessionUser();
            }
            Queries query = new Queries();

            if (id == 0)
            {
                return(RedirectToAction("Index", "home", new { error = "Cannot Locate Quiz" }));
            }
            UserQuizViewModel uqvmQuiz = GetQuizById(id);

            uqvmQuiz.isHR      = vmUser.isHR;
            uqvmQuiz.isManager = vmUser.isManager;
            return(View(uqvmQuiz));
        }
Esempio n. 8
0
        public ActionResult Index()
        {
            int id = db.Quizs.Max(q => q.ID);
            UserQuizViewModel userQuizViewModel = new UserQuizViewModel();

            userQuizViewModel.TrackingID = Guid.NewGuid();

            Quiz quiz = db.Quizs.Where(q => q.ID == id).FirstOrDefault();

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

            int questionCount = db.QuizQuestions.Where(q => q.QuizID == id).Count() + 1;

            userQuizViewModel.Quiz = new QuizViewModel
            {
                ID   = quiz.ID,
                Name = quiz.Name,
                AmountOfQuestions = quiz.Amount
            };

            IList <int> questionNumbers = new List <int>();
            Random      rand            = new Random();
            int         next;

            for (int i = 0; i < quiz.Amount; i++)
            {
                if (questionNumbers.Count == 0)
                {
                    next = rand.Next(1, questionCount);
                    bool exists = false;
                    while (!exists)
                    {
                        exists = db.QuizQuestions.Any(q => q.QuizID == id && q.ID == next);
                        if (!exists)
                        {
                            next = rand.Next(1, questionCount);
                        }
                    }
                }
                else
                {
                    do
                    {
                        next = rand.Next(1, questionCount);
                        bool exists = false;
                        while (!exists)
                        {
                            exists = db.QuizQuestions.Any(q => q.QuizID == id && q.ID == next);
                            if (!exists)
                            {
                                next = rand.Next(1, questionCount);
                            }
                        }
                    } while (questionNumbers.Contains(next));
                }
                questionNumbers.Add(next);
            }

            foreach (int number in questionNumbers)
            {
                UserQuestionAnswerViewModel userQuestions = db.QuizQuestions.Where(q => q.ID == number)
                                                            .Select(q => new UserQuestionAnswerViewModel
                {
                    QuestionID = q.ID,
                    Question   = q.Question
                }).FirstOrDefault <UserQuestionAnswerViewModel>();

                userQuestions.Answers = db.QuizAnswers.Where(a => a.QuestionID == number)
                                        .Select(a => new AnswerViewModel
                {
                    ID     = a.ID,
                    Answer = a.Answer
                }).ToList <AnswerViewModel>();

                userQuestions.AnswerType = db.QuizAnswers.Where(a => a.QuestionID == number)
                                           .Select(a => a.AnswerType).FirstOrDefault <string>();

                if (userQuizViewModel.QuizQuestionAndAnswer == null)
                {
                    userQuizViewModel.QuizQuestionAndAnswer = new List <UserQuestionAnswerViewModel>();
                }

                userQuizViewModel.QuizQuestionAndAnswer.Add(userQuestions);
            }

            return(View(userQuizViewModel));
        }