public async Task <ApiModels.AnswerResult> SaveAnswer(ApiModels.Answer answer) { if (string.IsNullOrEmpty(answer.AnswerText)) { throw new ArgumentNullException("Answer text is null"); } var question = QuestionCache.Where(q => q.Id == answer.QuestionID).FirstOrDefault(); var result = CheckAnswer(question, answer); UpdateUserPairScoreRepository(question, true, answer.UserId, answer.DictionaryId); if (result) { await UpdateQuestionRepository(question, answer); } var answerResult = new ApiModels.AnswerResult() { IsCorrect = result }; await RefreshCaches(true); return(answerResult); }
public ActionResult <dynamic> CreateQuestion(QuestionCache cache) { Question question; string message = string.Empty; if (!string.IsNullOrEmpty(cache.question)) { question = new Question() { question = HttpUtility.UrlDecode(cache.question), created_at = DateTimeOffset.UtcNow, deleted = false }; context.questions.Add(question); context.SaveChanges(); log.Information("Create new question, id -> " + question.question_id); return(new { success = true, data = new { question = question } }); } else { message = "Question can't be empty."; } return(Error500(message)); }
public ActionResult <dynamic> UpdateQuestion(QuestionCache cache) { Question question; string message = string.Empty; if (!string.IsNullOrEmpty(cache.question)) { if ((question = context.questions.Where(q => q.question_id == cache.question_id && !q.deleted).FirstOrDefault()) != null) { question.question = HttpUtility.UrlDecode(cache.question); context.questions.Update(question); context.SaveChanges(); log.Information("Update question, id -> " + question.question_id); return(new { success = true, data = new { question = question } }); } else { message = "Server can't define question by id."; } } else { message = "Question can't be empty."; } return(Error500(message)); }
public ActionResult <dynamic> DeleteQuestion(QuestionCache cache) { Question question; string message = string.Empty; if ((question = context.questions.Where(q => q.question_id == cache.question_id && !q.deleted).FirstOrDefault()) != null) { question.deleted = true; context.questions.Update(question); context.SaveChanges(); log.Information("Delete question, id -> " + question.question_id); return(new { success = true }); } else { message = "Server can't define question by id."; } return(Error500(message)); }