Exemple #1
0
        private static void DeleteUserAlbum(string userName)
        {
            IAlbum album = GetUserAlbum(userName);

            if (album != null)
            {
                AlbumController.DeleteAlbum(album);
            }
        }
Exemple #2
0
        /// <summary>
        /// Verifies the user album for the specified <paramref name="userName">user</paramref> exists if it is supposed to exist
        /// (creating it if necessary), or does not exist if not (that is, deleting it if necessary). Returns a reference to the user
        /// album if a user album exists or has just been created; otherwise returns null. Also returns null if user albums are
        /// disabled at the application level or userAlbumParentAlbumId in galleryserverpro.config does not match an existing album.
        /// A user album is created if user albums are enabled but none for the user exists. If user albums are enabled at the
        /// application level but the user has disabled them in his profile, the album is deleted if it exists.
        /// </summary>
        /// <param name="userName">Name of the user.</param>
        /// <returns>Returns a reference to the user album for the specified <paramref name="userName">user</paramref>, or null
        /// if user albums are disabled or the userAlbumParentAlbumId in galleryserverpro.config does not match an existing album.</returns>
        /// <exception cref="ArgumentException">Thrown when <paramref name="userName" /> is null or empty.</exception>
        public static IAlbum ValidateUserAlbum(string userName)
        {
            if (!Config.GetCore().EnableUserAlbum)
            {
                return(null);
            }

            if (String.IsNullOrEmpty(userName))
            {
                throw new ArgumentException("userName");
            }

            bool userAlbumExists      = false;
            bool userAlbumShouldExist = ProfileController.GetProfile(userName).EnableUserAlbum;

            IAlbum album = null;

            int albumId = GetUserAlbumId(userName);

            if (albumId > int.MinValue)
            {
                try
                {
                    // Try loading the album.
                    album = Factory.LoadAlbumInstance(albumId, false);

                    userAlbumExists = true;
                }
                catch (InvalidAlbumException) { }
            }

            // Delete or create if necessary. Deleting should only be needed if
            if (userAlbumExists && !userAlbumShouldExist)
            {
                try
                {
                    AlbumController.DeleteAlbum(album);
                }
                catch (Exception ex)
                {
                    // Log any errors that happen but don't let them bubble up.
                    AppErrorController.LogError(ex);
                }
                finally
                {
                    album = null;
                }
            }
            else if (!userAlbumExists && userAlbumShouldExist)
            {
                album = AlbumController.CreateUserAlbum(userName);
            }

            return(album);
        }