public ActionResult Create(Quiz collection) { try { // TODO: Add insert logic here if (ModelState.IsValid) { byte[] imageData = null; if (Request.Files.Count > 0) { HttpPostedFileBase poImgFile = Request.Files["fileim"]; using (var binary = new BinaryReader(poImgFile.InputStream)) { imageData = binary.ReadBytes(poImgFile.ContentLength); } } collection.Picture = imageData; var qz = new QuizData(); int id = qz.Insert(collection); if (id > 0) { return(RedirectToAction("Index", "Quiz")); } else { ModelState.AddModelError("", "Thêm thất bại"); } } return(RedirectToAction("Index")); } catch { return(View()); } }
public static async Task <IReadOnlyList <QuizQuestion> > GetQuestionsAsync(int category, int amount = 10, QuestionDifficulty difficulty = QuestionDifficulty.Easy) { if (category < 0) { throw new ArgumentException("Category ID is invalid!", nameof(category)); } if (amount < 1 || amount > 20) { throw new ArgumentException("Question amount out of range (max 20)", nameof(amount)); } string reqUrl = $"{_url}/api.php?amount={amount}&category={category}&difficulty={difficulty.ToAPIString()}&type=multiple&encode=url3986"; string response = await _http.GetStringAsync(reqUrl).ConfigureAwait(false); QuizData data = JsonConvert.DeserializeObject <QuizData>(response); if (data.ResponseCode == 0) { return(data.Questions.Select(q => { q.Content = WebUtility.UrlDecode(q.Content); q.Category = WebUtility.UrlDecode(q.Category); q.CorrectAnswer = WebUtility.UrlDecode(q.CorrectAnswer); q.Difficulty = difficulty; q.IncorrectAnswers = q.IncorrectAnswers.Select(ans => WebUtility.UrlDecode(ans)).ToList(); return q; }).ToList().AsReadOnly()); } else { return(null); } }
// GET: Admin/Quiz public ActionResult Index(int page = 1, int pageSize = 10) { QuizData qz = new QuizData(); var model = qz.ListQuizPaging(page, pageSize); return(View(model)); }
public void SaveToFile() { string data = JsonUtility.ToJson(this); string path = QuizData.fullPath(); File.WriteAllText(path, data); }
public ActionResult Delete(int id, FormCollection collection) { try { // TODO: Add delete logic here if (ModelState.IsValid) { var ts = new QuizData(); var res = ts.Delete(id); if (res) { return(RedirectToAction("Index", "Quiz")); } else { ModelState.AddModelError("", "Xóa thất bại"); } } return(RedirectToAction("Index")); } catch { return(View()); } }
public void UserSelectFalse() { animator.SetTrigger("False"); if (!currentQuestion.isTrue) { QuizData q = new QuizData(currentQuestion.fact, QuizData.State.Correct, (int)TimeManager.timeThreshhold); Debug.Log("THE CURRENT QUESITON IS ---> " + q.ToString()); QuizData.elementArray.Add(q); if (GameObject.FindGameObjectWithTag("AudioManager") != null) { FindObjectOfType <AudioManager>().Play("truenoise"); } score += 1; disableButtons(); } else { QuizData q = new QuizData(currentQuestion.fact, QuizData.State.Incorrect, (int)TimeManager.timeThreshhold); Debug.Log("THE CURRENT QUESITON IS ---> " + q.ToString()); QuizData.elementArray.Add(q); if (GameObject.FindGameObjectWithTag("AudioManager") != null) { FindObjectOfType <AudioManager>().Play("falsenoise"); } numWrong += 1; disableButtons(); } TimeManager.timeThreshhold = 9.5f; StartCoroutine(TrasnsitionToNextQuestionFalse()); }
public List <QuestionData> ReadQuestions(QuizData theQuiz) { List <QuestionData> return_data = new List <QuestionData>(); if (DataReader != null) { DataReader.Close(); } List <int> quest_ids = new List <int>(); SQL = "SELECT r.`question_id` FROM `rel_quizzes_questions` r WHERE r.`quiz_id` = \"" + theQuiz.Id + "\";"; InitializeCommand(); OpenConnection(); DataReader = Command.ExecuteReader(); if (DataReader.HasRows) { while (DataReader.Read()) { quest_ids.Add(DataReader.GetUInt16("question_id")); } } CloseConnection(); for (int i = 0; i < quest_ids.Count; i++) { return_data.Add(ReadQuestion(quest_ids[i])); } return(return_data); }
public void UpdateQuiz(QuizData theQuiz) { QuestionEntity temp = new QuestionEntity(); for (int i = 0; i < theQuiz.Questions.Count; i++) { QuestionData questionToSave; questionToSave = theQuiz.Questions[i]; if (questionToSave.Id == 0) { temp.CreateQuestion(questionToSave); AddQuestion(theQuiz, questionToSave); } else { temp.UpdateQuestion(questionToSave); } } temp.Dispose(); SQL = "UPDATE `quizzes` q SET q.`name` = \"" + theQuiz.Name + "\", q.`open_date` = \"" + theQuiz.Open.ToString("yyyy-MM-dd") + "\", q.`due_date` = \"" + theQuiz.Due.ToString("yyyy-MM-dd") + "\" WHERE q.`quiz_id` = \"" + theQuiz.Id + "\";"; InitializeCommand(); OpenConnection(); int result = ExecuteStoredProcedure(); CloseConnection(); if (result == 0) { throw new Exception("Unable to update the quiz on the database"); } }
/// <summary> /// Get the quiz's questions. /// </summary> /// <param name="id">The quiz's id.</param> public async Task OnGetAsync(string id) { DisplayQuestions = new List <DisplayQuestionModel>(); // Getting the current quiz QuizData quizData = new QuizData(_db); var dataQuizModels = await quizData.GetQuizById(id); DisplayQuizModel = new DisplayQuizModel { Duration = dataQuizModels[0].Duration, Id = dataQuizModels[0].Id, Quiz = dataQuizModels[0].Quiz, }; // Getting links List <DisplayLinkQuizQuestionModel> displayLinkQuizQuestionModels = new List <DisplayLinkQuizQuestionModel>(); LinkQuizQuestionData linkQuizQuestionData = new LinkQuizQuestionData(_db); List <DataLinkQuizQuestionModel> dataAccessLinkQuizQuestionModels = await linkQuizQuestionData.GetLinkedQuestions(id); foreach (DataLinkQuizQuestionModel dataAccessLinkQuizQuestionModel in dataAccessLinkQuizQuestionModels) { displayLinkQuizQuestionModels.Add(new DisplayLinkQuizQuestionModel { Id = dataAccessLinkQuizQuestionModel.Id, QuestionId = dataAccessLinkQuizQuestionModel.QuestionId, QuizId = dataAccessLinkQuizQuestionModel.QuizId, }); } DisplayLinks = displayLinkQuizQuestionModels; // Gettings questions for the dropdown list Questions = new SelectList(await GetQuestions(), "Id", "Question"); }
public static void GetQuestions(QuizData quiz) { //TODO replace code to get questions from database quiz.questions.Clear(); QuestionData newQuestion = new QuestionData(0); AnswerData correctAnswer = new AnswerData(0); AnswerData wrongAnswer = new AnswerData(0); correctAnswer.Correct = true; correctAnswer.Text = "This is the correct answer"; wrongAnswer.Text = "This is a wrong answer"; newQuestion.Text = "This is a question"; newQuestion.answers.Add(correctAnswer); newQuestion.answers.Add(wrongAnswer); newQuestion.answers.Add(wrongAnswer); newQuestion.answers.Add(wrongAnswer); for (int i = 0; i < 10; i++) { quiz.questions.Add(newQuestion); } }
public void DeleteQuiz(QuizData theQuiz) { if (DataReader != null) { DataReader.Close(); } QuestionEntity quest = new QuestionEntity(); for (int i = 0; i < theQuiz.Questions.Count; i++) { quest.DeleteQuestion(theQuiz.Questions[i]); } quest.Dispose(); SQL = "DELETE `quizzes`, `rel_courses_quizzes` FROM `quizzes` INNER JOIN `rel_courses_quizzes` ON `quizzes`.`quiz_id` = `rel_courses_quizzes`.`quiz_id` WHERE `quizzes`.`quiz_id` = \"" + theQuiz.Id + "\";"; InitializeCommand(); OpenConnection(); int result = ExecuteStoredProcedure(); CloseConnection(); if (result == 0) { throw new Exception("Could not delete the Quiz from Database"); } }
public IEnumerator RequestQuizOne() { WWWForm wwwForm = new WWWForm(); wwwForm.AddField("quiz_id", 1); wwwForm.AddField("type", "yontaku"); //4択だけど直そう WWW result = new WWW(quizUrl, wwwForm); //Debug.Log("test"); yield return(result); if (!string.IsNullOrEmpty(result.error)) { Debug.LogError("www Error:" + result.error); } else { Debug.Log(result.text); QuizData quizData = JsonUtility.FromJson <QuizData>(result.text); Debug.Log(quizData.type); Debug.Log(quizData.answer_txt); Debug.Log(quizData.text); //taskArray = todo.task.Split('|'); } }
/// <summary> /// Cache some references /// </summary> private void OnEnable() { originalBackgroundColor = GUI.backgroundColor; target = (QuizData)base.target; arrayProp = serializedObject.FindProperty("questions"); }
public void SetQuizUI(QuizData data) { descriptionText.text = data.desc; for (var i = 0; i < answerText.Length; i++) { answerText[i].text = data.answer[i]; } }
QuizData myQuiz; //quiz we are submitting /// <summary> /// Constructor /// </summary> /// <param name="quiz"></param> public frmSubmit(QuizData quiz) { InitializeComponent(); myQuiz = quiz; this.Text = "Submitting " + myQuiz.Name; }
void Start() { DontDestroyOnLoad(gameObject); allRoundData = QuizData.LoadFromFile().allRoundData; LoadPlayerProgress(); SceneManager.LoadScene("MenuScreen"); }
public void SetViewBagDD(int?selectedID = null) { var mt = new MonThiData(); ViewBag.MaMon = new SelectList(mt.ListMonThi(), "MaMon", "TenMon", selectedID); var qz = new QuizData(); ViewBag.MaCauHoi = new SelectList(qz.ListQuiz(), "MaCauHoi", "CauHoi", selectedID); }
private void AskQuestion() { QuizData Question = questions.Last(); Program.MainForm.LogDebug("Asking question.... Answer: " + Question.Answer); questions.RemoveAt(questions.Count - 1); QuizMap.SendPacket(OXPackets.QuizQuestion(true, Question.QuestionPage, Question.QuestionIdx)); curQuestion = RepeatingAction.Start("Quiz - " + (questions.Count - 1) + " - question", t => CheckAnswer(Question), 30 * 1000, 0); }
public void Show(QuizData quizData) { this.quizData = quizData; quizText.text = quizData.quiz; optionAText.text = quizData.optionA; optionBText.text = quizData.optionB; optionCText.text = quizData.optionC; optionDText.text = quizData.optionD; gameObject.SetActive(true); }
void SetQuiz() { quizIndex = Random.Range(0, quizTotal) % quizTotal; QuizData item = quizList[quizIndex]; answerLabels[0].text = QuizMakeString(item.answer1); answerLabels[1].text = QuizMakeString(item.answer2); answerLabels[2].text = QuizMakeString(item.answer3); answerLabels[3].text = QuizMakeString(item.answer4); questionLabel.text = item.question; }
public static List <QuizData> GetQuizzes(CourseData course) { // TODO replace with entity retrieving List <QuizData> quizzes = new List <QuizData>(); QuizData quiz = new QuizData(); quiz.Name = "My New Quiz"; quizzes.Add(quiz); return(quizzes); }
void QuizInit() { quizList = new List <QuizData>(); List <string> champs = new List <string>(); string[,] dic = LolSkillData.dic; for (int i = 0; i < dic.GetLength(0); i++) { string champ = dic[i, 2]; if (!champs.Contains(champ)) { champs.Add(champ); } } for (int i = 0; i < dic.GetLength(0); i++) { string idx = dic[i, 0]; string skill = dic[i, 1]; string champ = dic[i, 2]; QuizData quiz = new QuizData(); int t = champs.IndexOf(champ); List <int> ansIdList = new List <int>(); Hashtable ansValList = new Hashtable(); ansValList[0] = champs[t]; ansValList[1] = champs[(t + 1) % champs.Count]; ansValList[2] = champs[(t + 2) % champs.Count]; ansValList[3] = champs[(t + 3) % champs.Count]; for (int j = 0; j < 4; j++) { ansIdList.Add(j); } ansIdList.Shuffle(); for (int j = 0; j < 4; j++) { if (ansIdList[j] == 0) { quiz.correct = j; } } quiz.answer1 = "1. " + ansValList[ansIdList[0]] as string; quiz.answer2 = "2. " + ansValList[ansIdList[1]] as string; quiz.answer3 = "3. " + ansValList[ansIdList[2]] as string; quiz.answer4 = "4. " + ansValList[ansIdList[3]] as string; quiz.question = skill + "?"; quiz.id = int.Parse(idx); quizList.Add(quiz); } quizTotal = quizList.Count; }
public SingleMockTestPage(string dpath, int lim, int f) { InitializeComponent(); a = DependencyService.Get <IFileAccessHelper>().GetLocalFilePath(dpath); QD = new QuizData(a); var Data = QD.GetItemsAsync(); Testing(); limit = lim; paper = f; watch = new Stopwatch(); }
// Init Quiz List void QuizInit() { quizList = new List <QuizData>(); List <string> answers = new List <string>(); string[,] dic = Data.dic; for (int i = 0; i < dic.GetLength(0); i++) { string answer = dic[i, 2]; if (!answers.Contains(answer)) { answers.Add(answer); } } for (int i = 0; i < dic.GetLength(0); i++) { string idx = dic[i, 0]; string question = dic[i, 1]; string answer = dic[i, 2]; QuizData quiz = new QuizData(); int t = answers.IndexOf(answer); List <int> ansIdList = new List <int>(); Hashtable ansValList = new Hashtable(); ansValList[0] = answers[t]; ansValList[1] = answers[(t + 1) % answers.Count]; ansValList[2] = answers[(t + 2) % answers.Count]; ansValList[3] = answers[(t + 3) % answers.Count]; for (int j = 0; j < 4; j++) { ansIdList.Add(j); } ansIdList.Shuffle(); for (int j = 0; j < 4; j++) { if (ansIdList[j] == 0) { quiz.correct = j; } } quiz.answer1 = "1. " + ansValList[ansIdList[0]] as string; quiz.answer2 = "2. " + ansValList[ansIdList[1]] as string; quiz.answer3 = "3. " + ansValList[ansIdList[2]] as string; quiz.answer4 = "4. " + ansValList[ansIdList[3]] as string; quiz.question = question; // Question Setting. quiz.id = int.Parse(idx); quizList.Add(quiz); } quizTotal = quizList.Count; }
/// <summary> /// Handles submit button click event. /// Allows user to set open date and close date /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void submitToolStripMenuItem_Click(object sender, EventArgs e) { //show the form QuizData selectedQuiz = (QuizData)lvwQuizzes.SelectedItems[0].Tag; frmSubmit submitForm = new frmSubmit(selectedQuiz); submitForm.ShowDialog(); //check to see if the date time was changed, if it was remove it from the list if (selectedQuiz.Open != DateTime.MinValue) //determine if an open date has been set { lvwQuizzes.Items.Remove(lvwQuizzes.SelectedItems[0]); } }
void ClickAnswer(int no) { if (!quizOn) { return; } quizOn = false; QuizData item = quizList[quizIndex]; // Is answer correct? if (item.correct == no) { // Display good Effect Instantiate(goodEffect); // Display soul trail effect GameObject go = Instantiate(soulEffect) as GameObject; go.GetComponent <SoulEffect>().posX = -1f; // Display Happy Effect StartCoroutine(DelayActoin(0.6f, () => { go = Instantiate(happyEffect, new Vector3(-0.7f, 1f, 0f), Quaternion.identity) as GameObject; enemyHpMan.DoDamageHp(10); })); // Display Actor's motion friendAnimator.CrossFade("Good", 0.2f); enemyAnimator.CrossFade("Bad", 0.2f); } else { // Display Bad Effect Instantiate(badEffect); // Display soul trail effect GameObject go = Instantiate(soulEffect) as GameObject; go.GetComponent <SoulEffect>().posX = 1f; // Display Happy Effect StartCoroutine(DelayActoin(0.6f, () => { go = Instantiate(happyEffect, new Vector3(0.7f, 1f, 0f), Quaternion.identity) as GameObject; friendHpMan.DoDamageHp(10); })); // Display Actor's motion friendAnimator.CrossFade("Bad", 0.2f); enemyAnimator.CrossFade("Good", 0.2f); } StartCoroutine(DelayActoin(3f, () => { DrawQuiz(); })); }
/// <summary> /// Deletes the quiz. /// </summary> /// <param name="id">The quiz's id.</param> /// <returns>Refresh page.</returns> public async Task <IActionResult> OnPostDeleteAsync(int id) { QuizData quizData = new QuizData(_db); DataQuizModel newQuizModel = new DataQuizModel { Duration = DisplayQuiz.Duration, Id = DisplayQuiz.Id, Quiz = DisplayQuiz.Quiz, }; await quizData.DeleteQuiz(newQuizModel); return(RedirectToPage("./quiz")); }
public ActionResult Edit(int id, Quiz collection) { try { // TODO: Add update logic here if (ModelState.IsValid) { byte[] imageData = null; HttpPostedFileBase poImgFile = Request.Files["fileim"]; if (poImgFile != null && poImgFile.ContentLength > 0) { using (var binary = new BinaryReader(poImgFile.InputStream)) { imageData = binary.ReadBytes(poImgFile.ContentLength); } collection.Picture = imageData; var ts = new QuizData(); var res = ts.Update(collection); if (res) { return(RedirectToAction("Index", "Quiz")); } else { ModelState.AddModelError("", "Sửa thất bại"); } } else { byte[] tana = tn.Quizs.Where(x => x.MaCauHoi == id).Select(u => u.Picture).SingleOrDefault(); collection.Picture = tana; var ts = new QuizData(); var res = ts.Update(collection); if (res) { return(RedirectToAction("Index", "Quiz")); } else { ModelState.AddModelError("", "Sửa thất bại"); } } } return(RedirectToAction("Index")); } catch { return(View()); } }
/// <summary> /// saves a quiz /// </summary> /// <param name="quiz"></param> public static void SaveQuiz(QuizData quiz) { try { if (quiz.Id == 0) { entity.CreateQuiz(quiz); } else { entity.UpdateQuiz(quiz); } } catch (System.Exception e) { System.Windows.Forms.MessageBox.Show(e.Message); } }
public TriviaQuery(QuizData data) { Field <NonNullGraphType <ListGraphType <NonNullGraphType <QuizType> > > >("quizzes", resolve: context => { return(data.Quizzes); }); Field <NonNullGraphType <QuizType> >("quiz", arguments: new QueryArguments() { new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "id", Description = "id of the quiz" } }, resolve: (context) => data.FindById(context.GetArgument <string>("id"))); }
void QuizInit() { quizList = new List<QuizData>(); List<string> champs = new List<string>(); string[,] dic = LolSkillData.dic; for (int i = 0; i < dic.GetLength(0); i++) { string champ = dic[i,2]; if (!champs.Contains(champ)) champs.Add(champ); } for (int i = 0; i < dic.GetLength(0); i++) { string idx = dic[i, 0]; string skill = dic[i, 1]; string champ = dic[i, 2]; QuizData quiz = new QuizData(); int t = champs.IndexOf(champ); List<int> ansIdList = new List<int>(); Hashtable ansValList = new Hashtable(); ansValList[0] = champs[t]; ansValList[1] = champs[(t+1)%champs.Count]; ansValList[2] = champs[(t+2)%champs.Count]; ansValList[3] = champs[(t+3)%champs.Count]; for (int j = 0; j < 4; j++) ansIdList.Add(j); ansIdList.Shuffle(); for (int j = 0; j < 4; j++) if (ansIdList[j] == 0) quiz.correct = j; quiz.answer1 = "1. " + ansValList[ansIdList[0]] as string; quiz.answer2 = "2. " + ansValList[ansIdList[1]] as string; quiz.answer3 = "3. " + ansValList[ansIdList[2]] as string; quiz.answer4 = "4. " + ansValList[ansIdList[3]] as string; quiz.question = skill + "?"; quiz.id = int.Parse(idx); quizList.Add(quiz); } quizTotal = quizList.Count; }