private async Task <Question[]> GetQuestions() { Question question1 = await GetQuestion(); if (question1 == null) { return(null); } if (question1.Get <bool>("inBundle")) { Bundle = question1.Get <QuestionBundle>("bundle"); await Bundle.FetchAsync(); IList <Question> questions = Bundle.Get <IList <Question> >("questions"); foreach (Question question in questions) { await question.FetchIfNeededAsync(); } return(questions.ToArray()); } else { return(new Question[1] { question1 }); } }
private QuestionBundle SaveBundle() { QuestionBundle b; if (IsEditMode) { b = Bundle; } else { b = new QuestionBundle(); } b["passageText"] = tbPassage.Text; if (FileUpload0.HasFile) { b["image"] = Upload(FileUpload0); } b.ACL = new ParseACL(); b.ACL.PublicReadAccess = true; b.ACL.PublicWriteAccess = false; b.ACL.SetRoleWriteAccess(TutorRole, true); Task t1 = b.SaveAsync(); t1.Wait(); return(b); }
private async Task<Question[]> GetQuestions() { Question question1 = await GetQuestion(); if (question1 == null) return null; if (question1.Get<bool>("inBundle")) { Bundle = question1.Get<QuestionBundle>("bundle"); await Bundle.FetchAsync(); IList<Question> questions = Bundle.Get<IList<Question>>("questions"); foreach (Question question in questions) await question.FetchIfNeededAsync(); return questions.ToArray(); } else { return new Question[1] { question1 }; } }
private QuestionBundle SaveBundle() { QuestionBundle b; if (IsEditMode) b = Bundle; else b = new QuestionBundle(); b["passageText"] = tbPassage.Text; if (FileUpload0.HasFile) b["image"] = Upload(FileUpload0); b.ACL = new ParseACL(); b.ACL.PublicReadAccess = true; b.ACL.PublicWriteAccess = false; b.ACL.SetRoleWriteAccess(TutorRole, true); Task t1 = b.SaveAsync(); t1.Wait(); return b; }
protected void btnSubmitQuestion_Click(object sender, EventArgs e) { if (!ValidateQuestions()) { pnlError.Visible = true; return; } pnlError.Visible = false; if (IsEditMode) { List <Task> tasks = new List <Task>(); QuestionContents contents1 = CreateContents1(); QuestionData data1 = CreateData1(); Question question1 = CreateQuestion1(contents1, data1); if (IsBundle) { QuestionBundle bundle = SaveBundle(); } AsyncHelpers.RunSync(contents1.SaveAsync); AsyncHelpers.RunSync(data1.SaveAsync); AsyncHelpers.RunSync(question1.SaveAsync); } else { List <Task> tasks = new List <Task>(); QuestionContents contents1 = CreateContents1(); QuestionData data1 = CreateData1(); Question question1 = CreateQuestion1(contents1, data1); if (IsBundle) { QuestionBundle bundle = SaveBundle(); question1["inBundle"] = true; question1["bundle"] = bundle; QuestionContents contents2 = CreateContents2(); QuestionData data2 = CreateData2(); Question question2 = CreateQuestion2(contents2, data2, bundle); QuestionContents contents3 = CreateContents3(); QuestionData data3 = CreateData3(); Question question3 = CreateQuestion3(contents3, data3, bundle); tasks.Add(contents1.SaveAsync()); tasks.Add(contents2.SaveAsync()); tasks.Add(contents3.SaveAsync()); tasks.Add(data1.SaveAsync()); tasks.Add(data1.SaveAsync()); tasks.Add(data1.SaveAsync()); foreach (Task t in tasks) { t.Wait(); } Task t1 = question1.SaveAsync(); Task t2 = question2.SaveAsync(); Task t3 = question3.SaveAsync(); t1.Wait(); t2.Wait(); t3.Wait(); bundle["questions"] = new ParseObject[] { question1, question2, question3 }; Task t4 = bundle.SaveAsync(); t4.Wait(); } else { Task t1 = contents1.SaveAsync(); Task t2 = data1.SaveAsync(); t1.Wait(); t2.Wait(); Task t3 = question1.SaveAsync(); t3.Wait(); } } Session["QuestionObjectId"] = null; Response.Redirect("UploadQuestion?success=true"); }