public async Task Should_Add_Question() { var command = new AddQuestionCommand() { Name = "TESTE", Answers = new List <QuestionAnswerDto>() { new QuestionAnswerDto() { Id = Guid.NewGuid(), Name = "TESTE", Correct = true } } }; var result = await _service.Add(command); result.Success.Should().BeTrue(); }
public IActionResult Add(NewQuestionViewModel model) { var success = service.Add( Utility.GetUserContext().UserId, model.CourseId, model.Type, model.Topic, model.AnswerOptions); return(Ok(success)); }
public ActionResult Create(int id, Question q) { Question p = new Question(); p.QuizId = id; p.QuestionDescription = q.QuestionDescription; p.Question1stSuggestion = q.Question1stSuggestion; p.Question2ndSuggestion = q.Question2ndSuggestion; p.Question3rdSuggestion = q.Question3rdSuggestion; p.QuestionCorrectAnswer = q.QuestionCorrectAnswer; Ps.Add(p); Ps.Commit(); return(RedirectToAction("Index")); }
public ActionResult CreateQuestionn(QuestionModel projectVM) { Domain.Entity.Question p = new Domain.Entity.Question { Id = projectVM.Id, Subject = projectVM.Subject, choice1 = projectVM.choice1, choice2 = projectVM.choice2, choice3 = projectVM.choice3, ValidChoise = projectVM.ValidChoise, TestId = projectVM.TestId, }; qs.Add(p); qs.Commit(); return(new HttpStatusCodeResult(System.Net.HttpStatusCode.OK)); }
public ActionResult Create(QuestionModel qm) { Question q = new Question(); q.qQst = qm.qQst; q.QstId = qm.QstId; q.Rep1 = qm.Rep1; q.Rep2 = qm.Rep2; q.Rep3 = qm.Rep3; q.Rep4 = qm.Rep4; q.TestId = qm.TestId; q.RepCorrect = qm.RepCorrect; iqs.Add(q); iqs.Commit(); return(RedirectToAction("ShowQuestions")); }
public void Add_Question_Without_Title_Error() { Mock <IQuestionRepository> mockRepository = new Mock <IQuestionRepository>(MockBehavior.Strict); Question newQuestion = new Question(); mockRepository.Setup(s => s.Add(newQuestion)) .Throws(new ArgumentNullException(nameof(newQuestion.Title))); IQuestionService service = new QuestionService(mockRepository.Object); ArgumentNullException ex = Assert.Throws <ArgumentNullException>(() => service.Add(newQuestion)); Assert.Equal(nameof(newQuestion.Title), ex.ParamName); mockRepository.Verify(m => m.Add(It.IsAny <Question>()), Times.Once()); }
public ActionResult Create(question question) { try { question q = new question(); q.answer = question.answer; q.description = question.description; QuestionService questionserv = new QuestionService(); questionserv.Add(q); questionserv.Commit(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Add(QuestionAnswerVM data) { Question question = new Question { Content = data.Content }; User user = userService.GetByDefault(x => x.UserName == User.Identity.Name); question.UserID = user.ID; questionService.Add(question); Answer answer = new Answer { QuestionID = question.ID, UserID = user.ID, Content = data.AnswerContent }; answerService.Add(answer); return(Redirect("/SysAdmin/QA/List")); }
public ActionResult Create(questionModel qm) { try { // TODO: Add insert logic here question q = new question(); q.question_name = qm.question_name; q.question_description = qm.question_description; q.quiz_id_Quiz = qm.quiz_id_Quiz; q.id_Question = qm.id_Question; qts.Add(q); qts.Commit(); return(RedirectToAction("Index", new { id = q.quiz_id_Quiz })); } catch { return(View()); } }
public ActionResult Create(Question quest) { Question p = new Question(); try { // TODO: Add insert logic here p.Subject = quest.Subject; p.choice1 = quest.choice1; p.choice2 = quest.choice2; p.choice3 = quest.choice3; p.ValidChoise = quest.ValidChoise; p.TestId = quest.TestId; questionservice.Add(p); questionservice.Commit(); //return RedirectToAction("../Home/Index"); return(RedirectToAction("index", "Home")); } catch { return(View()); } }
public static void Add(int QuestionID, string Content, string Answer) { QuestionService.Add(QuestionID, Content, Answer); }
public ActionResult CreateTraining(TrainingModel t, LessonModel[] l, QuestionModel[] q, AnswerModel[] a) { Training lastTraining = new Training(); lastTraining = ts.GetLastAdded(); Lesson lastLesson = new Lesson(); lastLesson = ls.GetLastAdded(); Question lastQuestion = new Question(); lastQuestion = qs.GetLastAdded(); foreach (var itema in a) { Answer an = new Answer(); an.questionId = lastQuestion.questionId + itema.questionNumber; an.description = itema.description; if (itema.isTrue == 0) { an.isTrue = true; } else { an.isTrue = false; } an.editorId = 1; ans.Add(an); } // ADD QUESTIONS foreach (var itemq in q) { Question qu = new Question(); qu.lessonId = lastLesson.lessonId + itemq.lessonNumber; qu.title = itemq.title; qu.description = itemq.description; qu.editorId = 1; qu.dateAdded = DateTime.Now; qs.Add(qu); } foreach (var item in l) { // ADD A LESSON Lesson le = new Lesson(); le.trainingId = lastTraining.trainingId + 1; le.title = item.title; le.description = item.description; le.estimatedTime = item.estimatedTime; le.dateAdded = DateTime.Now; le.editorId = 1; ls.Add(le); } //ADD A TRAINING SESSION Training tr = new Training(); tr.title = t.title; tr.description = t.description; tr.estimatedTime = t.estimatedTime; tr.dateAdded = DateTime.Now; tr.editorId = 1; //tr.categoryId = 1; tr.difficultyValue = t.difficultyValue; tr.difficultyDescription = t.difficultyDescription; ts.Add(tr); ts.Commit(); ls.Commit(); qs.Commit(); ans.Commit(); return(RedirectToAction("Training")); }
public void Add_Question_Success() { List <Option> options = new List <Option> { new Option { Id = 1, Text = "Option A" }, new Option { Id = 2, Text = "Option B" }, new Option { Id = 3, Text = "Option C" }, new Option { Id = 4, Text = "Option D" } }; Option answer = options[2]; Question newQuestion = new Question("What was the score of the game?", answer, options, LevelEnum.Hard); Mock <IQuestionRepository> mockRepository = new Mock <IQuestionRepository>(MockBehavior.Strict); mockRepository.Setup(s => s.Add(newQuestion)) .Callback <Question>(q => { q.Id = 1; q.Level = LevelEnum.Hard; q.Options.ForEach(o => { o.QuestionId = q.Id; o.Question = q; }); }); Question expectedQuestion = new Question(); List <Option> expectedOptions = new List <Option> { new Option { Id = 1, Text = "Option A", QuestionId = expectedQuestion.Id, Question = expectedQuestion }, new Option { Id = 2, Text = "Option B", QuestionId = expectedQuestion.Id, Question = expectedQuestion }, new Option { Id = 3, Text = "Option C", QuestionId = expectedQuestion.Id, Question = expectedQuestion }, new Option { Id = 4, Text = "Option D", QuestionId = expectedQuestion.Id, Question = expectedQuestion } }; Option expectedAnswer = options[2]; expectedQuestion.Title = "What was the score of the game?"; expectedQuestion.Answer = expectedAnswer; expectedQuestion.Options = expectedOptions; expectedQuestion.Level = LevelEnum.Hard; expectedQuestion.Id = 1; IQuestionService service = new QuestionService(mockRepository.Object); service.Add(newQuestion); Assert.Equal(expectedQuestion, newQuestion); mockRepository.Verify(m => m.Add(It.IsAny <Question>()), Times.Once()); }
public async Task <IActionResult> Add(QuestionModel question) => (await questionService.Add(question)).Result();
public async Task <IActionResult> Add(Question question) { await questions.Add(question); return(View()); }
public async void AddQuestionClick(object o, EventArgs e) { if (userToken.IsExpire) { Android.Support.V7.App.AlertDialog.Builder alertDialog = new Android.Support.V7.App.AlertDialog.Builder(this) .SetTitle("登录提示") .SetMessage("未登录或登录token已经过期") .SetPositiveButton("授权", (s1, e1) => { StartActivity(new Intent(this, typeof(loginactivity))); }) .SetNegativeButton("取消", (s1, e1) => { return; }); alertDialog.Create().Show(); } string content = edit_content.Text.Trim(); string title = edit_content.Text.Trim(); string tags = edit_tags.Text.Trim(); if (string.IsNullOrEmpty(content) || content.Length > 100000 || content.Length < 20) { AlertUtil.ToastShort(this, "提问内容20-100000个字符之间"); return; } if (string.IsNullOrEmpty(title) || title.Length > 100000 || title.Length < 20) { AlertUtil.ToastShort(this, "标题6-200分字符"); return; } if (!string.IsNullOrEmpty(tags)) { var tagCount = tags.Split(',').Length; if (tagCount > 5) { AlertUtil.ToastShort(this, "不能超过5个标签,以中文都好隔开"); return; } } var userInfo = UserInfoShared.GetUserInfo(this); var dialog = new ProgressDialog(this); dialog.SetProgressStyle(ProgressDialogStyle.Spinner); dialog.SetCancelable(false); dialog.SetCanceledOnTouchOutside(false); dialog.SetTitle(Resources.GetString(Resource.String.bookmark_add)); dialog.SetMessage("提交中......."); dialog.Show(); var result = await QuestionService.Add(userToken, title, content, tags, flags, userInfo.SpaceUserId.ToString()); if (result.Success) { RunOnUiThread(() => { dialog.Hide(); edit_content.Text = ""; edit_title.Text = ""; edit_tags.Text = ""; rb_true.Checked = true; AlertUtil.ToastShort(this, "发布问答成功"); ActivityCompat.FinishAfterTransition(this); }); } else { RunOnUiThread(() => { dialog.Hide(); AlertUtil.ToastShort(this, result.Message); }); } }