Esempio n. 1
0
        /// <summary>
        /// Gets a list of tags the user can view. Guaranteed to not return null. Returns an empty collection
        /// when no tags are found.
        /// </summary>
        /// <returns>A collection of <see cref="Entity.Tag" /> instances.</returns>
        private IEnumerable <Entity.Tag> GetTagsForUser()
        {
            var tags = new List <Entity.Tag>();
            var hasMediaObjectTags = false;

            using (var repo = new MetadataTagRepository())
            {
                tags.AddRange(GetTagsForAlbums(repo));

                if (!UserCanViewRootAlbum)
                {
                    // When the user can view the entire gallery, the GetTagsForAlbums() function returned all the tags, so we don't
                    // need to look specifically at the tags belonging to media objects. But for restricted users we need this step.
                    var tagsForMediaObjects = GetTagsForMediaObjects(repo);
                    hasMediaObjectTags = tagsForMediaObjects.Any();

                    tags.AddRange(tagsForMediaObjects);
                }
            }

            // Optimization: When there are media object tags, we need to combine the album and media object tags; otherwise we can
            // just return the tags.
            if (hasMediaObjectTags)
            {
                return(SortAndFilter(tags.GroupBy(t => t.Value).Select(t => new Entity.Tag {
                    Value = t.Key, Count = t.Sum(t1 => t1.Count)
                })));
            }
            else
            {
                return(SortAndFilter(tags));
            }
        }
Esempio n. 2
0
        ///// <summary>
        ///// Determines whether the current user can view the specified <paramref name="album" />.
        ///// </summary>
        ///// <param name="album">The album.</param>
        ///// <returns><c>true</c> if the user can view the album; otherwise, <c>false</c>.</returns>
        //private bool CanUserViewAlbum(IAlbum album)
        //{
        //	return SecurityManager.IsUserAuthorized(SecurityActions.ViewAlbumOrMediaObject, SearchOptions.Roles, album.Id, SearchOptions.GalleryId, SearchOptions.IsUserAuthenticated, album.IsPrivate, SecurityActionsOption.RequireOne, album.IsVirtualAlbum);
        //}

        /// <summary>
        /// Gets a list of all tags in the gallery, regardless of a user's permission.
        /// </summary>
        /// <returns>IEnumerable{TagDto}.</returns>
        private IEnumerable <string> GetTags()
        {
            using (var repo = new MetadataTagRepository())
            {
                return(repo.Where(t => t.FKGalleryId == SearchOptions.GalleryId && t.Metadata.MetaName == TagName)
                       .Select(t => t.Tag.TagName).Distinct());
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Gets a list of all tags in the gallery, regardless of a user's permission.
        /// </summary>
        /// <returns>IEnumerable{TagDto}.</returns>
        private IEnumerable <Entity.Tag> GetTags()
        {
            using (var repo = new MetadataTagRepository())
            {
                var tags = repo.Where(t => t.FKGalleryId == SearchOptions.GalleryId && t.Metadata.MetaName == TagName)
                           .GroupBy(t => t.FKTagName)
                           .Select(t => new Entity.Tag {
                    Value = t.Key, Count = t.Count()
                });

                return(SortAndFilter(tags));
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Gets a list of tags from database for the gallery, sorted on the specified property.
        /// </summary>
        /// <returns><see cref="List{T}" /> where T is <see cref="Entity.TagCacheItem" />.</returns>
        private List <Entity.TagCacheItem> GetAllSortedTagsFromDb()
        {
            using (var repo = new MetadataTagRepository())
            {
                var query = repo.Where(t => t.FKGalleryId == SearchOptions.GalleryId && t.Metadata.MetaName == TagName)
                            .GroupBy(t => t.FKTagName)
                            .Select(t => new Entity.TagCacheItem
                {
                    Value        = t.Key,
                    CountAll     = t.Count(),
                    CountPrivate = t.Count(mt => mt.Metadata.MediaObject.Album.IsPrivate || mt.Metadata.Album.IsPrivate)
                });

                return(Sort(query).ToList());
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Gets a list of tags the user can view. Guaranteed to not return null. Returns an empty collection
        /// when no tags are found.
        /// </summary>
        /// <returns>A collection of <see cref="TagDto" /> instances.</returns>
        private IEnumerable <string> GetTagsForUser()
        {
            var tags = new List <TagDto>();

            using (var repo = new MetadataTagRepository())
            {
                tags.AddRange(GetTagsForAlbums(repo));

                if (!UserCanViewRootAlbum)
                {
                    // When the user can view the entire gallery, the GetTagsForAlbums() function returned all the tags, so we don't
                    // need to look specifically at the tags belonging to media objects. But for restricted users we need this step.
                    tags.AddRange(GetTagsForMediaObjects(repo));
                }
            }

            return(tags.Select(t => t.TagName).Distinct());
        }
Esempio n. 6
0
        /// <summary>
        /// Gets a list of tags the user can view. Guaranteed to not return null. Returns an empty collection
        /// when no tags are found.
        /// </summary>
        /// <returns>A collection of <see cref="Entity.Tag" /> instances.</returns>
        private IEnumerable<Entity.Tag> GetTagsForUser()
        {
            var tags = new List<Entity.Tag>();
              var hasMediaObjectTags = false;

              using (var repo = new MetadataTagRepository())
              {
            tags.AddRange(GetTagsForAlbums(repo));

            if (!UserCanViewRootAlbum)
            {
              // When the user can view the entire gallery, the GetTagsForAlbums() function returned all the tags, so we don't
              // need to look specifically at the tags belonging to media objects. But for restricted users we need this step.
              var tagsForMediaObjects = GetTagsForMediaObjects(repo);
              hasMediaObjectTags = tagsForMediaObjects.Any();

              tags.AddRange(tagsForMediaObjects);
            }
              }

              // Optimization: When there are media object tags, we need to combine the album and media object tags; otherwise we can
              // just return the tags.
              if (hasMediaObjectTags)
              {
            return SortAndFilter(tags.GroupBy(t => t.Value).Select(t => new Entity.Tag {Value = t.Key, Count = t.Sum(t1 => t1.Count)}));
              }
              else
              {
            return SortAndFilter(tags);
              }
        }
Esempio n. 7
0
        /// <summary>
        /// Gets a list of all tags in the gallery, regardless of a user's permission.
        /// </summary>
        /// <returns>IEnumerable{TagDto}.</returns>
        private IEnumerable<Entity.Tag> GetTags()
        {
            using (var repo = new MetadataTagRepository())
              {
            var tags = repo.Where(t => t.FKGalleryId == SearchOptions.GalleryId && t.Metadata.MetaName == TagName)
              .GroupBy(t => t.FKTagName)
              .Select(t => new Entity.Tag { Value = t.Key, Count = t.Count() });

            return SortAndFilter(tags);
              }
        }