public async Task <IActionResult> CreateUserStory(int projectId, [FromBody] CreateUserStoryDto userStory) { if (userStory == null) { return(BadRequest()); } // how to add model state error if (userStory.Description == userStory.Name) { ModelState.AddModelError("Details", "The provided description should be different than the Name"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!await _projectManagerRepository.ProjectExistAsync(projectId)) { return(NotFound()); } var userStoryToSave = Mapper.Map <UserStory>(userStory); _projectManagerRepository.AddUserStoryForProjectAsync(projectId, userStoryToSave); if (!await _projectManagerRepository.SaveAsync()) { return(StatusCode(500, "A problem happened while handling your request.")); } var createdUserStoryToReturn = Mapper.Map <UserStoryDto>(userStoryToSave); return(CreatedAtRoute("GetUserStory", new { projectId = projectId, id = createdUserStoryToReturn.Id }, createdUserStoryToReturn)); }