public async Task <IActionResult> CreateProject([FromBody] CreateProjectDto project) { if (project == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var projectToCreate = Mapper.Map <Project>(project); _projectManagerRepository.AddProjectAsync(projectToCreate); if (!await _projectManagerRepository.SaveAsync()) { _logger.LogError("An error occured creating the new project"); return(StatusCode(500, "A problem happened while handling your request.")); } var createdProjectToReturn = Mapper.Map <ProjectDto>(projectToCreate); return(CreatedAtRoute("GetProject", new { id = createdProjectToReturn.Id, }, createdProjectToReturn)); }
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)); }