コード例 #1
0
ファイル: Album.cs プロジェクト: ffdd270/vocadb
        public virtual ArtistForAlbum AddArtist(string name, bool isSupport, ArtistRoles roles)
        {
            ParamIs.NotNullOrEmpty(() => name);

            var link = new ArtistForAlbum(this, name, isSupport, roles);

            AllArtists.Add(link);

            return(link);
        }
コード例 #2
0
ファイル: Album.cs プロジェクト: Shyany/vocadb
        public virtual CollectionDiffWithValue <ArtistForAlbum, ArtistForAlbum> SyncArtists(
            IEnumerable <ArtistForAlbumContract> newArtists, Func <ArtistContract, Artist> artistGetter)
        {
            var create = new Func <ArtistForAlbumContract, ArtistForAlbum>(contract => {
                ArtistForAlbum link = null;

                if (contract.Artist != null)
                {
                    var artist = artistGetter(contract.Artist);

                    if (!HasArtist(artist))
                    {
                        link      = AddArtist(artist, contract.IsSupport, contract.Roles);
                        link.Name = contract.IsCustomName ? contract.Name : null;
                    }
                }
                else
                {
                    link = AddArtist(contract.Name, contract.IsSupport, contract.Roles);
                }

                return(link);
            });

            var delete = new Action <ArtistForAlbum>(link => {
                link.Delete();
            });

            var update = new Func <ArtistForAlbum, ArtistForAlbumContract, bool>((old, newEntry) => {
                if (!old.ContentEquals(newEntry))
                {
                    old.IsSupport = newEntry.IsSupport;
                    old.Roles     = newEntry.Roles;
                    old.Name      = newEntry.IsCustomName ? newEntry.Name : null;
                    return(true);
                }
                else
                {
                    return(false);
                }
            });

            var diff = CollectionHelper.SyncWithContent(AllArtists, newArtists.ToArray(), (a1, a2) => a1.Id == a2.Id, create, update, delete);

            if (diff.Changed)
            {
                UpdateArtistString();
            }

            return(diff);
        }
コード例 #3
0
ファイル: Album.cs プロジェクト: ffdd270/vocadb
        public virtual void DeleteArtistForAlbum(ArtistForAlbum artistForAlbum)
        {
            if (!artistForAlbum.Album.Equals(this))
            {
                throw new ArgumentException("Artist is not attached to album", "artistForAlbum");
            }

            AllArtists.Remove(artistForAlbum);

            if (artistForAlbum.Artist != null)
            {
                artistForAlbum.Artist.AllAlbums.Remove(artistForAlbum);
            }

            UpdateArtistString();
        }
コード例 #4
0
ファイル: Album.cs プロジェクト: ffdd270/vocadb
        /// <summary>
        /// Checks whether this album has a specific artist.
        /// </summary>
        /// <param name="artistForAlbum">Artist to be checked. Cannot be null.</param>
        /// <returns>True if the artist has this album. Otherwise false.</returns>
        public virtual bool HasArtistForAlbum(ArtistForAlbum artistForAlbum)
        {
            ParamIs.NotNull(() => artistForAlbum);

            return(Artists.Any(a => a.ArtistLinkEquals(artistForAlbum)));
        }