public ActionResult Create(Question newQuestion, IFormCollection collection) { try { if (ModelState.IsValid) { _questionRepo.AddQuestion(newQuestion); } return(RedirectToAction(nameof(Index))); } catch (Exception ex) { _logger.LogError($"Failed to create a question: {ex}"); return(View(newQuestion)); } }
public async Task <IActionResult> AddQuestion(NewQuestionModel model) { var userId = _userManager.GetUserId(User); var user = _userManager.FindByIdAsync(userId).Result; var question = BuildPost(model, user); string[] censoredWords = System.IO.File.ReadAllLines(@"CensoredWords.txt"); Censor censor = new Censor(censoredWords); question.QuestionTitle = censor.CensorText(question.QuestionTitle); question.QuestionContent = censor.CensorText(question.QuestionContent); await _questionImplementation.AddQuestion(question); await _applicationUserImplementation.UpdateUserRating(userId, typeof(Question)); return(RedirectToAction("Index", "Question", new { id = question.QuestionId })); }
//QuestionDAL public void AddQuestion(questions question) { questionDAL.AddQuestion(question); }
public IActionResult AddQuestion(uint id, string submit, string type_question, string q, string qa1, string qa2, string qa3, string qa4, string qa5, string qa6, string qa7, string qa8, string [] qbool) { Question question = new Question(); question.TextQuestion = q; question.IdQuizFK = id; question.QuestionType = type_question; question.Answer1 = qa1; question.Answer2 = qa2; if (qa3 != null) { question.Answer3 = qa3; } if (qa4 != null) { question.Answer4 = qa4; } if (qa5 != null) { question.Answer5 = qa5; } if (qa6 != null) { question.Answer6 = qa6; } if (qa7 != null) { question.Answer7 = qa7; } if (qa8 != null) { question.Answer8 = qa8; } for (int i = 0; i < qbool.Length; i++) { if (qbool[i].ElementAt(1) == '1') { question.Answer1Bool = true; } else if (qbool[i].ElementAt(1) == '2') { question.Answer2Bool = true; } else if (qbool[i].ElementAt(1) == '3') { question.Answer3Bool = true; } else if (qbool[i].ElementAt(1) == '4') { question.Answer4Bool = true; } else if (qbool[i].ElementAt(1) == '5') { question.Answer5Bool = true; } else if (qbool[i].ElementAt(1) == '6') { question.Answer6Bool = true; } else if (qbool[i].ElementAt(1) == '7') { question.Answer7Bool = true; } else if (qbool[i].ElementAt(1) == '8') { question.Answer8Bool = true; } } _question.AddQuestion(question); if (submit.Equals("Dodaj następne pytanie")) { return(RedirectToAction("AddQuestion", new { @id = id })); } else { return(RedirectToAction("Index")); } }
public static int AddQuestion(QuestionInfo Model) { return(dal.AddQuestion(Model)); }