Ejemplo n.º 1
0
        public TagForApiContract(Tag tag,
                                 IEntryImagePersisterOld thumbPersister,
                                 ContentLanguagePreference languagePreference,
                                 TagOptionalFields optionalFields)
        {
            ParamIs.NotNull(() => tag);

            CategoryName        = tag.CategoryName;
            CreateDate          = tag.CreateDate;
            DefaultNameLanguage = tag.TranslatedName.DefaultLanguage;
            Id         = tag.Id;
            Name       = tag.TranslatedName[languagePreference];
            Status     = tag.Status;
            Targets    = (int)tag.Targets;
            UrlSlug    = tag.UrlSlug;
            UsageCount = tag.UsageCount;
            Version    = tag.Version;

            var includeAdditionalNames = optionalFields.HasFlag(TagOptionalFields.AdditionalNames);

            if (includeAdditionalNames)
            {
                AdditionalNames = tag.Names.GetAdditionalNamesStringForLanguage(languagePreference);
            }

            if (optionalFields.HasFlag(TagOptionalFields.Description))
            {
                Description = tag.Description[languagePreference];
            }

            if (optionalFields.HasFlag(TagOptionalFields.MainPicture) && tag.Thumb != null && thumbPersister != null)
            {
                MainPicture = new EntryThumbForApiContract(tag.Thumb, thumbPersister);
            }

            if (optionalFields.HasFlag(TagOptionalFields.Names))
            {
                Names = tag.Names.Select(n => new LocalizedStringWithIdContract(n)).ToArray();
            }

            if (optionalFields.HasFlag(TagOptionalFields.Parent) && tag.Parent != null)
            {
                Parent = new TagBaseContract(tag.Parent, languagePreference, includeAdditionalNames);
            }

            if (optionalFields.HasFlag(TagOptionalFields.RelatedTags))
            {
                RelatedTags = tag.RelatedTags.Select(t => new TagBaseContract(t.LinkedTag, languagePreference, includeAdditionalNames)).ToArray();
            }

            if (optionalFields.HasFlag(TagOptionalFields.TranslatedDescription))
            {
                TranslatedDescription = new EnglishTranslatedStringContract(tag.Description);
            }

            if (optionalFields.HasFlag(TagOptionalFields.WebLinks))
            {
                WebLinks = tag.WebLinks.Links.Select(w => new WebLinkForApiContract(w)).ToArray();
            }
        }
Ejemplo n.º 2
0
        public void CopyFrom_Trim()
        {
            var source = new EnglishTranslatedString();
            var target = new EnglishTranslatedStringContract {
                Original = " "
            };

            var changed = source.CopyFrom(target);

            Assert.IsFalse(changed, "changed");
            Assert.AreEqual(string.Empty, source.Original, "Original");
        }
Ejemplo n.º 3
0
        public void CopyFrom_Trim()
        {
            var source = new EnglishTranslatedString();
            var target = new EnglishTranslatedStringContract {
                Original = " "
            };

            var changed = source.CopyFrom(target);

            changed.Should().BeFalse("changed");
            source.Original.Should().Be(string.Empty, "Original");
        }
Ejemplo n.º 4
0
        public void CopyFrom_Changed()
        {
            var source = new EnglishTranslatedString("ミク", "Miku");
            var target = new EnglishTranslatedStringContract {
                Original = "ミクさんマジ天使", English = "Hatsune Miku is truly my angel"
            };

            var changed = source.CopyFrom(target);

            Assert.IsTrue(changed, "changed");
            Assert.AreEqual("ミクさんマジ天使", source.Original, "Original");
        }
Ejemplo n.º 5
0
        public void CopyFrom_Changed()
        {
            var source = new EnglishTranslatedString("ミク", "Miku");
            var target = new EnglishTranslatedStringContract {
                Original = "ミクさんマジ天使", English = "Hatsune Miku is truly my angel"
            };

            var changed = source.CopyFrom(target);

            changed.Should().BeTrue("changed");
            source.Original.Should().Be("ミクさんマジ天使", "Original");
        }
Ejemplo n.º 6
0
 public ArtistForEditContract(Artist artist, ContentLanguagePreference languagePreference)
     : base(artist, languagePreference)
 {
     BaseVoicebank       = artist.BaseVoicebank != null ? new ArtistContract(artist.BaseVoicebank, languagePreference) : null;
     DefaultNameLanguage = artist.TranslatedName.DefaultLanguage;
     Description         = new EnglishTranslatedStringContract(artist.Description);
     Groups      = artist.Groups.Select(g => new GroupForArtistContract(g, languagePreference)).OrderBy(g => g.Group.Name).ToArray();
     Names       = artist.Names.Select(n => new LocalizedStringWithIdContract(n)).ToArray();
     Pictures    = artist.Pictures.Select(p => new EntryPictureFileContract(p)).ToList();
     UpdateNotes = string.Empty;
     WebLinks    = artist.WebLinks.Select(w => new WebLinkContract(w)).OrderBy(w => w.DescriptionOrUrl).ToArray();
 }
Ejemplo n.º 7
0
 public TagForEditContract(Tag tag, bool isEmpty, IUserPermissionContext userContext)
     : base(tag, userContext.LanguagePreference)
 {
     CanDelete           = EntryPermissionManager.CanDelete(userContext, tag);
     DefaultNameLanguage = tag.TranslatedName.DefaultLanguage;
     Description         = new EnglishTranslatedStringContract(tag.Description);
     IsEmpty             = isEmpty;
     Names       = tag.Names.Select(n => new LocalizedStringWithIdContract(n)).ToArray();
     RelatedTags = tag.RelatedTags.Select(t => new TagBaseContract(t.LinkedTag, userContext.LanguagePreference, false)).ToArray();
     Thumb       = (tag.Thumb != null ? new EntryThumbContract(tag.Thumb) : null);
     UpdateNotes = string.Empty;
     WebLinks    = tag.WebLinks.Links.Select(w => new WebLinkContract(w)).OrderBy(w => w.DescriptionOrUrl).ToArray();
 }
Ejemplo n.º 8
0
        public SongForEditContract(Song song, ContentLanguagePreference languagePreference)
            : base(song, languagePreference)
        {
            ParamIs.NotNull(() => song);

            Artists             = song.Artists.Select(a => new ArtistForSongContract(a, languagePreference)).OrderBy(a => a.Name).ToArray();
            DefaultNameLanguage = song.TranslatedName.DefaultLanguage;
            Lyrics          = song.Lyrics.Select(l => new LyricsForSongContract(l)).ToArray();
            Names           = song.Names.Select(n => new LocalizedStringWithIdContract(n)).ToArray();
            Notes           = new EnglishTranslatedStringContract(song.Notes);
            OriginalVersion = (song.OriginalVersion != null && !song.OriginalVersion.Deleted ? new SongContract(song.OriginalVersion, languagePreference) : null);
            PVs             = song.PVs.Select(p => new PVContract(p)).ToArray();
            Tags            = song.Tags.TagNames.ToArray();
            UpdateNotes     = string.Empty;
            WebLinks        = song.WebLinks.Select(w => new WebLinkContract(w)).OrderBy(w => w.DescriptionOrUrl).ToArray();
        }
Ejemplo n.º 9
0
 public AlbumForEditContract(Album album, ContentLanguagePreference languagePreference)
     : base(album, languagePreference)
 {
     ArtistLinks         = album.Artists.Select(a => new ArtistForAlbumContract(a, languagePreference)).OrderBy(a => a.Name).ToArray();
     DefaultNameLanguage = album.TranslatedName.DefaultLanguage;
     Description         = new EnglishTranslatedStringContract(album.Description);
     Identifiers         = album.Identifiers.Select(i => i.Value).ToArray();
     Names           = album.Names.Select(n => new LocalizedStringWithIdContract(n)).ToArray();
     OriginalRelease = (album.OriginalRelease != null ? new AlbumReleaseContract(album.OriginalRelease) : null);
     Pictures        = album.Pictures.Select(p => new EntryPictureFileContract(p)).ToList();
     PVs             = album.PVs.Select(p => new PVContract(p)).ToArray();
     Songs           = album.Songs
                       .OrderBy(s => s.DiscNumber).ThenBy(s => s.TrackNumber)
                       .Select(s => new SongInAlbumEditContract(s, languagePreference)).ToArray();
     UpdateNotes = string.Empty;
     WebLinks    = album.WebLinks.Select(w => new WebLinkContract(w)).OrderBy(w => w.DescriptionOrUrl).ToArray();
 }
Ejemplo n.º 10
0
        public virtual bool CopyFrom(EnglishTranslatedStringContract contract)
        {
            ParamIs.NotNull(() => contract);

            var changed = false;

            if (Original != contract.Original)
            {
                Original = contract.Original;
                changed  = true;
            }

            if (English != contract.English)
            {
                English = contract.English;
                changed = true;
            }

            return(changed);
        }
Ejemplo n.º 11
0
        public ArtistForEditContract(Artist artist, ContentLanguagePreference languagePreference, IAggregatedEntryImageUrlFactory imageStore)
            : base(artist, languagePreference)
        {
            BaseVoicebank       = artist.BaseVoicebank != null ? new ArtistContract(artist.BaseVoicebank, languagePreference) : null;
            DefaultNameLanguage = artist.TranslatedName.DefaultLanguage;
            Description         = new EnglishTranslatedStringContract(artist.Description);
            Groups        = artist.Groups.Where(g => g.LinkType == ArtistLinkType.Group).Select(g => new ArtistForArtistContract(g, languagePreference)).OrderBy(g => g.Parent.Name).ToArray();
            Illustrator   = artist.ArtistLinksOfType(ArtistLinkType.Illustrator, Domain.LinkDirection.ManyToOne).Select(g => new ArtistContract(g, languagePreference)).FirstOrDefault();
            Names         = artist.Names.Select(n => new LocalizedStringWithIdContract(n)).ToArray();
            Pictures      = artist.Pictures.Select(p => new EntryPictureFileContract(p, imageStore)).ToList();
            UpdateNotes   = string.Empty;
            VoiceProvider = artist.ArtistLinksOfType(ArtistLinkType.VoiceProvider, Domain.LinkDirection.ManyToOne).Select(g => new ArtistContract(g, languagePreference)).FirstOrDefault();
            WebLinks      = artist.WebLinks.Select(w => new WebLinkContract(w)).OrderBy(w => w.DescriptionOrUrl).ToArray();

            AssociatedArtists = artist.Groups
                                .Where(a => a.LinkType != ArtistLinkType.Group &&
                                       (a.Parent.Id != Illustrator?.Id || a.LinkType != ArtistLinkType.Illustrator) &&
                                       (a.Parent.Id != VoiceProvider?.Id || a.LinkType != ArtistLinkType.VoiceProvider))
                                .Select(g => new ArtistForArtistContract(g, languagePreference))
                                .ToArray();
        }
Ejemplo n.º 12
0
        public SongForEditContract(Song song, ContentLanguagePreference languagePreference)
            : base(song, languagePreference)
        {
            ParamIs.NotNull(() => song);

            var firstAlbum = song.Albums.Where(a => a.Album.OriginalReleaseDate.IsFullDate).OrderBy(a => a.Album.OriginalReleaseDate).FirstOrDefault();

            AlbumEventId        = firstAlbum?.Album.OriginalReleaseEvent?.Id;
            AlbumReleaseDate    = song.FirstAlbumDate != null ? (DateTime?)DateTime.SpecifyKind(song.FirstAlbumDate.Value, DateTimeKind.Utc) : null;
            Artists             = song.Artists.Select(a => new ArtistForSongContract(a, languagePreference)).OrderBy(a => a.Name).ToArray();
            DefaultNameLanguage = song.TranslatedName.DefaultLanguage;
            HasAlbums           = song.Albums.Any();
            Lyrics          = song.Lyrics.Select(l => new LyricsForSongContract(l)).ToArray();
            Names           = song.Names.Select(n => new LocalizedStringWithIdContract(n)).ToArray();
            Notes           = new EnglishTranslatedStringContract(song.Notes);
            OriginalVersion = (song.OriginalVersion != null && !song.OriginalVersion.Deleted ? new SongContract(song.OriginalVersion, languagePreference) : null);
            PVs             = song.PVs.Select(p => new PVContract(p)).ToArray();
            ReleaseEvent    = song.ReleaseEvent != null ? new ReleaseEventContract(song.ReleaseEvent) : null;
            Tags            = song.Tags.Tags.Select(t => t.Id).ToArray();
            UpdateNotes     = string.Empty;
            WebLinks        = song.WebLinks.Select(w => new WebLinkContract(w)).OrderBy(w => w.DescriptionOrUrl).ToArray();
        }