Esempio n. 1
0
        public static MetaItem[] ToMetaItems(IGalleryObjectMetadataItemCollection metadataItems, IGalleryObject galleryObject)
        {
            var metaItems  = new MetaItem[metadataItems.Count];
            var metaDefs   = Factory.LoadGallerySetting(galleryObject.GalleryId).MetadataDisplaySettings;
            var moProfiles = ProfileController.GetProfile().MediaObjectProfiles;

            for (int i = 0; i < metaItems.Length; i++)
            {
                IGalleryObjectMetadataItem md = metadataItems[i];

                metaItems[i] = new MetaItem
                {
                    Id         = md.MediaObjectMetadataId,
                    MediaId    = galleryObject.Id,
                    MTypeId    = (int)md.MetadataItemName,
                    GTypeId    = (int)galleryObject.GalleryObjectType,
                    Desc       = md.Description,
                    Value      = md.Value,
                    IsEditable = metaDefs.Find(md.MetadataItemName).IsEditable
                };

                if (md.MetadataItemName == MetadataItemName.Rating)
                {
                    ReplaceAvgRatingWithUserRating(metaItems[i], moProfiles);
                }
            }

            return(metaItems);
        }
Esempio n. 2
0
        private static void SaveAlbumIdToProfile(int albumId, string userName)
        {
            ProfileEntity profileEntity = ProfileController.GetProfile(userName);

            profileEntity.UserAlbumId = albumId;

            ProfileController.SaveProfile(profileEntity);
        }
Esempio n. 3
0
        private static void SaveAlbumIdToProfile(int albumId, string userName, int galleryId)
        {
            IUserProfile profile = ProfileController.GetProfile(userName);

            IUserGalleryProfile pg = profile.GetGalleryProfile(galleryId);

            pg.UserAlbumId = albumId;

            ProfileController.SaveProfile(profile);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        ///// <summary>
        ///// Gets the ID of the album for the current user's personal album (that is, this is the album that was created when the
        ///// user's account was created). If user albums are disabled, this function returns int.MinValue. It also returns int.MinValue
        ///// if the profile is null or the UserAlbumId property is not found  (this should not typically occur).
        ///// </summary>
        ///// <returns>Returns the ID of the album for the current user's personal album.</returns>
        //public static int GetUserAlbumId()
        //{
        //  int albumId = int.MinValue;

        //  if (!Config.Core.EnableUserAlbum)
        //    return albumId;

        //  if ((System.Web.HttpContext.Current.Profile != null) && (System.Web.HttpContext.Current.Profile[Constants.USER_ALBUM_ID_PROFILE_NAME] != null))
        //  {
        //    int tmpAlbumId = Convert.ToInt32(System.Web.HttpContext.Current.Profile[Constants.USER_ALBUM_ID_PROFILE_NAME], CultureInfo.InvariantCulture);

        //    albumId = (tmpAlbumId > 0 ? tmpAlbumId : albumId);
        //  }

        //  return albumId;
        //}

        /// <summary>
        /// Gets the ID of the album for the specified user's personal album (that is, this is the album that was created when the
        /// user's account was created). If user albums are disabled or the UserAlbumId property is not found in the profile,
        /// this function returns int.MinValue. This function executes faster than <see cref="GetUserAlbum"/> but it does not
        /// validate that the album exists.
        /// </summary>
        /// <returns>Returns the ID of the album for the current user's personal album.</returns>
        public static int GetUserAlbumId(string userName)
        {
            int albumId = Int32.MinValue;

            if (!Config.GetCore().EnableUserAlbum)
            {
                return(albumId);
            }

            int tmpAlbumId = ProfileController.GetProfile(userName).UserAlbumId;

            albumId = (tmpAlbumId > 0 ? tmpAlbumId : albumId);

            return(albumId);
        }
Esempio n. 6
0
        /// <summary>
        /// Persists the current user's sort preference for the specified <paramref name="album" />. No action is taken if the
        /// album is virtual. Anonymous user data is stored in session only; logged on users' data are permanently stored.
        /// </summary>
        /// <param name="album">The album whose sort preference is to be preserved.</param>
        /// <param name="sortByMetaName">Name of the metadata item to sort by.</param>
        /// <param name="sortAscending">Indicates the sort direction.</param>
        private static void PersistUserSortPreference(IAlbum album, MetadataItemName sortByMetaName, bool sortAscending)
        {
            if (album.IsVirtualAlbum)
            {
                return;
            }

            var profile = ProfileController.GetProfile();

            var aProfile = profile.AlbumProfiles.Find(album.Id);

            if (aProfile == null)
            {
                profile.AlbumProfiles.Add(new AlbumProfile(album.Id, sortByMetaName, sortAscending));
            }
            else
            {
                aProfile.SortByMetaName = sortByMetaName;
                aProfile.SortAscending  = sortAscending;
            }

            ProfileController.SaveProfile(profile);
        }