Esempio n. 1
0
        public IActionResult quizVerifier([FromBody] QuizAnswers quizAnswers)
        {
            var quiz = courses[quizAnswers.quizId].Contents.Find(e => e.Name.Equals(quizAnswers.courseItemName)) as TestCourseItem;

            if (quiz == null)
            {
                return(new NotFoundObjectResult("Course item not found for particular courseId"));
            }
            QuizResults quizResults = new QuizResults();

            for (int i = 0; i < quiz.quizEntries.Count; i++)
            {
                var e = quiz.quizEntries[i];
                if (e.Answer.Equals(quizAnswers.answers[i]))
                {
                    quizResults.correctOnes.Add(i);
                }
                else
                {
                    quizResults.invalidOnes.Add(i, e.Answer);
                }
            }

            return(new OkObjectResult(quizResults));
        }
Esempio n. 2
0
        void SubmitPage(QuizResults results)
        {
            ChangePageEvent changePage = new ChangePageEvent();

            changePage.pageName = "QuizSubmit";
            changePage.results  = results;
            this.eventAggregator.Publish(changePage);
        }
Esempio n. 3
0
 public QuizSubmitViewModel(IEventAggregator eventAggregator, QuizResults results)
 {
     this.eventAggregator     = eventAggregator;
     this.results             = results;
     this.Model               = new QuizSubmitModel();
     this.Model.QuestionTotal = results.questions.Length.ToString();
     this.Model.CorrectTotal  = results.correctTotal.ToString();
     GetLeaderboard();
 }
Esempio n. 4
0
        public IActionResult Submit(int QuizId, int[] Answers)
        {
            Quiz quiz = quizRepository.GetQuiz(QuizId);

            QuizResults result = new QuizResults("Kristian", quiz);

            result.AddAnswers(Answers);

            return(View("results", result));
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            while (true)
            {
                int NumberOfQuestions = Questions.GetQuestions().Count;

                Quiz Quiz           = new Quiz(Questions, Answers, RightAnswers);
                var  CorrectAnswers = Quiz.GetCorrectAnswers();

                Percentage Percentage  = new Percentage();
                int        _Percentage = Percentage.CalculatePercentage(CorrectAnswers, NumberOfQuestions);

                QuizResults QuizResults = new QuizResults(_Percentage, CorrectAnswers.Count, NumberOfQuestions);

                Console.WriteLine(QuizResults.DisplayNumberOfQuestions());
                Console.WriteLine(QuizResults.DisplayNumberOfCorrectAnswers());
                Console.WriteLine(QuizResults.DisplayNumberOfErrors());
                Console.WriteLine(QuizResults.DisplayPercentage());
                Console.ReadLine();
            }
        }
Esempio n. 6
0
        QuizResults AddInstantQuizValues(QuizResults results)
        {
            int pointer = 0;

            //Adds the correct answers together and makes the "correct" list for easier displaying for teachers
            foreach (string answer in Model.Answers)
            {
                //String input or multiple choice
                if (Model.QuestionTypes[pointer] == 0 || Model.QuestionTypes[pointer] == 2)
                {
                    //If it's correct
                    if (Model.UserInputs[pointer] == Model.Answers[pointer])
                    {
                        results.correctTotal += 1;
                        results.correct.Add(true);
                    }
                    else
                    {
                        results.correct.Add(false);
                    }
                }
                //Integer input
                else if (Model.QuestionTypes[pointer] == 1)
                {
                    //If it's correct
                    if (Int32.Parse(Model.UserInputs[pointer]) == Int32.Parse(Model.Answers[pointer]))
                    {
                        results.correctTotal += 1;
                        results.correct.Add(true);
                    }
                    else
                    {
                        results.correct.Add(false);
                    }
                }

                pointer += 1;
            }
            return(results);
        }
Esempio n. 7
0
        void FinishQuiz()
        {
            QuizResults results = new QuizResults(this.quizID, this.username, Model.QuizType, Model.Questions, Model.UserInputs);

            if (Model.QuizType == "Instant")
            {
                results = AddInstantQuizValues(results);
            }

            //Converts the results object into JSON
            ServerRequest request     = new ServerRequest();
            string        resultsJSON = request.Serialise(results);

            //Creates a server connection to submit the quiz results
            ServerConnection server = new ServerConnection();

            server.ServerRequest("SUBMITRESULTS", new string[4] {
                this.quizID.ToString(), this.username, resultsJSON, results.correctTotal.ToString()
            });

            //Go to the quiz submit screen and pass the QuizResults object
            SubmitPage(results);
        }
Esempio n. 8
0
        public IActionResult GetQuizResults([FromBody] TraineeGetQuizResults traineeGetQuizResultsDTO)
        {
            string connectionString = Configuration["ConnectionStrings:DefaultConnectionString"];

            //Create list of all quizzes
            var quizResults = new QuizResults();

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                //Create the SQL command and set type to stored procedure.
                SqlCommand command = new SqlCommand("Quiz_GetByQuizID", connection);
                command.CommandType = System.Data.CommandType.StoredProcedure;

                //Set the parameters for the command.
                command.Parameters.AddWithValue("@quizID", traineeGetQuizResultsDTO.QuizID);

                connection.Open();

                //Execute the query and store the result.
                //Get all quizzes that belong to a group.
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            quizResults = new QuizResults
                            {
                                GroupID  = reader.GetInt32(reader.GetOrdinal("GroupID")),
                                QuizID   = reader.GetInt32(reader.GetOrdinal("QuizID")),
                                QuizName = reader.GetString(reader.GetOrdinal("QuizName"))
                            };
                        }
                        reader.Close();
                    }
                    else
                    {
                        return(BadRequest("Could not find matching quiz."));
                    }
                }

                //Create list of all questions
                var questions = new List <Data.GetQuizResults.QuestionDetails>();

                command             = new SqlCommand("Questions_GetByQuizID", connection);
                command.CommandType = System.Data.CommandType.StoredProcedure;

                //Get all questions for each quiz.

                //Set the parameters for the command.
                command.Parameters.Clear();
                command.Parameters.AddWithValue("@quizID", traineeGetQuizResultsDTO.QuizID);

                //Execute the query and store the result
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var question = new Data.GetQuizResults.QuestionDetails
                            {
                                QuestionID   = reader.GetInt32(reader.GetOrdinal("QuestionID")),
                                QuizID       = reader.GetInt32(reader.GetOrdinal("QuizID")),
                                QuestionText = reader.GetString(reader.GetOrdinal("QuestionText"))
                            };

                            questions.Add(question);
                        }
                        reader.Close();
                    }
                    else
                    {
                        return(BadRequest("Could not find matching questions."));
                    }
                }

                //Create list of all choices
                var choices = new List <Data.GetQuizResults.ChoiceDetails>();

                command             = new SqlCommand("Choices_GetByQuizID", connection);
                command.CommandType = System.Data.CommandType.StoredProcedure;

                //Set the parameters for the command.
                command.Parameters.Clear();
                command.Parameters.AddWithValue("@quizID", traineeGetQuizResultsDTO.QuizID);

                //Execute the query and store the result
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var choice = new Data.GetQuizResults.ChoiceDetails
                            {
                                ChoiceID   = reader.GetInt32(reader.GetOrdinal("ChoiceID")),
                                QuizID     = reader.GetInt32(reader.GetOrdinal("QuizID")),
                                QuestionID = reader.GetInt32(reader.GetOrdinal("QuestionID")),
                                ChoiceText = reader.GetString(reader.GetOrdinal("ChoiceText")),
                                isCorrect  = reader.GetBoolean(reader.GetOrdinal("IsCorrect"))
                            };

                            choices.Add(choice);
                        }
                        reader.Close();
                    }
                    else
                    {
                        return(BadRequest("Could not find matching choices."));
                    }
                }

                //Add the choices to the matching question item.
                foreach (Data.GetQuizResults.QuestionDetails question in questions)
                {
                    var tempChoices = new List <Data.GetQuizResults.ChoiceDetails>();

                    foreach (Data.GetQuizResults.ChoiceDetails choice in choices)
                    {
                        if (choice.QuestionID == question.QuestionID)
                        {
                            tempChoices.Add(choice);
                        }
                    }
                    question.Choices = tempChoices.ToArray();
                }

                quizResults.Questions = questions.ToArray();

                var results = new List <TraineeQuizResults>();

                command             = new SqlCommand("Results_GetByQuizIDUserID", connection);
                command.CommandType = System.Data.CommandType.StoredProcedure;

                //Set the parameters for the command.
                command.Parameters.Clear();
                command.Parameters.AddWithValue("@quizID", traineeGetQuizResultsDTO.QuizID);
                command.Parameters.AddWithValue("@userID", traineeGetQuizResultsDTO.UserID);

                //Execute the query and store the result
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var result = new TraineeQuizResults
                            {
                                ResultValue = reader.GetInt32(reader.GetOrdinal("ResultValue")),
                                QuizID      = reader.GetInt32(reader.GetOrdinal("QuizID")),
                                QuestionID  = reader.GetInt32(reader.GetOrdinal("QuestionID")),
                                UserID      = reader.GetInt32(reader.GetOrdinal("UserID")),
                                ResultID    = reader.GetInt32(reader.GetOrdinal("ResultID"))
                            };

                            results.Add(result);
                        }
                        reader.Close();
                    }
                    else
                    {
                        return(BadRequest("Could not find matching results."));
                    }
                }

                foreach (Data.GetQuizResults.QuestionDetails question in quizResults.Questions)
                {
                    foreach (TraineeQuizResults result in results)
                    {
                        if (question.QuestionID == result.QuestionID)
                        {
                            question.Result = result.ResultValue;
                        }
                    }
                }

                connection.Close();
            }

            //Return OK result with quizzes
            return(Ok(
                       quizResults
                       ));
        }
Esempio n. 9
0
        public Result SaveAnonCareerReport(string data)
        {
            try
            {
                data = data.Replace("careerPathwaysCurrentAnswers", "answers");
                data = data.Replace("careerPathwaysResults", "results");


                var rawData = JsonConvert.DeserializeObject <RawCareerQuizDataEntity>(data);

                var con           = new DapperConnectionManager();
                var saveQuizQuery = new QueryEntity();
                var credentials   = new CredentialsManager();
                saveQuizQuery.Query = @"INSERT INTO AnonUserQuizzes (Email, Name, QuizId, DateVal, Results ,Completed, Type, Date, NurseType, ActiveWorking, Area, Setting, Age, Country, Suburb, PostCode, State, PatientsTitle, Qualification) VALUES (";

                string NurseType     = rawData.aboutYouAnswers["32"].ToString();
                string ActiveWorking = rawData.aboutYouAnswers["67"].ToString();
                string Area          = rawData.aboutYouAnswers["71"].ToString();
                string Setting       = rawData.aboutYouAnswers["72"].ToString();
                string Age           = rawData.aboutYouAnswers["73"].ToString();
                string Patients      = rawData.aboutYouAnswers["76"].ToString();
                string Qualification = rawData.aboutYouAnswers["33"].ToString();

                var    addressDetails = rawData.aboutYouAnswers["69"].ToDictionary();
                string Country        = "";
                string Suburb         = "";
                string Postcode       = "";
                string State          = "";

                foreach (var detail in addressDetails)
                {
                    switch (detail.Key.ToLower())
                    {
                    case ("country"):
                        Country = detail.Value.ToString();
                        break;

                    case ("suburb"):
                        Suburb = detail.Value.ToString();
                        break;

                    case ("postalcode"):
                        Postcode = detail.Value.ToString();
                        break;

                    case ("state"):
                        State = detail.Value.ToString();
                        break;

                    default: break;
                    }
                }


                var results = new CareerResults()
                {
                    results = rawData.results,
                    answers = rawData.answers
                };

                QuizResults newResult = new QuizResults();
                newResult.score            = new Dictionary <string, float>();
                newResult.scorePositives   = new Dictionary <string, List <string> >();
                newResult.scorePercentages = new Dictionary <string, int>();
                newResult.date             = results.results.date;

                foreach (var score in results.results.score)
                {
                    if (int.Parse(score.Key) <= 10)
                    {
                        newResult.score.Add(score.Key, score.Value);
                    }
                }

                foreach (var scorePositive in results.results.scorePositives)
                {
                    if (int.Parse(scorePositive.Key) <= 10)
                    {
                        newResult.scorePositives.Add(scorePositive.Key, scorePositive.Value);
                    }
                }

                foreach (var scorePercentage in results.results.scorePercentages)
                {
                    if (int.Parse(scorePercentage.Key) <= 10)
                    {
                        newResult.scorePercentages.Add(scorePercentage.Key, scorePercentage.Value);
                    }
                }

                results.results = newResult;


                saveQuizQuery.Query += "'" + "*****@*****.**" + "', ";
                saveQuizQuery.Query += "'" + "anon" + "', ";
                saveQuizQuery.Query += 2 + ", ";
                saveQuizQuery.Query += "CAST('" + DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'") + "' AS DATETIME), ";
                saveQuizQuery.Query += "'" + JsonConvert.SerializeObject(results) + "', ";
                saveQuizQuery.Query += 1 + ", ";
                saveQuizQuery.Query += "'PATHWAY'" + ", ";
                saveQuizQuery.Query += "'" + results.results.date + "'" + ", ";
                saveQuizQuery.Query += "'" + NurseType + "'" + ", ";
                saveQuizQuery.Query += "'" + ActiveWorking + "'" + ", ";
                saveQuizQuery.Query += "'" + Area + "'" + ", ";
                saveQuizQuery.Query += "'" + Setting + "'" + ", ";
                saveQuizQuery.Query += "'" + Age + "'" + ", ";
                saveQuizQuery.Query += "'" + Country + "'" + ", ";
                saveQuizQuery.Query += "'" + Suburb + "'" + ", ";
                saveQuizQuery.Query += "'" + Postcode + "'" + ", ";
                saveQuizQuery.Query += "'" + State + "'" + ", ";
                saveQuizQuery.Query += "'" + Patients + "'" + ", ";
                saveQuizQuery.Query += "'" + Qualification + "'" + ")";

                return(con.ExecuteQuery <UserEntity>(saveQuizQuery));
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Esempio n. 10
0
        public string Serialise(QuizResults results)
        {
            string json = JsonConvert.SerializeObject(results, Formatting.Indented);

            return(json);
        }