public AnswerRequest(AnswerOptions choice, int step, string session, string signature) { Choice = choice; Step = step; Session = session; Signature = signature; }
public async Task <IHttpActionResult> PutAuthor(int id, AnswerOptions author) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != author.Id) { return(BadRequest()); } db.Entry(author).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AuthorExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken) { AnswerOptions answer = parseInput(turnContext.Activity.Text); Activity reply; if (answer != AnswerOptions.Unknown) { var nextQuestion = await client.Answer(answer); if (client.GuessIsDue(nextQuestion)) { // If the genie thinks it knows the answer, tell it var guess = await client.GetGuess(); reply = MessageFactory.Text($"My guess is: {guess[0].Name} - {guess[0].Description}"); reply.Attachments = new List <Attachment> { CreateGuessCard(guess[0]) }; } else { // Otherwise, ask the next question reply = MessageFactory.Text($"Question {nextQuestion.Step + 1}: {nextQuestion.Text}"); reply.SuggestedActions = getPossibleActions(); } } else { reply = MessageFactory.Text(($"I didn't understand that. Please enter Yes (0), No (1), Don't Know (2), Probably (3), or Probably Not (4)")); reply.SuggestedActions = getPossibleActions(); } await turnContext.SendActivityAsync(reply, cancellationToken); }
public IActionResult ManageAnswer() { var username = User.Identity.Name.ToString(); var user = UserOptions.GetUser(username); Query query = QueryOptions.Load(user, 1); Question question = QuestionOptions.Load(query, 1); Answer answer = AnswerOptions.Load(question, 1); return(View("LoadAnswer", answer)); }
public IActionResult LoadAnswer(int queryNumber, int questionNumber, int answerNumber) { var username = User.Identity.Name.ToString(); var user = UserOptions.GetUser(username); Query query = QueryOptions.Load(user, queryNumber); Question question = QuestionOptions.Load(query, questionNumber); Answer answer = AnswerOptions.Load(question, answerNumber); return(View("LoadAnswer", answer)); }
public async Task <IHttpActionResult> GetAuthor(int id) { AnswerOptions author = await db.Authors.FindAsync(id); if (author == null) { return(NotFound()); } return(Ok(author)); }
public async Task <IHttpActionResult> PostAuthor(AnswerOptions author) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Authors.Add(author); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = author.Id }, author)); }
public async Task <IHttpActionResult> DeleteAuthor(int id) { AnswerOptions author = await db.Authors.FindAsync(id); if (author == null) { return(NotFound()); } db.Authors.Remove(author); await db.SaveChangesAsync(); return(Ok(author)); }
public async Task <IActionResult> CreatePollAsync(string[] answers, Poll poll) { List <int> answerOptionId = new List <int>(); if (ModelState.IsValid) { foreach (string answer in answers) { AnswerOptions answerOption = null; answerOption = db.AnswerOptions.Where(ao => ao.Description.Equals(answer)).SingleOrDefault(); if (answerOption != null) { answerOptionId.Add(answerOption.Id); } else { answerOption = new AnswerOptions { Description = answer }; db.Add(answerOption); db.SaveChanges(); answerOptionId.Add(answerOption.Id); } } if (!poll.NeedsLocalCouncil) { poll.Approved = true; } else { poll.Approved = false; } User user = await userManager.GetUserAsync(HttpContext.User); poll.UserId = user.Id; db.Add(poll); db.SaveChanges(); foreach (int aoId in answerOptionId) { db.Add(new AnswerOptionsPoll { PollId = poll.Id, AnswerOptionsId = aoId }); db.SaveChanges(); } } return(View("Index")); }
public async Task <AkinatorQuestion> Answer(AnswerOptions answer, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); var url = AkiUrlBuilder.Answer(BuildAnswerRequest(answer), _mServer); var response = await _mWebClient.GetAsync(url, cancellationToken).ConfigureAwait(false); var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); var result = EnsureNoError <Question>(url, content); _mStep = result.Step; CurrentQuestion = ToAkinatorQuestion(result); return(CurrentQuestion); }
private void GetAnswers(string method, string[] urlParameters, Action<IPagedList<Answer>> onSuccess, Action<ApiException> onError, AnswerOptions options) { MakeRequest<AnswerResponse>(method, urlParameters, new { key = apiKey, page = options.Page ?? null, pagesize = options.PageSize ?? null, body = options.IncludeBody ? (bool?)true : null, comments = options.IncludeComments ? (bool?)true : null, sort = options.SortBy.ToString().ToLower(), order = GetSortDirection(options.SortDirection), min = options.Min ?? null, max = options.Max ?? null, fromdate = options.FromDate.HasValue ? (long?)options.FromDate.Value.ToUnixTime() : null, todate = options.ToDate.HasValue ? (long?)options.ToDate.Value.ToUnixTime() : null }, (items) => onSuccess(new PagedList<Answer>(items.Answers, items)), onError); }
public IActionResult SelectAnswer(int number, string code) { var question = QuestionOptions.GetActive(number, code, true); var answer = AnswerOptions.Load(question, number); AnswerOptions.Select(answer); question.IsAnswered = true; //return RedirectToAction("JoinQuery", "Client", new { code, question }); if (QueryOptions.ValidCode(code)) { return(View("ClientView", question)); } else { return(View("QueryClosed", question)); } }
public Entities.CQuestion Answer(AnswerOptions answer) { string AnswerUri = String.Format(ANSWER_QUESTION_URI, session, signature, step, (int)answer); string JSONNewQuestion; using (var downloadStringTask = webClient.GetStringAsync(AnswerUri)) { downloadStringTask.Wait(); JSONNewQuestion = downloadStringTask.Result; } Entities.BaseResponse <Entities.CQuestion> Response = JsonConvert.DeserializeObject <Entities.BaseResponse <Entities.CQuestion> >(JSONNewQuestion, new JsonSerializerSettings() { MissingMemberHandling = MissingMemberHandling.Ignore }); Question = Response.Parameters; step = Response.Parameters.Step; return(Response.Parameters); }
public async Task <AkinatorQuestion> Answer(AnswerOptions answer, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var url = AkiUrlBuilder.Answer(BuildAnswerRequest(answer), m_usedLanguage, m_usedServerType); var response = await m_webClient.GetAsync(url, cancellationToken).ConfigureAwait(false); var content = await response.Content.ReadAsStringAsync(); var result = JsonConvert.DeserializeObject <BaseResponse <Question> >(content, new JsonSerializerSettings() { MissingMemberHandling = MissingMemberHandling.Ignore }); m_step = result.Parameters.Step; return(ToAkinatorQuestion(result.Parameters)); }
private static int DoAnswer(AnswerOptions answer) { switch (answer.Execute()) { case AnswerOptions.CallAnswer.NoCallToAnswerFound: LoggingUtil.Log(EventLogEntryType.Warning, EventLogIds.NoCallAtAll.Id(), "No call found."); return(0); case AnswerOptions.CallAnswer.LastCallAlreadyAnswered: LoggingUtil.Log(EventLogEntryType.Information, EventLogIds.CallAlreadyAnswered.Id(), "No new call to answer."); return(0); case AnswerOptions.CallAnswer.CallAnswered: LoggingUtil.Log(EventLogEntryType.Information, EventLogIds.CallAnswered.Id(), "New call answered."); return(0); default: throw new ArgumentOutOfRangeException(); } }
public virtual void GetQuestionAnswers(int questionId, Action<IPagedList<Answer>> onSuccess, Action<ApiException> onError, AnswerOptions options) { GetUsersAnswers(questionId.ToArray(), onSuccess, onError, options); }
protected override void Validate() { //题目创建用户不存在 if (!UsersAccessor.Exists(UserId)) { AddBrokenRule(NewQuestionFailureRule.QUESTION_CREATOR_NOT_EXISTS); } //题目所属课程不存在 if (!CourseAccessor.Exists(CourseId)) { AddBrokenRule(NewQuestionFailureRule.COURSE_NOT_EXISTS); } //题目类型无效 if (!((IList <int>)Enum.GetValues(typeof(QuestionType))).Contains(Type)) { AddBrokenRule(NewQuestionFailureRule.QUESTION_TYPE_ERROR); } //题目标题不能为空 if (string.IsNullOrWhiteSpace(Topic)) { AddBrokenRule(NewQuestionFailureRule.TOPIC_CANNOT_EMPTY); } // 如果->非问答题且答案项为NULL,则抛出错误; // 否则->题目类型与答案项进能校验,校验规则如下: // 1、匹配,则验证答案项设置是否有效 // 2、不匹配,则添加业务错误 if (Type != (int)QuestionType.ESSAY_QUESTION && AnswerOptions == null) { AddBrokenRule(NewQuestionFailureRule.ANSWER_OPTIONS_CANNOT_EMPTY); } else if (QuestionTools.CheckAnswerOptionsType(AnswerOptions, Type)) { //题目的答案项验证失败 if (!AnswerOptions.Validate()) { if (AnswerOptions is SingleChoiceAnswer) { AddBrokenRule(NewQuestionFailureRule.SINGLE_CHOICE_ANSWER_OPTIONS_ERROR); } else if (AnswerOptions is MultipleChoiceAnswer) { AddBrokenRule(NewQuestionFailureRule.MULTIPLE_CHOICE_ANSWER_OPTIONS_ERROR); } else if (AnswerOptions is TrueFalseAnswer) { AddBrokenRule(NewQuestionFailureRule.TRUE_FALSE_ANSWER_OPTIONS_ERROR); } else if (AnswerOptions is GapFillingAnswer) { AddBrokenRule(NewQuestionFailureRule.GAP_FILLING_ANSWER_OPTIONS_ERROR); } } } else { AddBrokenRule(NewQuestionFailureRule.QUESTION_TYPE_AND_ANSWER_OPTIONS_REGEX_FAILURE); } }
public IActionResult SaveAnswer(Answer answer) { AnswerOptions.Save(answer); return(RedirectToAction("ManageQuestion", "Question", new { queryNumber = answer.QueryNumber, questionNumber = answer.QuestionNumber })); }
public Task <AkinatorQuestion> Answer(AnswerOptions answer) => Answer(answer, CancellationToken.None);
private AnswerRequest BuildAnswerRequest(AnswerOptions choice) => new AnswerRequest(choice, m_step, m_session, m_signature);
public async Task <IActionResult> CreatePollAsync([FromBody] CreatePollModel createPoll) { if (ModelState.IsValid) { Concern concern = db.Concern.Where(c => c.Id == createPoll.ConcernId).SingleOrDefault(); int concernStatusId = concern.StatusId; concern.StatusId = 5; db.Update(concern); int userId = (await userManager.GetUserAsync(HttpContext.User)).Id; List <int> answerOptionId = new List <int>(); Poll poll = new Poll { Text = createPoll.Text, Title = createPoll.Title, End = createPoll.End, NeedsLocalCouncil = createPoll.NeedsLocalCouncil, LastUpdatedBy = userId, LastUpdatedAt = DateTime.UtcNow, UserId = userId, StatusId = 2, CategoryId = createPoll.CategoryId }; foreach (string answer in createPoll.Answers) { AnswerOptions answerOption = null; answerOption = db.AnswerOptions.Where(ao => ao.Description.Equals(answer)).SingleOrDefault(); if (answerOption != null) { answerOptionId.Add(answerOption.Id); } else { answerOption = new AnswerOptions { Description = answer }; db.Add(answerOption); //db.SaveChanges(); answerOptionId.Add(answerOption.Id); } } if (!poll.NeedsLocalCouncil) { poll.Approved = true; } else { poll.Approved = false; } db.Add(poll); //db.SaveChanges(); foreach (int aoId in answerOptionId) { db.Add(new AnswerOptionsPoll { PollId = poll.Id, AnswerOptionsId = aoId }); //db.SaveChanges(); } int result = db.SaveChanges(); return(Json(new { result, concernStatusId, concernId = createPoll.ConcernId })); } else { return(Json(new { result = 0 })); } }
public async Task <IActionResult> CreatePollAsync([FromBody] CreatePollModel createPoll) { if (ModelState.IsValid) { //Variablen int concernStatusId = 0; int userId = (await userManager.GetUserAsync(HttpContext.User)).Id; List <int> answerOptionId = new List <int>(); Poll poll = new Poll { Text = createPoll.Text, Title = createPoll.Title, End = createPoll.End, NeedsLocalCouncil = createPoll.NeedsLocalCouncil, LastUpdatedBy = userId, LastUpdatedAt = DateTime.UtcNow, UserId = userId, StatusId = 2, CategoryId = createPoll.CategoryId }; //Nur, wenn Umfrage aus Anliegen erstellt wird, wird das Anliegen auf Status "abgeschlossen" gesetzt. if (createPoll.ConcernId != 0) { Concern concern = db.Concern.Where(c => c.Id == createPoll.ConcernId).SingleOrDefault(); concernStatusId = 6; //concern.StatusId; concern.StatusId = concernStatusId; db.Update(concern); } //Antworten aus Objekt auslesen und in Datenbank speichern foreach (string answer in createPoll.Answers) { AnswerOptions answerOption = null; //Prüfung, ob Antwort schon einmal verwendet wurde answerOption = db.AnswerOptions.Where(ao => ao.Description.Equals(answer)).SingleOrDefault(); if (answerOption != null) { answerOptionId.Add(answerOption.Id); } else { answerOption = new AnswerOptions { Description = answer }; db.Add(answerOption); answerOptionId.Add(answerOption.Id); } } if (!poll.NeedsLocalCouncil) { poll.Approved = true; } else { poll.Approved = false; } //Umfrage Speichern db.Add(poll); //Antworten Speichern foreach (int aoId in answerOptionId) { db.Add(new AnswerOptionsPoll { PollId = poll.Id, AnswerOptionsId = aoId }); } //Dokumente aus dem Anliegen in die Umfrage übernehmen if (createPoll.FileIds != null) { foreach (int fileId in createPoll.FileIds) { File file = db.File.Where(f => f.Id == fileId).SingleOrDefault(); file.PollId = poll.Id; db.Update(file); } } //Bilder aus dem Anliegen in die Umfrage übernehmen if (createPoll.ImageIds != null) { foreach (int imageId in createPoll.ImageIds) { Image image = db.Image.Where(i => i.Id == imageId).SingleOrDefault(); image.PollId = poll.Id; db.Update(image); } } //Commit int result = db.SaveChanges(); return(Json(new { result, concernStatusId, concernId = createPoll.ConcernId })); } return(Json(new { result = 0 })); }
public virtual void GetQuestionAnswers(IEnumerable<int> questionIds, Action<IPagedList<Answer>> onSuccess, Action<ApiException> onError, AnswerOptions options) { GetAnswers("questions", new string[] { questionIds.Vectorize(), "answers" }, onSuccess, onError, options); }
public new async Task <AkinatorQuestion> Answer(AnswerOptions option, CancellationToken cancellationToken = default) { return(await Measure(base.Answer, cancellationToken, option)); }
private AnswerRequest BuildAnswerRequest(AnswerOptions choice) => new AnswerRequest(choice, _mStep, _mSession, _mSignature);