public async Task <MovieVm> Handle(CreateMovie request, CancellationToken cancellationToken) { var artists = _artistRepository.List(x => request.Actors.Contains(x.Id)).ToList(); var movie = new Movie(Guid.NewGuid(), request.Name, request.ReleaseYear, request.Duration, request.Summary, request.Country, request.MovieGenres); movie.Actors = artists; string imageUrl; if (request.Poster?.HasValue() == true) { if (!string.IsNullOrEmpty(movie.Poster)) { await _fileUtils.RemoveByUrlAsync(movie.Poster); } var fileName = $"movies/{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 = movie.Poster; } movie.Poster = imageUrl; movie = await _movieRepository.AddAsync(movie); return(movie.ToVm()); }
public async Task <ArtistVm> Handle(CreateArtist request, CancellationToken cancellationToken) { var artist = new Artist(Guid.NewGuid(), request.Name, request.Age, request.Description); string imageUrl; if (request.Photo?.HasValue() == true) { if (!string.IsNullOrEmpty(artist.Photo)) { await _fileUtils.RemoveByUrlAsync(artist.Photo); } var fileName = $"artists/{Guid.NewGuid()}{request.Photo.Name.GetExtension()}"; imageUrl = await _fileUtils.UploadAsync(request.Photo, fileName); if (imageUrl.IsNull()) { throw new Exception("Erro ao Importar o poster"); } } else { imageUrl = artist.Photo; } artist.Photo = imageUrl; await _artistRepository.AddAsync(artist); return(artist.ToVm()); }
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()); }
public async Task <BookVm> Handle(CreateBook request, CancellationToken cancellationToken) { var book = new Book(Guid.NewGuid(), request.Name, request.ReleaseYear, request.Pages, request.Summary, request.Publisher, request.ArtistId); string imageUrl; if (request.Poster?.HasValue() == true) { if (!string.IsNullOrEmpty(book.Poster)) { await _fileUtils.RemoveByUrlAsync(book.Poster); } var fileName = $"books/{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 = book.Poster; } book.Poster = imageUrl; await _bookRepository.AddAsync(book); return(book.ToVm()); }