Exemple #1
0
        public void Post(AlbumDTO value)
        {
            Album model = new Album()
            {
                Name        = value.Name,
                ReleaseYear = value.ReleaseYear,
                StudioId    = value.StudioId
            };

            IAlbumRepository.Create(model);
            for (int i = 0; i < value.ArtistId.Count; i++)
            {
                ArtistAlbum ArtistAlbum = new ArtistAlbum()
                {
                    AlbumId  = model.Id,
                    ArtistId = value.ArtistId[i]
                };
                IArtistAlbumRepository.Create(ArtistAlbum);
            }
            for (int i = 0; i < value.SongId.Count; i++)
            {
                SongAlbum SongAlbum = new SongAlbum()
                {
                    AlbumId = model.Id,
                    SongId  = value.ArtistId[i]
                };
                ISongAlbumRepository.Create(SongAlbum);
            }
        }
Exemple #2
0
        public void Put(int id, AlbumDTO value)
        {
            Album model = IAlbumRepository.Get(id);

            if (value.Name != null)
            {
                model.Name = value.Name;
            }
            if (value.ReleaseYear != 0)
            {
                model.ReleaseYear = value.ReleaseYear;
            }
            if (value.StudioId != 0)
            {
                model.StudioId = value.StudioId;
            }
            IAlbumRepository.Update(model);
            if (value.ArtistId != null)
            {
                IEnumerable <ArtistAlbum> MyArtistAlbums = IArtistAlbumRepository.GetAll().Where(x => x.AlbumId == id);
                foreach (ArtistAlbum MyArtistAlbum in MyArtistAlbums)
                {
                    IArtistAlbumRepository.Delete(MyArtistAlbum);
                }
                for (int i = 0; i < value.ArtistId.Count; i++)
                {
                    ArtistAlbum ArtistAlbum = new ArtistAlbum()
                    {
                        AlbumId  = model.Id,
                        ArtistId = value.ArtistId[i]
                    };
                    IArtistAlbumRepository.Create(ArtistAlbum);
                }
            }
            if (value.SongId != null)
            {
                IEnumerable <SongAlbum> MySongAlbums = ISongAlbumRepository.GetAll().Where(x => x.AlbumId == id);
                foreach (SongAlbum MySongAlbum in MySongAlbums)
                {
                    ISongAlbumRepository.Delete(MySongAlbum);
                }
                for (int i = 0; i < value.SongId.Count; i++)
                {
                    SongAlbum SongAlbum = new SongAlbum()
                    {
                        AlbumId = model.Id,
                        SongId  = value.ArtistId[i]
                    };
                    ISongAlbumRepository.Create(SongAlbum);
                }
            }
        }