diff --git a/Services/IImageService.cs b/Services/IImageService.cs index b4b8e5f..1eb24ff 100644 --- a/Services/IImageService.cs +++ b/Services/IImageService.cs @@ -22,5 +22,6 @@ namespace BackgroundBuilder.Services BitmapImage background, string primaryPath, string? overlayPath = null); + Task MoveFile(string sourcePath); } } diff --git a/Services/ImageService.cs b/Services/ImageService.cs index 415f0c0..e9b8abf 100644 --- a/Services/ImageService.cs +++ b/Services/ImageService.cs @@ -43,10 +43,27 @@ namespace BackgroundBuilder.Services var compositeBmp = RenderComposite(overlay, background, OverlayOffset); SaveBitmap(compositeBmp, primaryPath); - SaveBitmap(compositeBmp, "\\\\SRV-DADOS\\Wallpaper$\\Wallpaper.png"); await Task.FromResult((primaryPath, savedOverlayPath)); } + public async Task MoveFile(string sourcePath) + { + string destinationPath = "\\\\SRV-DADOS\\Wallpaper$\\Wallpaper.png"; + try + { + var directory = Path.GetDirectoryName(destinationPath); + if (!Directory.Exists(directory)) + { + Directory.CreateDirectory(directory!); + } + File.Copy(sourcePath, destinationPath, true); + } + catch (Exception ex) + { + MessageBox.Show($"Erro ao mover a imagem:\n{ex.Message}\n\nCaminho: {sourcePath} para {destinationPath}"); + } + await Task.CompletedTask; + } /// /// Renders a plus the diff --git a/ViewModels/MainWindowViewModel.cs b/ViewModels/MainWindowViewModel.cs index dbafde8..cc59bef 100644 --- a/ViewModels/MainWindowViewModel.cs +++ b/ViewModels/MainWindowViewModel.cs @@ -62,6 +62,7 @@ namespace BackgroundBuilder.ViewModels public RelayCommand UpdateCommand { get; } public RelayCommand ExportImageCommand { get; } public RelayCommand ImportExcelCommand { get; } + public RelayCommand UploadImageCommand { get; } public MainWindowViewModel( IContatoRepository repo, @@ -81,6 +82,7 @@ namespace BackgroundBuilder.ViewModels UpdateCommand = new RelayCommand(async _ => await UpdateAsync(), _ => SelectedContatos != null); ExportImageCommand = new RelayCommand(async _ => await RenderImageAsync(), _ => BackgroundImage != null && OverlayElement != null); ImportExcelCommand = new RelayCommand(async _ => await ImportExcelAsync()); + UploadImageCommand = new RelayCommand(async _ => await UploadImageAsync()); } public void RefreshTaskbarInfo() @@ -181,6 +183,33 @@ namespace BackgroundBuilder.ViewModels } } } + private async Task UploadImageAsync() + { + var dlg = new OpenFileDialog + { + Filter = "PNG Image|*.png" + }; + if (dlg.ShowDialog() == true) + { + try + { + await _imageService.MoveFile(dlg.FileName); + MessageBox.Show( + "ConcluĂ­do!", + "Confirm Upload", + MessageBoxButton.OK, + MessageBoxImage.Information); + } + catch (Exception ex) + { + MessageBox.Show( + $"Erro ao mover a imagem:\n{ex.Message}", + "Upload Failed", + MessageBoxButton.OK, + MessageBoxImage.Error); + } + } + } public async Task UpdateAsync() { diff --git a/Views/MainWindow.xaml b/Views/MainWindow.xaml index 07d295b..2afa39d 100644 --- a/Views/MainWindow.xaml +++ b/Views/MainWindow.xaml @@ -136,6 +136,7 @@ + +