public override async Task <IActionResult> Post([FromBody] Question question) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Answer answer = question.Answer; if (answer != null) { answer = await _answerRepo.Add(answer); question.AnswerId = answer.Id; question.Answer = null; } QuestionCategory questionCategory = question.QuestionCategory; if (questionCategory != null) { questionCategory = await _questionCategoryRepo.AddOrUpdate(questionCategory); question.QuestionCategoryId = questionCategory.Id; question.QuestionCategory = null; } ; ICollection <Feedback> feedbackCollection = question.Feedback; question.Feedback = null; Question createdEntity = await _repository.AddOrUpdate(question); if (createdEntity == null) { return(NotFound()); } if (feedbackCollection != null) { foreach (Feedback item in feedbackCollection) { item.QuestionId = createdEntity.Id; } feedbackCollection = await _feedBackRepo.AddOrUpdateCollection(feedbackCollection); } question.Feedback = feedbackCollection; return(CreatedAtAction(nameof(Get), new { id = createdEntity.Id }, createdEntity)); }