Exemple #1
0
        public async Task <SongVm> Handle(CreateSong request, CancellationToken cancellationToken)
        {
            var    song = new Song(Guid.NewGuid(), request.Name, request.AlbumId, request.ReleaseYear, request.Duration, request.ArtistId);
            string imageUrl;

            if (request.Poster?.HasValue() == true)
            {
                if (!string.IsNullOrEmpty(song.Poster))
                {
                    await _fileUtils.RemoveByUrlAsync(song.Poster);
                }

                var fileName = $"songs/{Guid.NewGuid()}{request.Poster.Name.GetExtension()}";

                imageUrl = await _fileUtils.UploadAsync(request.Poster, fileName);

                if (imageUrl.IsNull())
                {
                    throw new Exception("Erro ao Importar o poster");
                }
            }
            else
            {
                imageUrl = song.Poster;
            }
            song.Poster = imageUrl;
            await _songRepository.AddAsync(song);

            return(song.ToVm());
        }
Exemple #2
0
        public async Task AddAsync(string url, string author, string title, Guid playlistId)
        {
            var playlist = await _playlistRepository.GetAsync(playlistId);

            if (playlist == null)
            {
                throw new Exception($"Playlist with id: '{playlistId}' does not exists");
            }

            var song = new Song(url, author, title, playlistId);
            await _songRepository.AddAsync(song);
        }