/// <summary> /// approve or reject a given challenge question /// </summary> /// <param name="question">approving challenge question</param> /// <param name="isApproved">state to approve or reject</param> /// <param name="callback">callback to notify caller when task is finished</param> public void doApproveQuestion(ChallengeQuestion question, bool isApproved, Action <bool, string> callback) { question.reviewer = getFirebaseUser().DisplayName; question.status = isApproved ? ChallengeQuestion.Status.Approved : ChallengeQuestion.Status.Rejected; question.dateApproved = DateTime.Now; saveQuestion(question, callback); }
/// <summary> /// retrieving list of questions from firebase database /// </summary> /// <param name="callback">callback to notify caller when task is finished</param> public void getQuestionList(Action <List <ChallengeQuestion>, string> callback) { var refQestion = _db.RootReference.Child(ROOT_CHALLENGE_QUESTION); refQestion.GetValueAsync().ContinueWithOnMainThread(task => { string message = readError(task); if (message != null) { callback(null, message); return; } if (task.IsCompleted) { message = "task is success"; var snapshot = task.Result; var resultDict = JsonConvert.DeserializeObject <Dictionary <string, ChallengeQuestion> >(snapshot.GetRawJsonValue()); var list = new List <ChallengeQuestion>(); foreach (string key in resultDict.Keys) { ChallengeQuestion question = resultDict[key]; question.id = key; list.Add(question); } callback(list, message); } }); }
// when no more questions to approve private void DisplayEmpty() { cq = null; t[0].text = "No available questions pending approval!"; t[1].text = ""; t[2].text = ""; t[3].text = ""; t[4].text = ""; }
// show next question private void DisplayNextQuestion() { if (cqs.Count < 1) { EndChallenge(); return; } ChallengeQuestion cq = cqs[0]; ShowQuestion(cq); cqs.RemoveAt(0); }
private void ShowQuestion(ChallengeQuestion questionData) { RemoveAnswerButtons(); questionDisplayText.text = questionData.description; for (int i = 0; i < 4; i++) { GameObject answerButtonGameObject = answerButtonObjectPool.GetObject(); answerButtonGameObjects.Add(answerButtonGameObject); answerButtonGameObject.transform.SetParent(answerButtonParent); AnswerButton_cmode answerButton = answerButtonGameObject.GetComponent <AnswerButton_cmode>(); answerButton.Setup(new AnswerData_Cmode(questionData.choices[i], i == questionData.idxAnswer)); } }
public void Submit() { // checking empty fields if (string.IsNullOrEmpty(t[0].text)) { Debug.LogError("Question is empty! "); return; } if (string.IsNullOrEmpty(t[1].text)) { Debug.LogError("Answer is empty! "); return; } // creating question object to be uploaded List <string> texts = new List <string>(); texts.Add(t[1].text); for (int i = 2; i < 5; i++) { if (!String.IsNullOrEmpty(t[i].text)) { texts.Add(t[i].text); } } // string question_text, List< string > choices, int correct_choice ChallengeQuestion c = new ChallengeQuestion(t[0].text, texts, 0); c.swapChoices(); // uploading to firebase FirebaseManager.getInstance().addQuestion(c, (result, msg) => { Debug.Log("Save Question: " + result + ", " + msg); if (result) { Clear(); popup.SetActive(true); t[0].text = "Added to database!"; Button btn = submitButton.GetComponent <Button>(); btn.onClick.AddListener(setScene); } else { Debug.LogWarning("Save Question failed from database!"); } }); }
public HttpResponseMessage PostChallengeQuestion(ChallengeQuestion obj) { if (obj == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } try { db.ChallengeQuestions.Add(obj); db.SaveChanges(); var result = obj; return(Request.CreateResponse(HttpStatusCode.OK, result)); } catch (Exception) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Falha ao incluir Pergunta-Desafio.")); } }
public HttpResponseMessage PutChallengeQuestion(ChallengeQuestion challengeQuestion) { if (challengeQuestion == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } try { db.Entry <ChallengeQuestion>(challengeQuestion).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); var result = challengeQuestion; return(Request.CreateResponse(HttpStatusCode.OK, result)); } catch { return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Falha ao alterar Pergunta-Desafio")); } }
// show the next question private void DisplayNextQuestion() { if (cqs.Count < 1) { DisplayEmpty(); return; } cqs.RemoveAt(0); cq = cqs[0]; t[0].text = cq.description; for (int i = 0; i < 4; i++) { t[1 + i].text = cq.choices[i]; } // swap string tmp = t[1].text; t[1].text = t[1 + cq.idxAnswer].text; t[1 + cq.idxAnswer].text = tmp; }
// DATABASE: Challenge Question /// <summary> /// saving challenge question information to database /// </summary> /// <param name="question">challenge questions to be saved</param> /// <param name="callback">callback to notifiy caller when task is finished</param> /// <exception cref="System.ArgumentNullException">Thrown when callback not provided</exception> public void saveQuestion(ChallengeQuestion question, Action <bool, string> callback) { if (callback == null) { throw new ArgumentNullException("callback is not provided"); } var refQestion = _db.RootReference.Child(ROOT_CHALLENGE_QUESTION); string json = JsonConvert.SerializeObject(question); string key = question.id != null ? question.id : refQestion.Push().Key; refQestion.Child(key).SetRawJsonValueAsync(json).ContinueWithOnMainThread((task) => { string message = readError(task); if (message != null) { Debug.Log("saveQuestion.e: " + message); callback(false, message); return; } message = "task is success"; Debug.Log("saveQuestion: " + message); callback(true, message); }); }
/// <summary> /// saving a newly submitted challenge question to firebase database /// </summary> /// <param name="question">newly submitted challenge questions</param> /// <param name="callback">callback to notify user when task is finished</param> public void addQuestion(ChallengeQuestion question, Action <bool, string> callback) { question.createrId = getFirebaseUser().UserId; saveQuestion(question, callback); }