예제 #1
0
        public SongDetailsContract(Song song, ContentLanguagePreference languagePreference,
                                   SongListBaseContract[] pools, ISpecialTags specialTags, IUserPermissionContext userContext, IEntryThumbPersister thumbPersister)
        {
            Song = new SongContract(song, languagePreference);

            AdditionalNames            = song.Names.GetAdditionalNamesStringForLanguage(languagePreference);
            Albums                     = song.OnAlbums.OrderBy(a => a.OriginalReleaseDate.SortableDateTime).Select(a => new AlbumContract(a, languagePreference)).ToArray();
            AlternateVersions          = song.AlternateVersions.Select(s => new SongContract(s, languagePreference, getThumbUrl: false)).OrderBy(s => s.PublishDate).ToArray();
            Artists                    = song.Artists.Select(a => new ArtistForSongContract(a, languagePreference)).OrderBy(a => a.Name).ToArray();
            ArtistString               = song.ArtistString[languagePreference];
            CanEditPersonalDescription = EntryPermissionManager.CanEditPersonalDescription(userContext, song);
            CanRemoveTagUsages         = EntryPermissionManager.CanRemoveTagUsages(userContext, song);
            CreateDate                 = song.CreateDate;
            Deleted                    = song.Deleted;
            LikeCount                  = song.UserFavorites.Count(f => f.Rating == SongVoteRating.Like);
            LyricsFromParents          = song.GetLyricsFromParents(specialTags).Select(l => new LyricsForSongContract(l, false)).ToArray();
            Notes           = song.Notes;
            OriginalVersion = (song.OriginalVersion != null && !song.OriginalVersion.Deleted ?
                               new SongForApiContract(song.OriginalVersion, null, languagePreference, SongOptionalFields.AdditionalNames | SongOptionalFields.ThumbUrl) : null);

            PVs                     = song.PVs.Select(p => new PVContract(p)).ToArray();
            ReleaseEvent            = song.ReleaseEvent != null && !song.ReleaseEvent.Deleted ? new ReleaseEventForApiContract(song.ReleaseEvent, languagePreference, ReleaseEventOptionalFields.None, thumbPersister, true) : null;
            PersonalDescriptionText = song.PersonalDescriptionText;
            var author = song.PersonalDescriptionAuthor;

            PersonalDescriptionAuthor = author != null ? new ArtistForApiContract(author, languagePreference, thumbPersister, true, ArtistOptionalFields.MainPicture) : null;
            SubjectsFromParents       = song.GetCharactersFromParents().Select(c => new ArtistForSongContract(c, languagePreference)).ToArray();
            Tags           = song.Tags.ActiveUsages.Select(u => new TagUsageForApiContract(u, languagePreference)).OrderByDescending(t => t.Count).ToArray();
            TranslatedName = new TranslatedStringContract(song.TranslatedName);
            WebLinks       = song.WebLinks.Select(w => new WebLinkContract(w)).OrderBy(w => w.DescriptionOrUrl).ToArray();

            Pools = pools;
        }
예제 #2
0
        public AlbumDetailsContract(Album album, ContentLanguagePreference languagePreference, IUserPermissionContext userContext, IAggregatedEntryImageUrlFactory thumbPersister,
                                    Func <Song, SongVoteRating?> getSongRating = null, Tag discTypeTag = null)
            : base(album, languagePreference)
        {
            ArtistLinks = album.Artists.Select(a => new ArtistForAlbumContract(a, languagePreference)).OrderBy(a => a.Name).ToArray();
            CanEditPersonalDescription = EntryPermissionManager.CanEditPersonalDescription(userContext, album);
            CanRemoveTagUsages         = EntryPermissionManager.CanRemoveTagUsages(userContext, album);
            Description     = album.Description;
            Discs           = album.Songs.Any(s => s.DiscNumber > 1) ? album.Discs.Select(d => new AlbumDiscPropertiesContract(d)).ToDictionary(a => a.DiscNumber) : new Dictionary <int, AlbumDiscPropertiesContract>(0);
            DiscTypeTypeTag = discTypeTag != null ? new TagBaseContract(discTypeTag, languagePreference) : null;
            OriginalRelease = (album.OriginalRelease != null ? new AlbumReleaseContract(album.OriginalRelease, languagePreference) : null);
            Pictures        = album.Pictures.Select(p => new EntryPictureFileContract(p, thumbPersister)).ToArray();
            PVs             = album.PVs.Select(p => new PVContract(p)).ToArray();
            Songs           = album.Songs
                              .OrderBy(s => s.DiscNumber).ThenBy(s => s.TrackNumber)
                              .Select(s => new SongInAlbumContract(s, languagePreference, false, rating: getSongRating?.Invoke(s.Song)))
                              .ToArray();
            Tags     = album.Tags.ActiveUsages.Select(u => new TagUsageForApiContract(u, languagePreference)).OrderByDescending(t => t.Count).ToArray();
            WebLinks = album.WebLinks.Select(w => new WebLinkContract(w)).OrderBy(w => w.DescriptionOrUrl).ToArray();

            PersonalDescriptionText = album.PersonalDescriptionText;
            var author = album.PersonalDescriptionAuthor;

            PersonalDescriptionAuthor = author != null ? new ArtistForApiContract(author, languagePreference, thumbPersister, ArtistOptionalFields.MainPicture) : null;

            TotalLength = Songs.All(s => s.Song != null && s.Song.LengthSeconds > 0) ? TimeSpan.FromSeconds(Songs.Sum(s => s.Song.LengthSeconds)) : TimeSpan.Zero;
        }