Exemplo n.º 1
0
        public async void EditButton(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            if (quizParams.Quiz == null)
            {
                DisplayErrorMessageAsync("Please select a quiz from the list");
                return;
            }
            var completeQuiz = await QuizRequest.GetCompleteQuizAsync(quizParams.Quiz).ConfigureAwait(true);

            quizParams.Quiz = completeQuiz;

            //TODO: error no selected quiz
            // adds collections to list so they are easier to operate on
            int questionCounter = 1;

            foreach (Question q in completeQuiz.Questions)
            {
                q.QuestionNumber = questionCounter++;
                completeQuiz.QuestionList.Add(q);
                foreach (Answer a in q.Answers)
                {
                    q.AnswersList.Add(a);
                }
            }
            if (quizParams != null)
            {
                NavigationService.Navigate(typeof(EditQuiz), quizParams);
            }
        }
Exemplo n.º 2
0
        public async void DeleteQuiz(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            if (quizParams.Quiz == null)
            {
                DisplayErrorMessageAsync("Please select a quiz from the list");
                return;
            }
            Quiz quiz     = quizParams.Quiz;
            var  myHashId = HashGenerator.ComputeSha256Hash(IdentityService.GetAccountIdentifier());

            if (myHashId != quizParams.Quiz.UserIdHash)
            {
                DisplayErrorMessageAsync("Error. UserId hash did not match quiz's UserId hash.");
                return;
            }

            bool userConfirmed = await DisplayAreYouSureDialog().ConfigureAwait(true);

            if (userConfirmed)
            {
                if (IdentityService.IsLoggedIn())
                {
                    if (await QuizRequest.DeleteQuizAsync(quiz).ConfigureAwait(true))
                    {
                        NavigationService.Navigate(typeof(MainPage));
                    }
                    else
                    {
                        DisplayErrorMessageAsync("There was an error deleting the quiz.");
                    }
                }
            }
        }
Exemplo n.º 3
0
        public async void FillQuizList()
        {
            //TODO: errorhandling no internet
            var thisHashId = HashGenerator.ComputeSha256Hash(IdentityService.GetAccountIdentifier());

            var quizList = await QuizRequest.GetQuizzesFromIdHashAsync(thisHashId).ConfigureAwait(true);

            foreach (Quiz q in quizList)
            {
                QuizzesObservableCollection.Add(q);
            }
        }
        public HttpResponseMessage Create(QuizRequest req)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            int id = qService.Create(req);
            ItemResponse <int> response = new ItemResponse <int>();

            response.Item = id;
            return(Request.CreateResponse(HttpStatusCode.Created, response));
        }
Exemplo n.º 5
0
        public void Post([FromBody] QuizRequest quizRequest)
        {
            var quiz = new Quizes
            {
                Title   = quizRequest.Title,
                Summary = quizRequest.Summary,
                Score   = quizRequest.Score,
                // Exception handler will kick off when trying to insert the categoryId's that doesn't exist.
                CategoryId = quizRequest.CategoryId,
            };

            _context.Quizes.Add(quiz);
            _context.SaveChanges();
        }
Exemplo n.º 6
0
        public async void FillQuizList()
        {
            Quiz[] quizList = await QuizRequest.GetQuizListAsync().ConfigureAwait(true);

            if (quizList == null)
            {
                DisplayErrorMessageAsync("There was an error loading the quizzes");
                return;
            }
            foreach (Quiz q in quizList)
            {
                QuizzesObservableCollection.Add(q);
            }
        }
Exemplo n.º 7
0
        public async void AddQuiz()
        {
            var myHashId = HashGenerator.ComputeSha256Hash(IdentityService.GetAccountIdentifier());

            if (myHashId != quiz.UserIdHash)
            {
                DisplayErrorMessageAsync("Error. UserId hash did not match quiz's UserId hash.");
                return;
            }

            if (QuizIsValid(quiz))
            {
                bool userConfirmed = await DisplayAreYouSureDialog().ConfigureAwait(true);

                if (userConfirmed)
                {
                    quiz.QuizName = QuizNameHeader;
                    //updating quiz and question's ICollections and deleting their ILists.
                    quiz.Questions.Clear();
                    foreach (Question q in quiz.QuestionList)
                    {
                        quiz.Questions.Add(q);
                    }
                    quiz.QuestionList.Clear();
                    foreach (var question in quiz.Questions)
                    {
                        question.Answers.Clear();
                        foreach (var answer in question.AnswersList)
                        {
                            question.Answers.Add(answer);
                        }
                        question.AnswersList.Clear();
                    }

                    if (IdentityService.IsLoggedIn())
                    {
                        if (await QuizRequest.UpdateQuizCascadingAsync(quiz).ConfigureAwait(true))
                        {
                            NavigationService.Navigate(typeof(MainPage));
                        }
                        else
                        {
                            DisplayErrorMessageAsync("There was an error updating the quiz.");
                        }
                    }
                }
            }
        }
Exemplo n.º 8
0
        public async void AddQuiz()
        {
            if (QuizIsValid(quiz))
            {
                bool userConfirmed = await DisplayAreYouSureDialog().ConfigureAwait(true);

                if (userConfirmed)
                {
                    //updating quiz and question's ICollections and deleting their ILists.
                    quiz.Questions.Clear();
                    foreach (Question q in quiz.QuestionList)
                    {
                        quiz.Questions.Add(q);
                    }

                    quiz.QuestionList = null;
                    foreach (var q in quiz.Questions)
                    {
                        q.Answers.Clear();
                        foreach (var answer in q.AnswersList)
                        {
                            q.Answers.Add(answer);
                        }
                        q.AnswersList = null;
                    }

                    if (IdentityService.IsLoggedIn())
                    {
                        quiz.UserIdHash = HashGenerator.ComputeSha256Hash(IdentityService.GetAccountIdentifier());
                    }

                    if (await QuizRequest.AddQuizToDbAsync(quiz).ConfigureAwait(true))
                    {
                        Quizzes.Add(quiz);
                        NavigationService.Navigate(typeof(MainPage));
                    }
                    else
                    {
                        DisplayErrorMessageAsync("There was an unknown error adding your quiz to the database.");
                    }
                }
            }
        }
Exemplo n.º 9
0
        public int Create(QuizRequest req)
        {
            int id = 0;

            dataProvider.ExecuteNonQuery(
                "Quizzes_insert",
                delegate(SqlParameterCollection parameter)
            {
                parameter.AddWithValue("@question", req.Question);
                parameter.AddWithValue("@answer", req.Answer);
                parameter.AddWithValue("@answers", JsonConvert.SerializeObject(req.Answers));
                parameter.AddWithValue("@subject", req.Subject);
                parameter.AddWithValue("@answer_type", req.AnswerType);
                SqlParameter newId = new SqlParameter("@id", SqlDbType.Int);
                newId.Direction    = ParameterDirection.Output;
                parameter.Add(newId);
            }, returnParameters : delegate(SqlParameterCollection param)
            {
                id = (int)param["@id"].Value;
            }
                );
            return(id);
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            string        url     = "https://career.guru99.com/top-27-ssis-interview-questions/";
            string        type    = "Question";
            ChromeOptions options = new ChromeOptions();

            options.AddArgument("--headless");
            options.AddArgument("--incognito");
            options.AddArgument("--ignore-certificate-errors");
            IWebDriver chromeDriver = new ChromeDriver(options);

            chromeDriver.Url = url;
            var html   = chromeDriver.PageSource;
            var parser = new HtmlParser();
            var doc    = parser.Parse(html);

            if (type == "Question")
            {
                var questions = doc.QuerySelectorAll("p > strong");

                for (int i = 0; i < questions.Length; i++)
                {
                    try
                    {
                        var    question = new QuestionRequest();
                        string str      = questions[i].TextContent;
                        if (str.Length > 3 && str.Contains("?"))
                        {
                            var result = str.Substring(str.IndexOf(")") + 1);
                            question.Question = result;
                            question.Subject  = "SQL Server";
                            Create(question);
                        }
                    }
                    catch (SqlException sqlex) when(sqlex.Number == 2601)
                    {
                        continue;
                    }
                }
                void Create(QuestionRequest req)
                {
                    using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["InterviewMeConnection"].ConnectionString))
                    {
                        SqlCommand cmd = con.CreateCommand();
                        cmd.CommandText = "Questions_insert";
                        cmd.CommandType = System.Data.CommandType.StoredProcedure;
                        con.Open();
                        cmd.Parameters.AddWithValue("@question", req.Question);
                        cmd.Parameters.AddWithValue("@subject", req.Subject);
                        cmd.Parameters.Add("@id", SqlDbType.Int).Direction = ParameterDirection.Output;
                        cmd.ExecuteNonQuery();
                    }
                }
            }

            else
            {
                var listings = doc.QuerySelectorAll(".mtq_question");
                void Create(QuizRequest req)
                {
                    using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["InterviewMeConnection"].ConnectionString))
                    {
                        SqlCommand cmd = con.CreateCommand();
                        cmd.CommandText = "Quizzes_insert";
                        cmd.CommandType = System.Data.CommandType.StoredProcedure;

                        con.Open();
                        cmd.Parameters.AddWithValue("@question", req.Question);
                        cmd.Parameters.AddWithValue("@answer", req.Answer);
                        cmd.Parameters.AddWithValue("@answers", JsonConvert.SerializeObject(req.Answers));
                        cmd.Parameters.AddWithValue("@subject", req.Subject);
                        cmd.Parameters.AddWithValue("@answer_type", req.AnswerType);
                        cmd.Parameters.Add("@id", SqlDbType.Int).Direction = ParameterDirection.Output;
                        cmd.ExecuteNonQuery();
                    }
                }

                for (int i = 0; i < listings.Length; i++)
                {
                    var quiz    = new QuizRequest();
                    var listing = listings[i];
                    quiz.Question = listing.QuerySelector(".mtq_question_text").TextContent;

                    var answers = new List <string>();
                    var choices = listing.QuerySelectorAll(".mtq_clickable");
                    for (int j = 0; j < choices.Length; j++)
                    {
                        answers.Add(choices[j].QuerySelector("div.mtq_answer_text").TextContent);
                        if (choices[j].QuerySelector("div.mtq_correct_marker") != null)
                        {
                            quiz.Answer = choices[j].QuerySelector("div.mtq_answer_text").TextContent;
                        }
                    }
                    quiz.Answers    = answers;
                    quiz.AnswerType = "Multiple Choice";
                    quiz.Subject    = "JavaScript";
                    Create(quiz);
                }
            }
        }