void endAPICall(HTTPRequest req, HTTPResponse res) { // deserialize json question = JsonMapper.ToObject<QuestionModel> (res.DataAsText); // save questionId PlayerPrefs.SetString ("questionId", question._id); // end spinning callingAPI = false; }
void questionReady(HTTPRequest req, HTTPResponse res) { float delay = ((Time.time - startTime) < (Properties.starQuestionDelay - Properties.delayQuestionStart)) ? Properties.starQuestionDelay : Properties.delayQuestionStart; // parse response question = JsonMapper.ToObject<QuestionModel> (res.DataAsText); // save questionId PlayerPrefs.SetString ("questionId", question._id); // deay action and launch question Utils.delayAction (this, () => { // dispatch event to start question _dispatcher.Dispatch ("question_loaded", question); // fadeout panel Utils.fadeOutPanel (this, panel, Properties.starQuestionFadeInOutDuration, executeQuestion); }, delay); }
public ActionResult Thanks(QuestionModel model) { CookieService cookie=new CookieService(); Alternative alternative = _db.Alternatives.Single(a => a.Id == model.AlternativeId); Question question = _db.Questions.Single(q => q.Id == model.QuestionId); if (cookie.VoteAllowed(question.Id)) { alternative.Votes++; _db.SaveChanges(); cookie.MakeVoteAuthenticate(question.Id); return View(question); } else return View("VoteDenied",question); }
void buildScene(Object data) { question = (QuestionModel)data; // reset question-answers _dispatcher.Dispatch ("reset_answers"); _dispatcher.Dispatch("message_wrong_hide"); _dispatcher.Dispatch("message_correct_hide"); // set background color setBackgroundColor (); // set quote setQuote (); // set answers setAnswers (); // show question show (); // open quote openQuote (); // start countdown startCountdown (); }
private void SaveAnswerBtnClicked(object sender, RoutedEventArgs e) { AdminWindowVM aw = (AdminWindowVM)this.DataContext; if(CurrentQuestion.Equals(Guid.Empty)) return; QuestionContentRTB.SelectAll(); #region Validate Fields if (QuestionContentRTB.Selection.Text == "") { MessageBox.Show("Question is not defined"); return; } if(AnswersDictionary.Count ==0) { MessageBox.Show("No answers added"); return; } if (AnswersDictionary.Count != 0) { bool IsanswrsEmpty = true; for (int i = 0; i < AnswersCount; i++) { if (AnswersDictionary.ContainsKey(i)) { try { RichTextBox tb = (RichTextBox)AnswersStackPannel.FindName("AnswerRTB" + i.ToString()); tb.SelectAll(); if (tb.Selection.Text.Trim() != "") { IsanswrsEmpty = false; } } catch { } } } if (IsanswrsEmpty) { MessageBox.Show("No answers added"); return; } } if (AnswersDictionary.Count != 0) { bool IsAChecked = false; for (int i = 0; i < AnswersCount; i++) { if (AnswersDictionary.ContainsKey(i)) { try { RadioButton rb = (RadioButton)AnswersStackPannel.FindName("AnswerRadioButton" + i.ToString()); if ((bool)rb.IsChecked) { IsAChecked = true; } } catch { } } } if (!IsAChecked) { MessageBox.Show("Select Correct Answer"); return; } } #endregion QuestionModel Question = new QuestionModel(); Question.Answers = new List<AnswersModel>(); Question.Images = new List<ImageModel>(); Question.QID = CurrentQuestion; Question.QBody = QuestionContentRTB.Selection.Text.Trim(); Question.HasMultipleAnswers = false; if (ImageDictionary.Count != 0) Question.HasImages = true; for (int i = 0; i < AnswersCount; i++) { if (AnswersDictionary.ContainsKey(i)) { RichTextBox tb = (RichTextBox)AnswersStackPannel.FindName("AnswerRTB" + i.ToString()); tb.SelectAll(); if (tb.Selection.Text.Trim() != "") { AnswersModel answer = new AnswersModel(); answer.QID = Question.QID; answer.AID = Guid.NewGuid(); answer.AnswerBody = tb.Selection.Text.Trim(); RadioButton rb = (RadioButton)AnswersStackPannel.FindName("AnswerRadioButton" + i.ToString()); answer.IsCorrectAnswer = (bool)rb.IsChecked; Question.Answers.Add(answer); } } } for (int i = 0; i < ImagesCount; i++) { if (ImageDictionary.ContainsKey(i)) { try { byte[] picbyte = null; Image img = (Image)ImagesStackPanel.FindName("QImage" + i.ToString()); BitmapImage bimg = (BitmapImage)img.Source; if (bimg.UriSource == null) { picbyte = ((MemoryStream)bimg.StreamSource).ToArray(); } else { FileStream fs = new FileStream(bimg.UriSource.LocalPath.ToString(), FileMode.Open, FileAccess.Read); picbyte = new byte[fs.Length]; fs.Read(picbyte, 0, System.Convert.ToInt32(fs.Length)); fs.Close(); } ImageModel imodel = new ImageModel(); imodel.QID = Question.QID; imodel.ImageID = Guid.NewGuid(); imodel.Image = picbyte; Question.Images.Add(imodel); } catch { } } } CRUDManager dm = new CRUDManager(); if (dm.UpdateQuestion(Question)) { aw.QList[ComboboxIndex] = ConvertModelToVM(Question); QuestionEditSelectCombobox.SelectedIndex = 0; } else { MessageBox.Show("Question Save Failed"); return; } }
private QuestionVM ConvertModelToVM(QuestionModel Question) { if (Question == null) return null; QuestionVM qvm = new QuestionVM(); qvm.QID = Question.QID; qvm.QBody = Question.QBody; if (qvm.QBody.Length > 40) { qvm.QHeader = qvm.QBody.Substring(0, 40) + "..."; } else qvm.QHeader = qvm.QBody; qvm.HasImages = Question.HasImages; qvm.Answers = new ObservableCollection<AnswersVM>(); for (int j = 0; j < Question.Answers.Count; j++) { AnswersVM a = new AnswersVM(); a.AID = Question.Answers[j].AID; a.QID = Question.Answers[j].QID; a.AnswerBody = Question.Answers[j].AnswerBody; a.IsCorrectAnswer = Question.Answers[j].IsCorrectAnswer; qvm.Answers.Add(a); } qvm.Images = new ObservableCollection<ImageModel>(); for (int j = 0; j < Question.Images.Count; j++) { qvm.Images.Add(Question.Images[j]); } return qvm; }
public ActionResult Question(int questionIndex1Based) { QuestionModel model = new QuestionModel(questionIndex1Based); return View(model); }
public async Task <ActionResult <IEnumerable <QuestionModel> > > putQuestion(int areaId, int courseId, int lessonId, [FromBody] QuestionModel question, int questionId) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var resp = await service.putQuestionAsync(areaId, courseId, lessonId, question, questionId); ResponseIdModel rsp = new ResponseIdModel(); rsp.id = resp.Id.GetValueOrDefault(); return(Created($"api/Area/{areaId:int}/Course/{courseId:int}/Lesson/{lessonId:int}/Question/{resp.Id:int}", rsp)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public LawQuestionsModel GetQuestionsForLaw(int lawID, string userID) { var auService = new AnonymousUserService(); using (var context = JavnaRasprava.WEB.DomainModels.ApplicationDbContext.Create()) { var law = context.Laws .Where(x => x.LawID == lawID) .Include("Questions.UserRepresentativeQuestions.Representative.Party") .FirstOrDefault(); if (law == null) { return(null); } var result = new LawQuestionsModel { LawID = lawID, Law = law, Questions = new List <QuestionModel>(), }; result.TotalQuestionsMade = law.Questions.SelectMany(x => x.UserRepresentativeQuestions).Count(); if (result.TotalQuestionsMade == 0) { return(result); } var lawQuestionCounts = law.Questions .Where(x => x.Verified) .SelectMany(x => x.UserRepresentativeQuestions) .GroupBy(x => x.QuestionID) .Select(g => new { QuestionId = g.Key, Count = g.Count() }) .ToList(); var representativeQuestionCount = law.Questions .Where(x => x.Verified) .SelectMany(x => x.UserRepresentativeQuestions) .GroupBy(x => new { x.RepresentativeID, x.QuestionID }) .Select(g => new { g.Key.QuestionID, g.Key.RepresentativeID, Count = g.Count() }) .ToList(); var representativeIDs = law.Questions .Where(x => x.Verified) .SelectMany(x => x.UserRepresentativeQuestions) .Select(x => x.RepresentativeID) .ToList(); var questionIDs = law.Questions .Where(x => x.Verified) .Select(x => x.QuestionID).ToList(); var questionLikeCounts = context.QuestionLikes .Where(x => questionIDs.Contains(x.QuestionID)) .GroupBy(x => new { x.QuestionID, x.Vote }) .Select(g => new { QuestionID = g.Key.QuestionID, Vote = g.Key.Vote, Count = g.Count() }) .ToList(); var userQuestionLikes = context.QuestionLikes .Where(x => questionIDs.Contains(x.QuestionID) && x.ApplicationUserID == userID) .ToList(); var answers = context.Answers .Where(x => representativeIDs.Contains(x.RepresentativeID) && questionIDs.Contains(x.QuestionID)) .ToList(); var answerIDs = answers.Select(x => x.AnswerID).ToList(); var answerLikesCounts = context.AnswerLikes .Where(x => answerIDs.Contains(x.AnswerID)) .GroupBy(x => new { x.AnswerID, x.Vote }) .Select(g => new { AnswerID = g.Key.AnswerID, Vote = g.Key.Vote, Count = g.Count() }) .ToList(); var userAnswerLikes = context.AnswerLikes .Where(x => x.ApplicationUserID == userID && answerIDs.Contains(x.AnswerID)) .ToList(); foreach (var question in law.Questions.Where(x => x.Verified)) { QuestionModel qmodel = PopulateQuestionModel(question); qmodel.AskedCount = lawQuestionCounts.Where(x => x.QuestionId == question.QuestionID).Select(x => x.Count).FirstOrDefault(); qmodel.LikesCount = questionLikeCounts.Where(x => x.QuestionID == question.QuestionID && x.Vote).Select(x => x.Count).FirstOrDefault(); qmodel.DislikesCount = questionLikeCounts.Where(x => x.QuestionID == question.QuestionID && !x.Vote).Select(x => x.Count).FirstOrDefault(); var userQuestionLike = userQuestionLikes.Where(x => x.ApplicationUserID == userID && x.QuestionID == question.QuestionID).FirstOrDefault(); if (!string.IsNullOrWhiteSpace(userID)) { qmodel.UserLiked = userQuestionLike == null ? (bool?)null : userQuestionLike.Vote; } else { qmodel.UserLiked = auService.GetUserQuestionLike(question.QuestionID); } qmodel.Representatives = new List <QustionRepresentativeModel>(); foreach (var rep in question.UserRepresentativeQuestions.Select(x => x.Representative)) { // Collection has item per question so it has to be added only once if (qmodel.Representatives.Any(x => x.ID == rep.RepresentativeID)) { continue; } QustionRepresentativeModel repModel = PopulateQuestionRepresentativeModel(rep); repModel.AskedCount = representativeQuestionCount .Where(x => x.QuestionID == question.QuestionID && x.RepresentativeID == rep.RepresentativeID) .Select(x => x.Count) .First(); var answer = answers.Where(x => x.RepresentativeID == rep.RepresentativeID && x.QuestionID == question.QuestionID).FirstOrDefault(); if (answer != null) { repModel.Answered = true; repModel.Answer = PopulateAnswerModel(answer); repModel.Answer.LikesCount = answerLikesCounts.Where(x => x.AnswerID == answer.AnswerID && x.Vote).Select(x => x.Count).FirstOrDefault(); repModel.Answer.DislikesCount = answerLikesCounts.Where(x => x.AnswerID == answer.AnswerID && !x.Vote).Select(x => x.Count).FirstOrDefault(); if (!string.IsNullOrWhiteSpace(userID)) { var userAnswer = userAnswerLikes.Where(x => x.AnswerID == answer.AnswerID && x.ApplicationUserID == userID).FirstOrDefault(); repModel.Answer.UserLiked = userAnswer == null ? (bool?)null : userAnswer.Vote; } else { repModel.Answer.UserLiked = auService.GetUserAnswerLike(answer.AnswerID); } } qmodel.Representatives.Add(repModel); } qmodel.AnswersCount = qmodel.Representatives.Count(x => x.Answered); result.Questions.Add(qmodel); } return(result); } }
/// <summary> /// Get questions from imported file. /// </summary> /// <param name="fileId"> /// Imported file id. /// </param> /// <param name="smiId"> /// Sub module item id. /// </param> /// <param name="userId"> /// The user Id. /// </param> /// <param name="format"> /// Questions format. /// </param> /// <returns> /// The <see cref="ServiceResponse"/>. /// </returns> protected QuestionDTO[] Import(string fileId, int?smiId, int?userId, FormatsEnum format) { var questionDtos = new List <QuestionDTO>(); Error error = null; try { SubModuleItem subModuleItem = smiId.HasValue ? this.SubModuleItemModel.GetOneById(smiId.Value).Value : null; User creator = userId.HasValue ? this.UserModel.GetOneById(userId.Value).Value : null; string fileName = fileId + ".xml"; string filePath = Path.Combine(this.ImportPath, fileName); string schemaPath = Path.Combine(this.SchemasPath, format + ".xsd"); if (subModuleItem == null && creator == null) { throw new ArgumentException(); } EdugameQuestions questions = this.DeserializeEdugameQuestions(format, filePath, schemaPath); QuestionModel questionModel = this.QuestionModel; DistractorModel distractorModel = this.DistractorModel; Func <string, string, File> saveImage = this.GetSaveImageRutine(subModuleItem, creator); List <QuestionType> questionTypes = this.QuestionTypeModel.GetAllActive().ToList(); foreach (EdugameQuestion question in questions.Questions) { Question convertedQuestion = EdugameConverter.Convert(question, questionTypes); convertedQuestion.SubModuleItem = subModuleItem; if (convertedQuestion.CreatedBy == null) { convertedQuestion.CreatedBy = subModuleItem.Return(x => x.CreatedBy, creator); } if (convertedQuestion.ModifiedBy == null) { convertedQuestion.ModifiedBy = convertedQuestion.CreatedBy; } File questionImage = saveImage(question.ImageName, question.Image); if (questionImage != null) { convertedQuestion.Image = questionImage; } convertedQuestion.RandomizeAnswers = convertedQuestion.QuestionType.Id == (int)QuestionTypeEnum.Sequence ? (bool?)true : null; if (subModuleItem != null) { questionModel.RegisterSave(convertedQuestion); } QuestionFor customQuestion = this.ProcessCustomQuestionType(convertedQuestion, question); ProcessDistractors(question, convertedQuestion, saveImage, subModuleItem, creator, distractorModel); questionDtos.Add(new QuestionDTO(convertedQuestion, customQuestion)); } System.IO.File.Delete(filePath); } catch (ArgumentException) { error = new Error( Errors.CODE_ERRORTYPE_REQUEST_NOT_PROCESSED, ErrorsTexts.ImportError_Subject, ErrorsTexts.ImportError_NoData); } catch (SerializationException) { error = new Error( Errors.CODE_ERRORTYPE_REQUEST_NOT_PROCESSED, ErrorsTexts.ImportError_Subject, ErrorsTexts.ImportError_InvalidFormat); } catch (FileNotFoundException) { error = new Error( Errors.CODE_ERRORTYPE_REQUEST_NOT_PROCESSED, ErrorsTexts.ImportError_Subject, ErrorsTexts.ImportError_NotFound); } catch (Exception ex) { Logger.Error("Import", ex); error = new Error( Errors.CODE_ERRORTYPE_REQUEST_NOT_PROCESSED, ErrorsTexts.ImportError_Subject, ErrorsTexts.ImportError_Unknown); } if (error != null) { this.LogError("Export.Import", error); throw new FaultException <Error>(error, error.errorMessage); } return(questionDtos.ToArray()); }