void Buzz_Clicked(System.Object sender, System.EventArgs e) { QuizzingPageViewModel qVm = (QuizzingPageViewModel)this.BindingContext; if (qVm.isStarted) { qVm.isStarted = false; qVm.IsReading = true; qVm.Read(); } else { if (qVm.IsReading) { qVm.IsReading = false; AnswerEntry.Focus(); } else { if (!string.IsNullOrWhiteSpace(qVm.AnsweredText)) { qVm.CheckAnswer(); MainButton.IsEnabled = false; } else { qVm.IsReading = true; AnswerEntry.Unfocus(); qVm.Read(); } } } }
public GQuestionMenuEntry(int x, int y, int xWidth, AnswerEntry a) : base(x, y) { this.m_yBase = y; this.m_Answer = a; this.m_Radio = new GRadioButton(210, 211, false, 0, 0); this.m_Label = (GLabel) new GWrappedLabel(a.Text, (IFont)Engine.GetFont(1), Hues.Load(1109), this.m_Radio.Width + 4, 5, xWidth - this.m_Radio.Width - 4); this.m_Width = xWidth; this.m_Height = this.m_Radio.Height; if (this.m_Label.Y + this.m_Label.Height > this.m_Height) { this.m_Height = this.m_Label.Y + this.m_Label.Height; } this.m_Children.Add((Gump)this.m_Radio); this.m_Children.Add((Gump)this.m_Label); }
public object Any(Answer request) { Guid userId = UserSession.GetUserId(); TableRepository tableRepository = new TableRepository(); // create answers AnswerEntry answerEntry = tableRepository.Get <AnswerEntry>(Tables.Answers, request.QuestionId, userId); if (answerEntry == null) { DateTime dateTime = DateTime.UtcNow; answerEntry = new AnswerEntry(request.QuestionId, userId) { Content = request.Content, Creation = dateTime, Modification = dateTime, Votes = 0 }; // update the answers count QuestionEntry questionEntry = tableRepository.Get <QuestionEntry>(Tables.Questions, request.QuestionOwnerId, request.QuestionId); if (questionEntry != null) { questionEntry.Answers++; tableRepository.InsertOrMerge(questionEntry, Tables.Questions); } } else { // perform an edit answerEntry.Content = request.Content; answerEntry.Modification = DateTime.UtcNow; } tableRepository.InsertOrMerge(answerEntry, Tables.Answers); AnswerResponse response = new AnswerResponse { Result = ErrorCode.OK }; return(response); }
public object Any(Vote request) { Guid userId = UserSession.GetUserId(); VoteResponse response = new VoteResponse { Result = ErrorCode.OK, }; TableRepository tableRepository = new TableRepository(); UserQuestionEntry userQuestionEntry = tableRepository.Get <UserQuestionEntry>(Tables.UserQuestion, request.QuestionId, userId); // Création d'un nouveau vote if (userQuestionEntry == null) { DateTime dateTime = DateTime.UtcNow; userQuestionEntry = new UserQuestionEntry(request.QuestionId, userId) { Creation = dateTime, Modification = dateTime }; } else { userQuestionEntry.Modification = DateTime.UtcNow; } Guid target = request.VoteTarget == VoteTarget.Question ? request.QuestionId : request.OwnerId; HashSet <string> votesUp = new HashSet <string>(userQuestionEntry.VotesUp?.Split('|') ?? new string[] { }); HashSet <string> votesDown = new HashSet <string>(userQuestionEntry.VotesDown?.Split('|') ?? new string[] { }); VoteKind oldValue = VoteKind.None; if (votesUp.Contains(target.ToString())) { oldValue = VoteKind.Up; } else if (votesDown.Contains(target.ToString())) { oldValue = VoteKind.Down; } response.VoteKind = request.VoteKind; votesUp.Remove(target.ToString()); votesDown.Remove(target.ToString()); if (response.VoteKind == oldValue) { response.VoteKind = VoteKind.None; } else { switch (response.VoteKind) { case VoteKind.Up: votesUp.Add(target.ToString()); break; case VoteKind.Down: votesDown.Add(target.ToString()); break; } } userQuestionEntry.VotesUp = votesUp.Join("|"); userQuestionEntry.VotesDown = votesDown.Join("|"); if (request.VoteTarget == VoteTarget.Answer) { AnswerEntry answerEntry = tableRepository.Get <AnswerEntry>(Tables.Answers, request.QuestionId, request.OwnerId); answerEntry.Votes -= (int)oldValue; answerEntry.Votes += (int)response.VoteKind; tableRepository.InsertOrMerge(answerEntry, Tables.Answers); response.VoteValue = answerEntry.Votes; // badges if (response.VoteKind == VoteKind.Up) { switch (answerEntry.Votes) { case 1: AllBadges.Approved.CreateIfNotExist(tableRepository, answerEntry.GetAnswerOwnerId()); break; case 10: AllBadges.NiceAnswer.CreateForQuestion(tableRepository, answerEntry.GetAnswerOwnerId(), request.QuestionId); break; case 25: AllBadges.GoodAnswer.CreateForQuestion(tableRepository, answerEntry.GetAnswerOwnerId(), request.QuestionId); break; case 100: AllBadges.GreatAnswer.CreateForQuestion(tableRepository, answerEntry.GetAnswerOwnerId(), request.QuestionId); break; } } } else { QuestionEntry questionEntry = tableRepository.Get <QuestionEntry>(Tables.Questions, request.OwnerId, request.QuestionId); questionEntry.Votes -= (int)oldValue; questionEntry.Votes += (int)response.VoteKind; tableRepository.InsertOrMerge(questionEntry, Tables.Questions); response.VoteValue = questionEntry.Votes; // badges if (response.VoteKind == VoteKind.Up) { switch (questionEntry.Votes) { case 1: AllBadges.Padawan.CreateIfNotExist(tableRepository, questionEntry.GetOwnerId()); break; case 10: AllBadges.NiceQuestion.CreateForQuestion(tableRepository, questionEntry.GetOwnerId(), request.QuestionId); break; case 25: AllBadges.GoodQuestion.CreateForQuestion(tableRepository, questionEntry.GetOwnerId(), request.QuestionId); break; case 100: AllBadges.GreatQuestion.CreateForQuestion(tableRepository, questionEntry.GetOwnerId(), request.QuestionId); break; } } } // insert le vote tableRepository.InsertOrReplace(userQuestionEntry, Tables.UserQuestion); // badges if (response.VoteKind == VoteKind.Up) { AllBadges.Supporter.CreateIfNotExist(tableRepository, userId); } else if (response.VoteKind == VoteKind.Down) { AllBadges.Critic.CreateIfNotExist(tableRepository, userId); } return(response); }