private void AddNewQuestion(QuestionModel questionModel, IQuestionService questionService, AnswerModel answerModel, IAnswerService answerService) { //* adding a question questionModel.isOpen = false; questionService.Add(questionModel); //* adding answers answerModel.QuestionID = questionService.GetAll().OrderByDescending(x => x.QuestionID).First().QuestionID; string[] answerText = new string[] { txt_correctAnswer.Text, txt_secondAnswer.Text, txt_thirdAnswer.Text, txt_fourthAnswer.Text }; foreach (var item in answerText) { if (item == txt_correctAnswer.Text) { answerModel.isCorrect = true; answerModel.AnswerText = item; answerService.Add(answerModel); } else { answerModel.isCorrect = false; answerModel.AnswerText = item; answerService.Add(answerModel); } } }
public IActionResult Post([FromBody] AnswerModel resposta) { var answer = _mapper.Map <Answer>(resposta); _answerService.Add(answer); return(Ok()); }
public JsonResult AnswerEdit(int AnswerId, AnswerModel AnswerModel) { try { if (AnswerId == 0) { Core3Base.Infra.Data.Entity.Answer Answer = new Core3Base.Infra.Data.Entity.Answer { Responce = AnswerModel.Answer.Responce, IsActive = AnswerModel.Answer.IsActive, }; return(Json(_answerService.Add(Answer).HttpGetResponse())); } else { var Answer = _answerService.GetAnswerById(AnswerId).Result; Answer.Responce = AnswerModel.Answer.Responce; Answer.IsActive = AnswerModel.Answer.IsActive; return(Json(_answerService.Update(Answer).HttpGetResponse())); } } catch (Exception e) { return(Json(e.Message)); } }
public void CreateTemplate(TemplateModel model) { var template = new Template() { Content = model.Content, Duration = model.Duration, Level = model.Level, PassScore = model.PassScore, Skill = model.Skill }; var newTemplate = _TemplateService.Add(template); foreach (var item in model.Questions) { var question = new Question() { Content = item.Content, TemplateId = newTemplate.ID }; var newQuestion = _QuestionService.Add(question); var listAnswer = new List <Answer>(); foreach (var ans in item.Answers) { var answer = new Answer() { QuestionId = newQuestion.ID, Content = ans.Content, IsCorrect = ans.IsCorrect }; listAnswer.Add(answer); } _AnswerService.Add(listAnswer); } }
public async Task <IActionResult> Create(AnswerViewModel model) { if (ModelState.IsValid) { try { if (model.Answers == null) { model.Answers = new List <Answer>(); } _answerService.BeginTransaction(); var answer = helper.GetAnswer(model); answer.Id = _answerService.Add(answer); if (answer.Id < 0) { throw new Exception("database error"); } model.Answers.AddRange(_answerService.List(x => x.QuestionId == model.QuestionId)); _answerService.CommitTransaction(); return(View(nameof(Create), model)); } catch (Exception ex) { _answerService.RollbackTransaction(); } } return(View(model)); }
public ActionResult Create(Answer answer) { if (_answerService.Add(answer)) { return(View("Index")); } return(View("Index")); }
public ActionResult Question(FormCollection form, int questionid) { var formId = _queryableRepository.Table.FirstOrDefault(x => x.KnowledgeTestId == questionid); var keys = Request.Form.AllKeys; var reqForm = form["item.Question"]; var date = DateTime.Now.ToShortDateString(); var quiz = _knowledgeTestService.GetAll().Where(x => (Convert.ToDateTime(x.KnowledgeDate.ToShortDateString()) == Convert.ToDateTime(date))); var quizList = quiz.ToList(); if (reqForm == formId.ValidAnswerType) { _answerService.Add(new Answer { UserId = Convert.ToInt32(GeneralHelpers.GetUserId()), KnowledgeTestId = questionid, AnswerDate = DateTime.Now, ValidAnswer = true }); _scoreService.Add(new Score { UserId = Convert.ToInt32(GeneralHelpers.GetUserId()), ScoreTotal = formId.Point, ScoreType = ScoreType.BilgiModulu, }); SuccessNotification("Tebrikler! Cevabınız Doğru."); } else { _answerService.Add(new Answer { UserId = Convert.ToInt32(GeneralHelpers.GetUserId()), KnowledgeTestId = questionid, AnswerDate = DateTime.Now, ValidAnswer = false }); ErrorNotification("Üzgünüm Doğru Cevap " + formId.ValidAnswerType + " Olmalıydı :("); } return(RedirectToAction("Question")); }
public IActionResult Add([FromQuery] AnswerViewModel model) { var AnswerResponse = _AnswerService.Add(new Answer { QuestionsId = model.QuestionsId, Responce = model.Responce, }); if (AnswerResponse.IsSucceeded && AnswerResponse.Result != null) { return(Ok(AnswerResponse.Result)); } return(AnswerResponse.HttpGetResponse()); }
public ActionResult QuestionAnswer(AnswerListViewModel answerListViewModel) { var personId = HttpContext.Session.GetInt32("personId"); answerListViewModel.Answer.SurveyId = answerListViewModel.Question.SurveyId; answerListViewModel.Answer.QuestionId = answerListViewModel.Question.Id; answerListViewModel.Answer.UserId = (int)personId; //personId !! answerListViewModel.QuestionOptions = _questionOptionService.GetByQuestionId(answerListViewModel.Question.Id); _answerService.Add(answerListViewModel.Answer); TempData["_QuestionAnswer"] = 1; return(View(answerListViewModel)); }
public ActionResult Create(AnswerViewModel answer) { if (!ModelState.IsValid) { ErrorNotification("Kayıt Eklenemedi!"); return(RedirectToAction("Create")); } _answerService.Add(new Answer { //TODO:Alanlar buraya yazılacak //Örn:BrandName = brand.BrandName, }); SuccessNotification("Kayıt Eklendi."); return(RedirectToAction("AnswerIndex")); }
public void Import(string fileName, string quizName) { var json = File.ReadAllText(fileName); var questions = JsonConvert.DeserializeObject <IEnumerable <JsonQuestion> >(json); var quizId = quizService.Add(quizName); foreach (var question in questions) { var questionId = questionService.Add(question.Question, quizId); foreach (var answer in question.Answers) { answerService.Add(answer.Answer, answer.Correct ? 1 : 0, answer.Correct, questionId); } } }
private void SaveUpdateOpenQuestion(QuestionModel questionModel, IQuestionService questionService, AnswerModel answerModel, IAnswerService answerService) { if (!string.IsNullOrEmpty(txt_question.Text) && !string.IsNullOrEmpty(txt_correctAnswer.Text)) { answerModel.AnswerText = txt_correctAnswer.Text; if (btn_save.Text == "Update") { //* updating a question questionModel.isOpen = true; questionModel.QuestionID = questionID; questionService.Update(questionModel); //* updating a correct answer answerModel.QuestionID = questionID; answerModel.isCorrect = true; answerModel.AnswerID = answerService.GetAll().Where(x => x.QuestionID == questionID && x.isCorrect == true).Single().AnswerID; answerService.Update(answerModel); MessageBox.Show("Updated successfully!", "Done"); this.Close(); } else { //* add a new question questionModel.isOpen = true; questionService.Add(questionModel); //* add a new answer answerModel.isCorrect = true; answerModel.QuestionID = questionService.GetAll().OrderByDescending(x => x.QuestionID).First().QuestionID; answerService.Add(answerModel); MessageBox.Show("Added successfully!", "Done"); txt_correctAnswer.Text = string.Empty; txt_question.Text = string.Empty; } } else { MessageBox.Show("Please fill in all fields.", "Error"); } }
public ActionResult Create([Bind(Include = "Name")] AnswerVM answerVM) { try { if (ModelState.IsValid) { AnswerDTO answerDTO = Mapper.Map <AnswerDTO>(answerVM); AnswerService.Add(answerDTO); return(RedirectToAction("Index")); } return(View()); } catch (UniqueConstraintException ex) { return(Json(new { hasError = true, data = ex.Message }, JsonRequestBehavior.AllowGet)); } }
public ActionResult AnswerQuestion(Answer model, int?pageIndex) { if (ModelState.IsValid) { if (model.answerId > 0) { _answerService.Update(model); _answerService.Save(); } else { model.createTime = DateTime.Now; model.isTrash = false; model.userName = User.Identity.Name; _answerService.Add(model); _answerService.Save(); } return(RedirectToAction("Index", new { pageIndex = pageIndex, languageId = model.languageId })); } ViewBag.Quanlycauhoi = "active"; return(View(model)); }
public async Task <ActionResult> AddAnswerAsync(Answer answer) { var question = _questionService.GetAll().SingleOrDefault(t => t.Id == answer.QuestionId); if (question == null) { throw new ArgumentNullException(nameof(question)); } else { answer.Id = Guid.NewGuid().ToString(); answer.Date = DateTime.Now; answer.SenderName = User.Identity.Name; answer.IsAdmin = _userService.IsAdmin(_userService.GetUserBySystemName(User)); _answerService.Add(answer); // Notify every client await _hubContext.Clients.Group(answer.QuestionId).AnswerCountChange(question.Id, question.Answers.Count); await _hubContext.Clients.Group(answer.QuestionId).AnswerAdded(answer); return(new JsonResult(answer)); } }
public async Task <Result <AnswerResponse> > Post([FromBody] AddAnswerCommand command) => await _service.Add(command);
public ActionResult FinalAnswerSubmit(int questionNumber, string textContent) { try { string input = textContent; int numOfWords = _smartTextBox.GetNumberOfWords(input); int numOfConnectors = _smartTextBox.GetNumberOfConnectors(input); IDictionary <string, int> repeatedWords = _smartTextBox.GetRepeatedWords(input); TempData["NumberOfWords"] = numOfWords; TempData["NumberOfConnectorWords"] = numOfConnectors; TempData["Answer"] = input; smartView.QuestionNumber = questionNumber; Answer ans = new Answer(); string userid = User.Identity.GetUserId(); foreach (var std in _studentService.All().Include(x => x.Homeworks)) { if (std.ApplicationUserId.Equals(userid)) { student = std; break; } } string tmpName = (string)Session["textName"]; textGuid = _textService.All().Where(t => t.Name == tmpName).FirstOrDefault().Id; List <Homework> AllStudentHW = _homeworkService.All().Where(x => x.Text.Id == textGuid).ToList(); Homework hw = AllStudentHW.First(); ICollection <Question> tmpQuestionsList = _homeworkService.All().Include(x => x.Questions.Select(p => p.Policy)).Where(x => x.Id == hw.Id).FirstOrDefault().Questions; smartView.question = tmpQuestionsList.Where(x => x.Question_Number == questionNumber).FirstOrDefault();//include policy.. smartView.Questions = tmpQuestionsList.ToList(); if (_answerService.All().Where(x => x.Student_Id == student.Id && x.Homework_Id == hw.Id).FirstOrDefault() == null) { ans.Answer_To = _homeworkService.All().Where(x => x.Id == hw.Id).FirstOrDefault(); ans.Date_Submitted = DateTime.Now; ans.Homework_Id = hw.Id; //ans.Id = Guid.NewGuid(); ans.IsDeleted = false; ans.TestID = 0; ans.Grade = 0; ans.Student_Id = student.Id; ans.Submitted_By = student; _answerService.Add(ans); ans = _answerService.All().Where(x => x.Student_Id == student.Id && x.Homework_Id == hw.Id).FirstOrDefault(); ICollection <QuestionAnswer> QuestionsAnsweredOnHomeWork = _answerService.All().Where(x => x.Homework_Id == hw.Id && x.Student_Id == student.Id).SelectMany(x => x.questionAnswers).ToList(); QuestionAnswer tmpQuestionAnswer = new QuestionAnswer(); tmpQuestionAnswer.In_Answer = ans; tmpQuestionAnswer.Answer_Id = ans.Id; tmpQuestionAnswer.Of_Question = smartView.question; tmpQuestionAnswer.Question_Id = smartView.question.Id; tmpQuestionAnswer.Content = input; tmpQuestionAnswer.Date_Submitted = ans.Date_Submitted; QuestionsAnsweredOnHomeWork.Add(tmpQuestionAnswer); ans.questionAnswers = QuestionsAnsweredOnHomeWork; _answerService.Update(ans); } else { ICollection <QuestionAnswer> QuestionsAnsweredOnHomeWork = _answerService.All().Where(x => x.Homework_Id == hw.Id && x.Student_Id == student.Id).SelectMany(x => x.questionAnswers).ToList(); ans = _answerService.All().Where(x => x.Student_Id == student.Id && x.Homework_Id == hw.Id).FirstOrDefault(); if (QuestionsAnsweredOnHomeWork.Where(x => x.Of_Question.Question_Number == questionNumber).Count() == 0) { QuestionAnswer tmpQuestionAnswer = new QuestionAnswer(); // tmpQuestionAnswer.Id = Guid.NewGuid(); tmpQuestionAnswer.Answer_Id = ans.Id; tmpQuestionAnswer.Content = input; tmpQuestionAnswer.Date_Submitted = DateTime.Now; tmpQuestionAnswer.In_Answer = ans; tmpQuestionAnswer.Of_Question = smartView.question; tmpQuestionAnswer.Question_Id = smartView.question.Id; QuestionsAnsweredOnHomeWork.Add(tmpQuestionAnswer); ans.questionAnswers = QuestionsAnsweredOnHomeWork; _answerService.Update(ans); } else { QuestionAnswer tmpQuestionAnswer = QuestionsAnsweredOnHomeWork.Where(x => x.Of_Question.Question_Number == questionNumber).FirstOrDefault(); ans.questionAnswers.Remove(tmpQuestionAnswer); tmpQuestionAnswer.Content = input; tmpQuestionAnswer.Date_Submitted = DateTime.Now; ans.questionAnswers.Add(tmpQuestionAnswer); _answerService.Update(ans); } } if (smartView.question.Suggested_Openings.Count == 0) { SuggestedOpening noSuggOpen = new SuggestedOpening("אין משפטי פתיחה לשאלה זו"); SuggestedOpening noSuggOpen2 = new SuggestedOpening("התשובה לשאלה נמצאת בגוף השאלה"); smartView.question.Suggested_Openings.Add(noSuggOpen); smartView.question.Suggested_Openings.Add(noSuggOpen2); } List <int> SmartViewQuestionsNumbers = new List <int>(); Answer QuestionsAnswered = _answerService.All().Include(y => y.questionAnswers).Where(x => x.Homework_Id == hw.Id && x.Student_Id == student.Id).FirstOrDefault(); smartView.CompleteQuestions = QuestionsAnswered.questionAnswers.ToList(); int k = 0; foreach (var QuestAns in smartView.CompleteQuestions) { SmartViewQuestionsNumbers.Add(QuestAns.Of_Question.Question_Number); k++; } smartView.CompleteQuestionsNumbers = SmartViewQuestionsNumbers; if ((int)(k / smartView.Questions.Count() * 100) > 99) { student.Homeworks.Remove(hw); _studentService.Update(student); } TempData["toManyConnectors"] = "התשובה הוגשה בהצלחה למערכת. תוכל לשנות אותה עד לתאריך ההגשה האחרון"; string tmpstring = "שאלה מספר " + questionNumber; return(RedirectToAction("GotoSmartTextBox", new { questionNumber = tmpstring })); } catch (Exception e) { return(RedirectToAction("Index")); } }