public ActionResult <QuestionShallowDTO> Put(long id, [FromBody] CreateQuestionForm question) { if (string.IsNullOrEmpty(question.Content)) { return(BadRequest()); } var quest = _context.Questions.FirstOrDefault(x => x.Id == id); if (quest != null) { var category = _context.Categories.FirstOrDefault(x => x.Id == question.CategoryId); if (category == null) { return(BadRequest()); } quest.Category = category; quest.Content = question.Content; _context.Questions.Update(quest); _context.SaveChanges(); return(Ok(new QuestionShallowDTO(quest))); } else { return(NoContent()); } }
public ActionResult <QuestionShallowDTO> Post([FromBody] CreateQuestionForm question) { if (string.IsNullOrEmpty(question.Content)) { return(BadRequest()); } var category = _context.Categories.FirstOrDefault(x => x.Id == question.CategoryId); if (category == null) { return(BadRequest()); } var quest = new Question { Category = category, Content = question.Content }; _context.Questions.Add(quest); _context.SaveChanges(); return(Ok(new QuestionShallowDTO(quest))); }