Example #1
0
        public async Task Update(EditAlbumDto input)
        {
            var @album = input.MapTo <Album>();

            @album.TenantId = AbpSession.GetTenantId();
            int i = 0;
            await _albumRepository.UpdateAsync(@album);
        }
Example #2
0
        public void Edit_ChangesProperties()
        {
            // Arrange
            var context = this.ServiceProvider.GetRequiredService <WmipDbContext>();
            var album   = new Album
            {
                Id             = 1,
                AlbumCoverLink = "first",
                Genre          = "first",
                Name           = "first",
                ReleaseDate    = DateTime.Now.AddDays(-1),
                ReleaseStage   = ReleaseStage.Secret,
                SpotifyLink    = "first",
                AlbumsSongs    = new List <AlbumSong>()
                {
                    new AlbumSong {
                        SongId = 1
                    }
                }
            };

            context.Albums.Add(album);
            context.SaveChanges();
            var albumsService = new AlbumsService(context);
            var editInfo      = new EditAlbumDto()
            {
                Id              = 1,
                AlbumCoverLink  = "newlink",
                Genre           = "newgenre",
                Name            = "newname",
                ReleaseDate     = DateTime.Now.AddDays(1),
                ReleaseStage    = ReleaseStage.Announced,
                SpotifyLink     = "newSLink",
                SelectedSongIds = new int[] { 1, 2, 3, 4, 5, 6, 7 }
            };

            // Act
            albumsService.Edit(editInfo);

            //Assert
            Assert.Equal(editInfo.Name, context.Albums.First().Name);
            Assert.Equal(editInfo.AlbumCoverLink, context.Albums.First().AlbumCoverLink);
            Assert.Equal(editInfo.Genre, context.Albums.First().Genre);
            Assert.Equal(editInfo.ReleaseDate, context.Albums.First().ReleaseDate);
            Assert.Equal(editInfo.ReleaseStage, context.Albums.First().ReleaseStage);
            Assert.Equal(editInfo.SpotifyLink, context.Albums.First().SpotifyLink);
            Assert.Equal(editInfo.SelectedSongIds, context.Albums.First().AlbumsSongs.Select(s => s.SongId));
        }
Example #3
0
        public bool Edit(EditAlbumDto editInfo)
        {
            try
            {
                var album = this.context.Albums.Find(editInfo.Id);
                if (album == null)
                {
                    return(false);
                }

                album.Name           = editInfo.Name;
                album.Genre          = editInfo.Genre;
                album.ReleaseDate    = editInfo.ReleaseDate;
                album.ReleaseStage   = editInfo.ReleaseStage;
                album.SpotifyLink    = editInfo.SpotifyLink;
                album.AlbumCoverLink = editInfo.AlbumCoverLink;
                album.ApprovalStatus = ApprovalStatus.Pending;
                album.AlbumsSongs.Clear();

                if (editInfo.SelectedSongIds != null)
                {
                    foreach (var songId in editInfo.SelectedSongIds)
                    {
                        var currentAlbumSong = this.context.AlbumsSongs.FirstOrDefault(s => s.SongId == songId && s.AlbumId == editInfo.Id);
                        if (currentAlbumSong == null)
                        {
                            currentAlbumSong = new AlbumSong
                            {
                                SongId = songId,
                            };
                        }

                        album.AlbumsSongs.Add(currentAlbumSong);
                    }
                }

                this.context.Albums.Update(album);
                this.context.SaveChanges();
                return(true);
            }
            catch
            {
                return(false);
            }
        }