public async Task <ActionResult> DeleteGallery(Guid id) { Guid userId = new Guid(HttpContext.User.Identity.Name); if (await _galleryService.DoesGalleryExistAsync(id) == false) { return(NotFound()); } if (await _galleryService.IsGalleryOwnedByUserAsync(id, userId) == false) { return(Unauthorized()); } try { await _galleryService.DeleteGalleryAsync(id); return(NoContent()); } catch (Exception ex) { var problemDetails = new ProblemDetails { Title = "An unexpected error occurred.", Status = StatusCodes.Status500InternalServerError, Detail = "Unable to delete the gallery at this moment due to an error, the error has been logged and sent to the developers for fixing.", Instance = HttpContext.TraceIdentifier, }; return(StatusCode(StatusCodes.Status500InternalServerError, problemDetails)); } }