public IActionResult CreateQuestion([FromBody] QuestionViewModel questionVm, [FromQuery(Name = "quiz")] int quizId) { Question question = new Question { Text = questionVm.Text }; Question newQuestion = questionRepository.AddQuestion(quizId, question); if (newQuestion == null) { return(BadRequest("The text is already assigned to another question")); } List <AnswerViewModel> realAnswers = this.processListOfAnswers(ref questionVm, ref newQuestion, quizId); if (realAnswers == null) { return(BadRequest("You can't have two duplicate answers")); } newQuestion = this.questionRepository.UpdateQuestion(newQuestion); QuestionViewModel newQuestionVm = entityToVmMapper.Map(newQuestion); newQuestionVm.Answers = realAnswers; return(Created($"/{newQuestionVm.Id}", newQuestionVm)); }
public IActionResult AddQuestionTags(Question question, List <string> tags) { var repository = new QuestionRepository(_connection); repository.AddQuestion(question, tags); return(Redirect("/")); }
public void AddQuestionToDataBase() { QuestionRepository questionsRepository = new QuestionRepository("hexagondbconnection"); int id = questionsRepository.AddQuestion(statement: "AAA", option1: "A1", option2: "A2", option3: "A3", option4: "A4", correctAnswer: 1); // Named parametrization Question question = questionsRepository.GetQuestionById(id); Assert.AreEqual(id, question.Id); Assert.AreEqual("AAA", question.Statement); Assert.AreEqual("A1", question.Option1); Assert.AreEqual("A2", question.Option2); Assert.AreEqual("A3", question.Option3); Assert.AreEqual("A4", question.Option4); Assert.AreEqual(1, question.CorrectAnswer); // Hit the Database and GetQuestion out of it //string connectionString = @"server=IN-PPM2320;database=dotnetdb1;intergrated security=true"; //using (SqlConnection connection = new SqlConnection(connectionString)) //{ // SqlCommand command = new SqlCommand(); // command.CommandText = "select * from questions where id=@id"; //parameterize query preparation // command.Connection = connection; // command.Parameters.AddWithValue("@id", id); // connection.Open(); // connects to the database server // // firing the query to the DB servers SQl processing Engine // SqlDataReader reader = command.ExecuteReader(); // // reader gets the cursor to read the records // reader.Read(); //get the first record in reader object // question = new Question(); // // Extracting data from the reader object per column bases // // and filling the data in Question Object // question.Id = (int)reader["Id"]; // question.Statement = (string)reader["statement"]; // question.Option1 = (string)reader["option1"]; // question.Option2 = (string)reader["option2"]; // question.Option3 = (string)reader["option3"]; // question.Option4 = (string)reader["option4"]; // question.CorrectAnswer = (int)reader["correctanswer"]; // Assert.AreEqual(id, question.Id); // Assert.AreEqual("AAA", question.Statement); // Assert.AreEqual("A1", question.Option1); // Assert.AreEqual("A2", question.Option2); // Assert.AreEqual("A3", question.Option3); // Assert.AreEqual("A4", question.Option4); // Assert.AreEqual(1, question.CorrectAnswer); }
public IActionResult AddQuestion(Question q, String tags) { var tagList = new List <String>(); tagList = tags.Split(',').ToList(); var db = new QuestionRepository(_conn); // var User = db.GetUserByEmail(User.Identity.Name); q.UserId = db.GetUserByEmail(User.Identity.Name).Id; db.AddQuestion(q, tagList); return(RedirectToAction("Index", new { id = q.Id })); }
public IActionResult AddQuestion(Question question, string tag) { var repos = new QuestionRepository(_connectionString); var repos2 = new AccountRepository(_connectionString); var user = repos2.GetUserByEmail(User.Identity.Name); var tags = new List <string>(); if (tag != null) { tags = tag.Split(',').ToList(); } question.UserId = user.Id; question.DatePosted = DateTime.Now; repos.AddQuestion(question, tags); return(Redirect("/")); }
public void Add(Question question) { questionRepository.AddQuestion(question); }
public ActionResult AddQuestion(CreateQuestionRequest createRequest) { var newQuestion = _questionRepository.AddQuestion(createRequest.QuestionText, createRequest.QuestionDate); return(Created($"/api/student/{newQuestion.Id}", newQuestion)); }