public IActionResult Create([FromQuery] int surveyId) { var viewModel = new QuestionBindingModel() { SurveyId = surveyId }; return(View(viewModel)); }
public IActionResult AddQuestion(QuestionBindingModel bindingModel) { if (ModelState.IsValid) { var user = userMgr.FindByNameAsync(User.Identity.Name).Result; discussService.AddQuestion(bindingModel, user); return(RedirectToAction(Actions.All, Paths.Discussions)); } return(View(bindingModel)); }
public async Task <IActionResult> Edit([FromForm] QuestionBindingModel model) { if (ModelState.IsValid) { var questionModel = model.ToServiceModel(); await _questionService.EditQuestionAsync(questionModel); return(RedirectToAction("Edit", "Survey", new { questionModel.SurveyId })); } return(View(model)); }
public QuestionBindingModel GetTestQuestionBM(Category category) { var model = new QuestionBindingModel() { Title = "TestQuestion", Content = "Just a test content", Tags = "web nice", Category = category }; return(model); }
public QuestionBindingModel GetTestQuestionBM() { var model = new QuestionBindingModel() { Title = "TestQuestion", Content = "Just a test content", Tags = "web nice", Category = Category.WebDevelopment }; return(model); }
//Tested public Question AddQuestion(QuestionBindingModel model, CustomUser publisher) { var question = new Question(model.Title, model.Content, model.Category, publisher); this.context.Questions.Add(question); this.context.SaveChanges(); var tags = GenerateTagEntities(model.Tags, question); question.Tags = tags; this.context.SaveChanges(); return(question); }
public IHttpActionResult CreateQuestion([FromBody] QuestionBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } QuestionDTO newQuestion = _mapper.Map <QuestionDTO>(model); this._questionService.Add(newQuestion); return(Ok()); }
public async Task <ActionResult <Question> > PostQuestion(QuestionBindingModel question) { Question newquestion = new Question { Title = question.Title, Content = question.Content, CreatedUserID = question.CreatedUserID }; _context.Questions.Add(newquestion); await _context.SaveChangesAsync(); return(CreatedAtAction("GetQuestion", new { id = newquestion.QuestionId }, question)); }
public async Task <IActionResult> Create([FromForm] QuestionBindingModel model) { if (ModelState.IsValid) { var questionModel = model.ToServiceModel(); await _questionService.CreateQuestionAsync(questionModel); int questionId = questionModel.Id; int surveyId = questionModel.SurveyId; return(RedirectToAction($"Create", "Option", new { surveyId, questionId })); } return(View(model)); }
public void WithValidModelReturnsQuestionViewModel() { var question = new QuestionBindingModel() { Content = "Test question" }; var model = new JoinEventViewModel() { EventId = 1, Question = question }; var result = this.service.GetQuestionModel(model); Assert.AreEqual(typeof(QuestionViewModel), result.GetType()); }
public async Task <ActionResult <Question> > PostQuestion(String token, QuestionBindingModel question) { if (token == null) { return(Unauthorized()); } Question newquestion = new Question { Title = question.Title, Content = question.Content, CreatedUserID = question.CreatedUserID, Tag = question.Tag }; _context.Questions.Add(newquestion); await _context.SaveChangesAsync(); return(CreatedAtAction("GetQuestion", new { id = newquestion.QuestionId }, question)); }
public IHttpActionResult UpdateQuestion(int id, [FromBody] QuestionBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } QuestionDTO questionToUpdate = this._questionService.GetById(id); if (questionToUpdate == null) { return(Content(HttpStatusCode.NotFound, $"Test category with id={id} does not exist.")); } QuestionDTO updatedQuestion = _mapper.Map <QuestionDTO>(model); this._questionService.Update(updatedQuestion); return(Ok()); }
public async Task <IActionResult> PutQuestion(Guid id, QuestionBindingModel updated_question) { if (id == null) { return(BadRequest()); } var question = await _context.Questions.FindAsync(id); if (question == null) { return(NotFound()); } question.Title = updated_question.Title; question.Content = updated_question.Content; _context.Entry(question).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!QuestionExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }