public async Task <IActionResult> UpdateHighlight(int highlightId, [FromBody] HighlightResource highlightResource) { Highlight highlight = await highlightService.FindAsync(highlightId); if (highlight == null) { ProblemDetails problem = new ProblemDetails { Title = "Failed getting the highlight.", Detail = "The database does not contain a highlight with that id.", Instance = "795CDB7E-DB46-4A24-8F12-7557BDD79D15" }; return(NotFound(problem)); } mapper.Map(highlightResource, highlight); highlightService.Update(highlight); highlightService.Save(); return(Ok(mapper.Map <Highlight, HighlightResourceResult>(highlight))); }
public async Task <IActionResult> UpdateHighlight(int highlightId, [FromBody] HighlightResource highlightResource) { Highlight highlight = await highlightService.FindAsync(highlightId); if (highlight == null) { ProblemDetails problem = new ProblemDetails { Title = "Failed getting the highlight.", Detail = "The database does not contain a highlight with that id.", Instance = "795CDB7E-DB46-4A24-8F12-7557BDD79D15" }; return(NotFound(problem)); } mapper.Map(highlightResource, highlight); File file = null; if (highlightResource.ImageId != null) { file = await fileService.FindAsync(highlightResource.ImageId.Value); if (file == null) { ProblemDetails problem = new ProblemDetails { Title = "File was not found.", Detail = "The specified file was not found while creating highlight.", Instance = "412CC9A8-CB2A-4389-9F9C-F8494AB65AE0" }; return(NotFound(problem)); } } Project project = await projectService.FindWithUserCollaboratorsAndInstitutionsAsync(highlightResource.ProjectId); if (project == null) { ProblemDetails problem = new ProblemDetails { Title = "Project was not found.", Detail = "The specified project was not found while creating highlight.", Instance = "B923484E-D562-4F03-A57E-88D02819EBD6" }; return(NotFound(problem)); } highlight.Image = file; highlight.Project = project; try { highlightService.Update(highlight); highlightService.Save(); return(Ok(mapper.Map <Highlight, HighlightResourceResult>(highlight))); } catch (DbUpdateException e) { Log.Logger.Error(e, "Database exception"); ProblemDetails problem = new ProblemDetails { Title = "Failed updating highlight.", Detail = "Failed updating the highlight to the database.", Instance = "D9933508-F7B6-44B1-9266-5B040D2EA07D" }; return(BadRequest(problem)); } }