Ejemplo n.º 1
0
        public IQueryable <Entity.GalleryItem> Sort(Entity.AlbumAction albumAction)
        {
            // POST /api/albums/getsortedalbum -
            try
            {
                return(GalleryObjectController.SortGalleryItems(albumAction));
            }
            catch (InvalidAlbumException)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content      = new StringContent(String.Format("Could not find album with ID = {0}", albumAction.Album.Id)),
                    ReasonPhrase = "Album Not Found"
                });
            }
            catch (GallerySecurityException)
            {
                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"
                });
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sorts the gallery items passed to this method and return. No changes are made to the data store.
        /// When the album is virtual, the <see cref="Entity.AlbumAction.Album.GalleryItems" /> property
        /// must be populated with the items to sort. For non-virtual albums (those with a valid ID), the
        /// gallery objects are retrieved based on the ID and then sorted. The sort preference is saved to
        /// the current user's profile, except when the album is virtual. The method incorporates security to
        /// ensure only authorized items are returned to the user.
        /// </summary>
        /// <param name="albumAction">An instance containing the album to sort and the sort preferences.</param>
        /// <returns>IQueryable{Entity.GalleryItem}.</returns>
        /// <exception cref="GalleryServerPro.Events.CustomExceptions.GallerySecurityException">Thrown when
        /// the user does not have view permission to the specified album.</exception>
        public static IQueryable <Entity.GalleryItem> SortGalleryItems(Entity.AlbumAction albumAction)
        {
            IAlbum album;

            if (albumAction.Album.Id > int.MinValue)
            {
                album = Factory.LoadAlbumInstance(albumAction.Album.Id, true);

                SecurityManager.ThrowIfUserNotAuthorized(SecurityActions.ViewAlbumOrMediaObject, RoleController.GetGalleryServerRolesForUser(), album.Id, album.GalleryId, Utils.IsAuthenticated, album.IsPrivate, album.IsVirtualAlbum);

                PersistUserSortPreference(album, albumAction.SortByMetaNameId, albumAction.SortAscending);
            }
            else
            {
                album = Factory.CreateAlbumInstance(albumAction.Album.Id, albumAction.Album.GalleryId);
                album.IsVirtualAlbum   = (albumAction.Album.VirtualType != (int)VirtualAlbumType.NotVirtual);
                album.VirtualAlbumType = (VirtualAlbumType)albumAction.Album.VirtualType;

                var roles = RoleController.GetGalleryServerRolesForUser();

                foreach (var galleryItem in albumAction.Album.GalleryItems)
                {
                    if (galleryItem.IsAlbum)
                    {
                        var childAlbum = Factory.LoadAlbumInstance(galleryItem.Id, false);

                        if (SecurityManager.IsUserAuthorized(SecurityActions.ViewAlbumOrMediaObject, roles, childAlbum.Id, childAlbum.GalleryId, Utils.IsAuthenticated, childAlbum.IsPrivate, childAlbum.IsVirtualAlbum))
                        {
                            album.AddGalleryObject(childAlbum);
                        }
                    }
                    else
                    {
                        var mediaObject = Factory.LoadMediaObjectInstance(galleryItem.Id);

                        if (SecurityManager.IsUserAuthorized(SecurityActions.ViewAlbumOrMediaObject, roles, mediaObject.Parent.Id, mediaObject.GalleryId, Utils.IsAuthenticated, mediaObject.Parent.IsPrivate, ((IAlbum)mediaObject.Parent).IsVirtualAlbum))
                        {
                            album.AddGalleryObject(mediaObject);
                        }
                    }
                }
            }

            var galleryObjects = album
                                 .GetChildGalleryObjects(GalleryObjectType.All, !Utils.IsAuthenticated)
                                 .ToSortedList(albumAction.SortByMetaNameId, albumAction.SortAscending, album.GalleryId);

            return(ToGalleryItems(galleryObjects).AsQueryable());
        }