Exemplo n.º 1
0
        public ActionResult Score()
        {
            if ((Session["User"] == null) || ((bool)Session["Finshed"] == false)) //Checks that a User is logged in and All the questions have been answered.
            {
                return(Redirect("../Home/Index"));                                //return Redirect used instead of return View because Return View simply displays the View without calling the relevant controller method causing the page to be static.
            }
            else
            {
                QuestionDB        questions = (QuestionDB)Session["Questions"]; //The QuestionDB instance is set from the Session Questions
                QuizDBDataContext db        = new QuizDBDataContext();          //Creates a instance of the Database
                tblResult         result    = new tblResult                     //Creates a new instance of tblResult to be saved into the Database
                {
                    PlayerID       = (int)Session["UserID"],                    //Sets the PlayerID from the ID stored in the Session
                    Score          = questions.QuestionRoundScore(),            //Sets the Score for the round as well as the current DateTime stamp
                    ResultDateTime = DateTime.Now
                };

                db.tblResults.InsertOnSubmit(result);
                try     //Try catch used to submit the changes to the Database
                {
                    db.SubmitChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }

                ViewBag.TotalScore = questions.TotalScore();

                return(View("Score"));
            }
        }
Exemplo n.º 2
0
        public JsonResult Get(int id)
        {
            var      questionDB     = new QuestionDB(_context);
            question singleQuestion = questionDB.getQuestion(id);

            return(Json(singleQuestion));
        }
Exemplo n.º 3
0
        // GET: Quiz

        /*
         * The QuizController Index method using GET is used to make the API call to retrive the 10 Questions.
         * When the request is complete a JSON string is returned and it must be looped over and passed into the Question class for processing.
         * Each Question is then added to the QuestionDB class.
         * Returns the User to the Home Page if they are not logged in.
         */
        public ActionResult Index()
        {
            int QuestionCount = 10;                //Number of questions used

            if (Session["User"] == null)           //Checks if the user is logged in.
            {
                return(Redirect("../Home/Index")); //return Redirect used instead of return View because Return View simply displays the View without calling the relevant controller method causing the page to be static.
            }
            else
            {
                string     url         = "https://opentdb.com/api.php?amount=10&type=multiple"; //The url used to make the Api call.
                HttpClient client      = new HttpClient();
                string     fetchedJSON = client.GetStringAsync(url).Result;                     //The Api call is made and the Result is saved as a string.

                QuestionDB questions = new QuestionDB();                                        //Creates a instance of the QuestionDB class.

                for (int i = 0; i < QuestionCount; i++)
                {
                    Question question = new Question(fetchedJSON, i);   //Loops over the amount of questions there are passing in the JSON and the Number the Question is.
                    questions.AddQuestion(question);                    //Adds the Question to the QuestionDB instance
                }

                Session["Questions"] = questions;   //Sets the questions into a Session
                int num        = 0;
                int displayNum = num;
                num++;
                Session["Count"] = num;                            //Sets the Current Question number into a session

                return(View(questions.GetQuestionAt(displayNum))); //Passes a model into the View
            }
        }
Exemplo n.º 4
0
        public ActionResult Continue(string Questions)
        {
            if (Session["User"] == null)           //Checks if a User is logged in.
            {
                return(Redirect("../Home/Index")); //return Redirect used instead of return View because Return View simply displays the View without calling the relevant controller method causing the page to be static.
            }
            else
            {
                QuestionDB questions = (QuestionDB)Session["Questions"];    //The QuestionDB instance is set from the Session Questions
                int        num       = (int)Session["Count"];               //The Current question number is retrived from the Session

                if (questions.GetQuestionAt(num - 1).IsAnswer(Questions))   //Checks if the user got the previous question correct
                {
                    string yes = "Correct";
                    ViewBag.ANS = yes;              //Sets ViewBag based on answer.
                }
                else
                {
                    string no = "InCorrect";
                    ViewBag.ANS = no;               //Sets ViewBag based on answer.
                }

                int displayNum = num;
                num++;
                Session["Count"] = num;

                if (num > questions.QuestionCount())    //Checks if the last question has been completed
                {
                    Session["Finshed"] = true;          //Calls the Score method and sets the Finshed Session to true.
                    return(Score());
                }
                Session["Finshed"] = false;
                return(View(questions.GetQuestionAt(displayNum)));       //Passes a model into the View
            }
        }
Exemplo n.º 5
0
        public JsonResult GetBruker()
        {
            var           BrukerDB    = new QuestionDB(_context);
            List <bruker> alleBrukere = BrukerDB.hentAlleBrukere();

            return(Json(alleBrukere));
        }
Exemplo n.º 6
0
        public JsonResult Get()
        {
            var             questionDB    = new QuestionDB(_context);
            List <question> alleQuestions = questionDB.hentAlleQuestions();

            return(Json(alleQuestions));
        }
        public IActionResult Index()
        {
            LoginViewModel model = new LoginViewModel()
            {
                Question = QuestionDB.GetInstance().GetAllQuestiones()
            };

            return(View(model));
        }
Exemplo n.º 8
0
        public JsonResult Get()
        {
            var             questionDB     = new QuestionDB(_context);
            List <question> alleKunder     = questionDB.getAllQuestions();
            List <question> sortedQuestion = alleKunder.OrderBy(q => q.votes).ToList();

            sortedQuestion.Reverse();
            return(Json(sortedQuestion));
        }
Exemplo n.º 9
0
 // Start is called before the first frame update
 void Start()
 {
     db            = JsonUtility.FromJson <QuestionDB>(txtDb.text);
     categoryIndex = (int)Math.Round((db.categories.Length - 1) * UnityEngine.Random.value);
     categoryObj.GetComponent <TextMeshPro>().text = db.categories[categoryIndex].categoryName;
     answeredQuestions = new ArrayList();
     answerPermutation = new ArrayList();
     currentDelay      = delayAfterAnswer;
 }
Exemplo n.º 10
0
        public JsonResult Delete(int id)
        {
            var  questionDB = new QuestionDB(_context);
            bool OK         = questionDB.deleteQuestion(id);

            if (!OK)
            {
                return(Json("Could not delete question!"));
            }
            return(Json("OK"));
        }
Exemplo n.º 11
0
        public JsonResult Delete(int id)
        {
            var  brukerDb = new QuestionDB(_context);
            bool OK       = brukerDb.slettEnBruker(id);

            if (!OK)
            {
                return(Json("Kunne ikke slette brukeren!"));
            }
            return(Json("OK"));
        }
Exemplo n.º 12
0
        public JsonResult Put(int id, [FromBody] question innKunde)
        {
            var  questionDb = new QuestionDB(_context);
            bool OK         = questionDb.endreEnRating(id, innKunde);

            if (OK)
            {
                return(Json(OK));
            }

            return(Json("Kunne ikke endre rating i DB"));
        }
Exemplo n.º 13
0
 public JsonResult Post([FromBody] bruker innBrukere)
 {
     if (ModelState.IsValid)
     {
         var  brukerDb = new QuestionDB(_context);
         bool OK       = brukerDb.lagreBruker(innBrukere);
         if (OK)
         {
             return(Json("OK"));
         }
     }
     return(Json("Kunne ikke sette inn kunden i DB"));
 }
Exemplo n.º 14
0
 public JsonResult Put(int id, [FromBody] question inQuestion)
 {
     if (ModelState.IsValid)
     {
         var  questionDB = new QuestionDB(_context);
         bool OK         = questionDB.updateQuestion(id, inQuestion);
         if (OK)
         {
             return(Json("OK"));
         }
     }
     return(Json("Could not update question in DB"));
 }
Exemplo n.º 15
0
        public JsonResult Downvote(int id)
        {
            System.Diagnostics.Debug.WriteLine("Upvote ID: " + id);
            var  questionDB = new QuestionDB(_context);
            bool OK         = questionDB.downvoteQuestion(id);

            if (OK)
            {
                System.Diagnostics.Debug.WriteLine("Inside OK");
                return(Json("OK"));
            }
            return(Json("Could not update votes"));
        }
Exemplo n.º 16
0
 public JsonResult Post([FromBody] question inQuestion)
 {
     if (ModelState.IsValid)
     {
         var questionDB = new QuestionDB(_context);
         inQuestion.answer = inQuestion.answer.Replace("\n", "<br />");
         bool OK = questionDB.saveQuestion(inQuestion);
         if (OK)
         {
             return(Json("OK"));
         }
     }
     return(Json("Could not save question in DB"));
 }
        private async void btnAdd_Click(object sender, EventArgs e)
        {
            int i = 1;
            HandbookQuestionsService handbookQuestionsService = new HandbookQuestionsService();
            ApplicationViewModel     applicationViewModel     = new ApplicationViewModel();
            QuestionDB question = new QuestionDB();

            if (txtId.Text != "")
            {
                question.Id = Int32.Parse(txtId.Text);
            }
            question.Content = txtContent.Text;
            question.Answer  = Int32.Parse(txtAnswer.Text);
            question.Test    = test.Id;
            await applicationViewModel.GetQuestions(user.Login, user.Password);

            if (applicationViewModel.handbookQuestions.ToList().Where(q => q.TestId == test.Id).Count() <= test.Quantity)
            {
                await handbookQuestionsService.Add(user.Login, user.Password, question);

                questionForm.dataGridView.Rows.Clear();

                await applicationViewModel.GetQuestions(user.Login, user.Password);

                var Questions = applicationViewModel.handbookQuestions.Where(q => q.TestId == test.Id).ToList();
                foreach (var questions in Questions)
                {
                    var rowNumber = questionForm.dataGridView.Rows.Add();
                    questionForm.dataGridView.Rows[rowNumber].Cells["Id"].Value               = questions.Id;
                    questionForm.dataGridView.Rows[rowNumber].Cells["No"].Value               = i++;
                    questionForm.dataGridView.Rows[rowNumber].Cells["TestId"].Value           = questions.TestId;
                    questionForm.dataGridView.Rows[rowNumber].Cells["TestName"].Value         = questions.TestName;
                    questionForm.dataGridView.Rows[rowNumber].Cells["TestQuantity"].Value     = questions.TestQuantity;
                    questionForm.dataGridView.Rows[rowNumber].Cells["TestQuantityPass"].Value = questions.TestQuantityPass;
                    questionForm.dataGridView.Rows[rowNumber].Cells["SubjectId"].Value        = questions.SubjectId;
                    questionForm.dataGridView.Rows[rowNumber].Cells["SubjectName"].Value      = questions.SubjectName;
                    questionForm.dataGridView.Rows[rowNumber].Cells["GradeId"].Value          = questions.GradeId;
                    questionForm.dataGridView.Rows[rowNumber].Cells["GradeNumber"].Value      = questions.GradeNumber;
                    questionForm.dataGridView.Rows[rowNumber].Cells["Content"].Value          = questions.Content;
                    questionForm.dataGridView.Rows[rowNumber].Cells["Answer"].Value           = questions.Answer;
                }
                this.Close();
            }
            else
            {
                MessageBox.Show("cannot add, maximum number reached");
            }
        }
        //private async void btnAdd_Click(object sender, EventArgs e)
        //{
        //    if (test != null)
        //    {
        //        ApplicationViewModel applicationViewModel = new ApplicationViewModel();
        //        await applicationViewModel.GetGrades(user.Login, user.Password);
        //        AddQuestionForm questionForm = new AddQuestionForm(user, test, this);
        //        questionForm.Show();
        //    }
        //    else
        //    {
        //        MessageBox.Show("Choose test");
        //    }
        //}

        private async void dataGridView_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            QuestionDB questionDB = new QuestionDB();

            questionDB.Id      = Int32.Parse(dataGridView.Rows[e.RowIndex].Cells["Id"].FormattedValue.ToString());
            questionDB.Content = dataGridView.Rows[e.RowIndex].Cells["Content"].FormattedValue.ToString();
            questionDB.Answer  = Int32.Parse(dataGridView.Rows[e.RowIndex].Cells["Answer"].FormattedValue.ToString());
            questionDB.Test    = Int32.Parse(dataGridView.Rows[e.RowIndex].Cells["TestId"].FormattedValue.ToString());


            ApplicationViewModel applicationViewModel = new ApplicationViewModel();
            await applicationViewModel.GetGrades(user.Login, user.Password);

            AddQuestionForm questionForm = new AddQuestionForm(user, test, this, questionDB);

            questionForm.Show();
        }
Exemplo n.º 19
0
 private static Question QuestionFromDB(QuestionDB q)
 {
     return(new Question(q.Number, q.Text, q.Variants, q.BallsCorrect, q.CorrectNum));
 }
 public AddQuestionForm(User user, HandbookTest test, QuestionForm questionForm, QuestionDB question)
 {
     InitializeComponent();
     this.user         = user;
     this.test         = test;
     this.questionForm = questionForm;
     txtId.Text        = question.Id.ToString();
     txtContent.Text   = question.Content;
     txtAnswer.Text    = question.Answer.ToString();
 }
 // GET: Vote
 public void VoteUp(int id)
 {
     QuestionDB qDB = new QuestionDB();
     bool OK = qDB.voteQuestion(id, 1);
 }
Exemplo n.º 22
0
 public QuestionBL()
 {
     Qdb    = new QuestionDB();
     kdb    = new KnowledgeKeyDB();
     sortdb = new QuestionSortDB();
 }
Exemplo n.º 23
0
 public KnowledgeKeyBL()
 {
     Kkdb = new KnowledgeKeyDB();
     Qdb  = new QuestionDB();
 }
Exemplo n.º 24
0
 public QuestionManager()
 {
     Qdb    = new QuestionDB();
     sortdb = new QuestionSortDb();
 }