public IQueryable <Entity.GalleryItem> Sort(Entity.Album album, bool persistToAlbum) { try { if (persistToAlbum) { // Change the sort of an existing album for all users. if (album.Id <= 0) { throw new ArgumentException("An album ID must be specified when calling the AlbumsController.Sort() Web.API method with the persistToAlbum parameter set to true."); } AlbumController.Sort(album.Id, album.SortById, album.SortUp); return(GalleryObjectController.ToGalleryItems(AlbumController.LoadAlbumInstance(album.Id).GetChildGalleryObjects().ToSortedList()).AsQueryable()); } else { return(GalleryObjectController.SortGalleryItems(album)); } } catch (InvalidAlbumException) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent($"Could not find album with ID {album.Id}. It may have been deleted by another user."), ReasonPhrase = "Album Not Found" }); } catch (GallerySecurityException ex) { AppEventController.LogError(ex); throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)); } catch (Exception ex) { AppEventController.LogError(ex); throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = Utils.GetExStringContent(ex), ReasonPhrase = "Server Error" }); } }
public async Task <IActionResult> Sort(Entity.Album album, bool persistToAlbum) { try { if (persistToAlbum) { // Change the sort of an existing album for all users. if (album.Id <= 0) { throw new ArgumentException("An album ID must be specified when calling the AlbumsController.Sort() Web.API method with the persistToAlbum parameter set to true."); } await _albumController.Sort(album.Id, album.SortById, album.SortUp); return(new JsonResult(_galleryObjectController.ToGalleryItems(_albumController.LoadAlbumInstance(album.Id).GetChildGalleryObjects().ToSortedList()))); } else { return(new JsonResult(_galleryObjectController.SortGalleryItems(album))); } } catch (InvalidAlbumException) { return(NotFound($"Could not find album with ID {album.Id}. It may have been deleted by another user.")); } catch (GallerySecurityException ex) { AppEventController.LogError(ex); return(Forbid()); } catch (Exception ex) { AppEventController.LogError(ex); return(StatusCode(500, _exController.GetExString(ex))); } }