public IActionResult CreateRelatedProject(int taskId, [FromBody] RelatedProjectsForCreateDto relatedProject) { if (relatedProject == null) { return(BadRequest()); } if (relatedProject.Name == relatedProject.Description) { ModelState.AddModelError("Description", "The provided description should be different from the name"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var task = TasksDataStore.Current.Tasks.FirstOrDefault(t => t.Id == taskId); if (task == null) { return(NotFound()); } var maxRelatedPorjectId = TasksDataStore.Current.Tasks.SelectMany(t => t.RelatedProjects).Max(r => r.Id); var finalRelatedProject = new RelatedProjectsDto { Id = ++maxRelatedPorjectId, Name = relatedProject.Name, Description = relatedProject.Description }; task.RelatedProjects.Add(finalRelatedProject); return(CreatedAtRoute("GetRelatedProject", new { taskId, projectId = finalRelatedProject.Id }, finalRelatedProject)); }
public IActionResult UpdateRelatedProject(int taskId, int projectId, [FromBody] RelatedProjectsForCreateDto updatedRelatedProject) { if (updatedRelatedProject == null) { return(BadRequest()); } if (updatedRelatedProject.Name == updatedRelatedProject.Description) { ModelState.AddModelError("Description", "The provided description should be different from the name"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var task = TasksDataStore.Current.Tasks.FirstOrDefault(t => t.Id == taskId); if (task == null) { return(NotFound()); } var relatedProject = task.RelatedProjects.FirstOrDefault(r => r.Id == projectId); if (relatedProject == null) { return(NotFound()); } relatedProject.Name = updatedRelatedProject.Name; relatedProject.Description = updatedRelatedProject.Description; return(NoContent()); }