public ActionResult UpdateQuestion(int id, [FromBody] FaqQuestionCreateUpdateVM question) { if (question == null || db.FaqGroups.FirstOrDefault(g => g.FaqGroupId == question.FaqGroupId) == null) { return(BadRequest()); } var questionEntity = db.FaqQuestions.FirstOrDefault(q => q.Id == id); if (questionEntity == null) { return(NotFound()); } questionEntity.Question = question.Question; questionEntity.Answer = question.Answer; questionEntity.FaqGroupId = question.FaqGroupId; db.SaveChanges(); var questionVM = new FaqQuestionVMWithoutNavigationProperty { Id = questionEntity.Id, Question = questionEntity.Question, Answer = questionEntity.Answer }; return(Ok(questionVM)); }
public ActionResult CreateQuestion([FromBody] FaqQuestionCreateUpdateVM question) { if (question == null || db.FaqGroups.FirstOrDefault(g => g.FaqGroupId == question.FaqGroupId) == null) { return(BadRequest()); } var questionEntity = new FaqQuestion { Question = question.Question, Answer = question.Answer, FaqGroupId = question.FaqGroupId }; db.FaqQuestions.Add(questionEntity); db.SaveChanges(); return(Ok()); }