public static void SetItemByNameCounts(this IItemByName item, Guid userId, ItemByNameCounts counts)
        {
            var current = item.UserItemCountList.FirstOrDefault(i => i.UserId == userId);

            if (current != null)
            {
                item.UserItemCountList.Remove(current);
            }

            counts.UserId = userId;
            item.UserItemCountList.Add(counts);
        }
        /// <summary>
        /// Sets the item counts.
        /// </summary>
        /// <param name="artist">The artist.</param>
        /// <param name="userId">The user id.</param>
        /// <param name="allItems">All items.</param>
        private void SetItemCounts(MusicArtist artist, Guid? userId, IEnumerable<IHasArtist> allItems)
        {
            var name = artist.Name;

            var items = allItems
                .Where(i => i.HasArtist(name))
                .ToList();

            var counts = new ItemByNameCounts
            {
                TotalCount = items.Count,

                SongCount = items.OfType<Audio>().Count(),

                AlbumCount = items.OfType<MusicAlbum>().Count(),

                MusicVideoCount = items.OfType<MusicVideo>().Count()
            };

            if (userId.HasValue)
            {
                artist.UserItemCounts[userId.Value] = counts;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Attaches the item by name counts.
        /// </summary>
        /// <param name="dto">The dto.</param>
        /// <param name="item">The item.</param>
        /// <param name="user">The user.</param>
        private void AttachItemByNameCounts(BaseItemDto dto, IItemByName item, User user)
        {
            ItemByNameCounts counts;

            if (user == null)
            {
                //counts = item.ItemCounts;
                return;
            }
            if (!item.UserItemCounts.TryGetValue(user.Id, out counts))
            {
                counts = new ItemByNameCounts();
            }

            dto.ChildCount = counts.TotalCount;

            dto.AdultVideoCount = counts.AdultVideoCount;
            dto.AlbumCount = counts.AlbumCount;
            dto.EpisodeCount = counts.EpisodeCount;
            dto.GameCount = counts.GameCount;
            dto.MovieCount = counts.MovieCount;
            dto.MusicVideoCount = counts.MusicVideoCount;
            dto.SeriesCount = counts.SeriesCount;
            dto.SongCount = counts.SongCount;
            dto.TrailerCount = counts.TrailerCount;
        }