public async Task <ActionResult <QuestionContract> > NextQuestion(string sessionId) { if (_sessions.Any(x => x.SessionId == sessionId)) // existing session { var session = _sessions.First(x => x.SessionId == sessionId); var remainingQuestions = _questionList.Questions.Where(q => !session.Questions.Any(sq => sq.Id == q.Id)).ToArray(); if (remainingQuestions.Length == 0) { return(NotFound()); } var question = remainingQuestions[new Random().Next(remainingQuestions.Count())]; session.Questions.Add(question); var contract = new QuestionContract(question.Id, question.Message, question.Answers); return(contract); } else // new session { var question = _questionList.Questions[new Random().Next(_questionList.Questions.Length)]; var session = new SessionQuiz(sessionId); session.Questions.Add(question); _sessions.Add(session); var contract = new QuestionContract(question.Id, question.Message, question.Answers); return(contract); } }
public async Task <IActionResult> question(int id, [FromBody] QuestionContract question) { Logger.HttpRequestOutput("PUT", "api/question/question"); bool result = DataBaseService.EditQuestion(id, question); return(Json(result)); }
/// <summary> /// 题目转换 /// </summary> public static QuestionContract ConvertQuestion(CiWong.Tools.Workshop.DataContracts.QuestionContract question, long parentVersion = 0, decimal questionRefScore = 0, bool isConvertRefInfo = true) { if (null == question) { return(null); } var questionContract = new QuestionContract(); questionContract.Id = question.Id; questionContract.VersionId = question.VersionId; questionContract.Type = (int)question.Type; questionContract.Stem = TemplateConverter.Instance.ConvertToHtml(question.Trunk.Body, TemplateConverter.Mathml, TemplateConverter.Mathlate, TemplateConverter.MathmlBlank, TemplateConverter.Math); questionContract.IsObjective = question.IsObjective; questionContract.QuestionRefSorce = Convert.ToSingle(questionRefScore); questionContract.ParentVersion = parentVersion; questionContract.Opions = question.Options.Select(t => ConvertOption(t)).ToList(); if (null != question.Trunk.Attachments) { questionContract.Attachments = question.Trunk.Attachments.Select(t => ConvertAttachment(t)).ToList(); } if (isConvertRefInfo) { questionContract.RefInfo = ConvertRefInfo(question); } return(questionContract); }
/// <summary> /// 题目转换 /// </summary> public static QuestionContract ConvertQuestion(Ques.Core.Models.Question question, float questionRefScore = 0, bool isConvertRefInfo = true) { if (null == question) { return(null); } var questionContract = new QuestionContract(); questionContract.Id = question.QuestionID; questionContract.VersionId = question.Version; questionContract.Type = (int)question.qType; questionContract.CurriculumID = (int)question.CurriculumID; questionContract.Stem = null == question.Stem ? string.Empty : TemplateConverter.Instance.ConvertToHtml(question.Stem, TemplateConverter.Mathml, TemplateConverter.Mathlate, TemplateConverter.MathmlBlank, TemplateConverter.Math); questionContract.IsObjective = question.IsObjective; questionContract.QuestionRefSorce = questionRefScore; questionContract.ParentVersion = question.ParentOfVersion; questionContract.Opions = question.Option.Select(t => ConvertOption(t)).ToList(); questionContract.Attachments = question.Attachments.Where(t => t.Type == AttachmentType.Problem).Select(t => ConvertAttachment(t)).ToList(); questionContract.KnowledgePoints = question.Point.Select(t => new KnowledgePoint() { PointCode = t.Code ?? string.Empty, PointName = t.Name ?? string.Empty }); if (isConvertRefInfo) { questionContract.RefInfo = ConvertRefInfo(question); } return(questionContract); }
public async Task <IActionResult> question([FromBody] QuestionContract question) { Logger.HttpRequestOutput("POST", "api/question/question"); int questionid = DataBaseService.SaveQuestion(question); bool result = DataBaseService.SaveAnswer(question, questionid); return(Json(result)); }
public static bool SaveAnswer(QuestionContract questionContract, int id) { try { SaveAnswer(questionContract.Answer1, id); SaveAnswer(questionContract.Answer2, id); SaveAnswer(questionContract.Answer3, id); return(true); } catch (Exception ex) { Logger.ExceptionOutput(ex); return(false); } }
public static bool EditQuestion(int id, QuestionContract question) { try { var Question = (from query_question in model.QuestionList where query_question.Id == id select query_question).Single(); Question.QuestionDescription = question.QuestionDescription; Question.AdditionalInformation = question.AdditionalInformation; model.SaveChanges(); return(true); } catch (Exception ex) { Logger.ExceptionOutput(ex); return(false); } }
public static int SaveQuestion(QuestionContract questionContract) { try { Question question = new Question() { SurveyId = Int32.Parse(questionContract.SurveyId), QuestionDescription = questionContract.QuestionDescription, AdditionalInformation = questionContract.AdditionalInformation, }; model.QuestionList.Add(question); model.SaveChanges(); return(question.Id); } catch (Exception ex) { Logger.ExceptionOutput(ex); return(0); } }