public async Task <IActionResult> UpdateProject(int id, [FromBody] ProjectForManipulation project) { Project oldProject = await projectService.FindProject(id); if (oldProject == null) { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (oldProject.Name != project.Name) { if (await projectService.FindProjectByName(project.Name) != null) { ModelState.AddModelError("Name", "Project name already exist."); return(BadRequest(ModelState)); } } try { await projectService.UpdateProject(project, oldProject); return(NoContent()); } catch (Exception xcp) { return(StatusCode(500, xcp.InnerException.Message)); } }
public async Task <IActionResult> CreateProject([FromBody] ProjectForManipulation project) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (await projectService.FindProjectByName(project.Name) != null) { ModelState.AddModelError("Name", "Project name already exist."); return(BadRequest(ModelState)); } try { Project newProject = await projectService.AddProject(project); return(Created($"Get/{newProject.ProjectId}", newProject)); } catch (Exception xcp) { return(StatusCode(500, xcp.InnerException.Message)); } }