From f395258832f209efc9827ec6afcc87e9060f26eb Mon Sep 17 00:00:00 2001 From: Natlinux81 <97396587+Natlinux81@users.noreply.github.com> Date: Mon, 29 Aug 2022 22:20:55 +0200 Subject: [PATCH] implementet ErrorMessages --- .../Commands/CreateTournamentCommand.cs | 4 ++- .../Commands/DeleteTournamentCommand.cs | 2 +- .../Commands/UpdateTournamentCommand.cs | 2 +- .../Queries/GetAllTournamentsQuery.cs | 2 +- Apollon.WPF/Commands/AddTournamentCommand.cs | 3 +- .../Commands/DeleteTournamentCommand.cs | 3 +- Apollon.WPF/Commands/EditTournamentCommand.cs | 3 +- .../Commands/LoadTournamentsCommand.cs | 3 +- .../ViewModels/AddEditDetailsViewModel.cs | 19 +++++++++++- Apollon.WPF/ViewModels/OverviewViewModel.cs | 17 +++++++++++ .../ViewModels/WarningDeleteViewModel.cs | 20 ++++++++++++- .../Views/Components/AddEditDetails.xaml | 11 +++++++ Apollon.WPF/Views/OverviewView.xaml | 29 +++++++++++++++++-- Apollon.WPF/Views/WarningDeleteView.xaml | 12 ++++++++ 14 files changed, 118 insertions(+), 12 deletions(-) diff --git a/Apollon.EntityFramework/Commands/CreateTournamentCommand.cs b/Apollon.EntityFramework/Commands/CreateTournamentCommand.cs index 5bda453..eb2445f 100644 --- a/Apollon.EntityFramework/Commands/CreateTournamentCommand.cs +++ b/Apollon.EntityFramework/Commands/CreateTournamentCommand.cs @@ -21,8 +21,10 @@ namespace Apollon.EntityFramework.Commands public async Task Execute(Tournament tournament) { + throw new Exception(); + using (TournamentsDbContext context = _contextFactory.Create()) - { + { TournamentDto tournamentDto = new TournamentDto() { Id = tournament.Id, diff --git a/Apollon.EntityFramework/Commands/DeleteTournamentCommand.cs b/Apollon.EntityFramework/Commands/DeleteTournamentCommand.cs index 4eafca8..3230cb6 100644 --- a/Apollon.EntityFramework/Commands/DeleteTournamentCommand.cs +++ b/Apollon.EntityFramework/Commands/DeleteTournamentCommand.cs @@ -19,7 +19,7 @@ namespace Apollon.EntityFramework.Commands } public async Task Execute(Guid id) - { + { using (TournamentsDbContext context = _contextFactory.Create()) { TournamentDto tournamentDto = new TournamentDto() diff --git a/Apollon.EntityFramework/Commands/UpdateTournamentCommand.cs b/Apollon.EntityFramework/Commands/UpdateTournamentCommand.cs index 338be09..f06cd65 100644 --- a/Apollon.EntityFramework/Commands/UpdateTournamentCommand.cs +++ b/Apollon.EntityFramework/Commands/UpdateTournamentCommand.cs @@ -19,7 +19,7 @@ namespace Apollon.EntityFramework.Commands } public async Task Execute(Tournament tournament) - { + { using (TournamentsDbContext context = _contextFactory.Create()) { TournamentDto tournamentDto = new TournamentDto() diff --git a/Apollon.EntityFramework/Queries/GetAllTournamentsQuery.cs b/Apollon.EntityFramework/Queries/GetAllTournamentsQuery.cs index 5494ec3..5ec300c 100644 --- a/Apollon.EntityFramework/Queries/GetAllTournamentsQuery.cs +++ b/Apollon.EntityFramework/Queries/GetAllTournamentsQuery.cs @@ -20,7 +20,7 @@ namespace Apollon.EntityFramework.Queries } public async Task> Execute() - { + { using (TournamentsDbContext context = _contextFactory.Create()) { IEnumerable tournamentsDtos = await context.Tournaments.ToListAsync(); diff --git a/Apollon.WPF/Commands/AddTournamentCommand.cs b/Apollon.WPF/Commands/AddTournamentCommand.cs index 600996a..747def6 100644 --- a/Apollon.WPF/Commands/AddTournamentCommand.cs +++ b/Apollon.WPF/Commands/AddTournamentCommand.cs @@ -28,6 +28,7 @@ namespace Apollon.WPF.Commands { AddEditDetailsViewModel detailsViewModel = _addTournamentViewModel.AddEditDetailsViewModel; + detailsViewModel.ErrorMessage = null; detailsViewModel.IsSubmitting = true; Tournament tournament = new Tournament( @@ -51,7 +52,7 @@ namespace Apollon.WPF.Commands } catch (Exception) { - throw; + detailsViewModel.ErrorMessage = "Daten konnten nicht gespeichert werden!"; } finally { diff --git a/Apollon.WPF/Commands/DeleteTournamentCommand.cs b/Apollon.WPF/Commands/DeleteTournamentCommand.cs index 11eef16..f7af36e 100644 --- a/Apollon.WPF/Commands/DeleteTournamentCommand.cs +++ b/Apollon.WPF/Commands/DeleteTournamentCommand.cs @@ -31,6 +31,7 @@ namespace Apollon.WPF.Commands public override async Task ExecuteAsync(object parameter) { + _warningDeleteViewModel.ErrorMessage = null; _warningDeleteViewModel.IsDeleting = true; Tournament tournament = _overviewListingItemViewModel.Tournament; @@ -43,7 +44,7 @@ namespace Apollon.WPF.Commands } catch (Exception) { - throw; + _warningDeleteViewModel.ErrorMessage = "Speichern fehlgeschlagen!"; } finally { diff --git a/Apollon.WPF/Commands/EditTournamentCommand.cs b/Apollon.WPF/Commands/EditTournamentCommand.cs index 6231603..bd4a237 100644 --- a/Apollon.WPF/Commands/EditTournamentCommand.cs +++ b/Apollon.WPF/Commands/EditTournamentCommand.cs @@ -26,6 +26,7 @@ namespace Apollon.WPF.Commands { AddEditDetailsViewModel detailsViewModel = _editTournamentViewModel.AddEditDetailsViewModel; + detailsViewModel.ErrorMessage = null; detailsViewModel.IsSubmitting = true; Tournament tournament = new Tournament( @@ -48,7 +49,7 @@ namespace Apollon.WPF.Commands catch (Exception) { - throw; + detailsViewModel.ErrorMessage = "Daten konnten nicht gespeichert werden!"; } finally { diff --git a/Apollon.WPF/Commands/LoadTournamentsCommand.cs b/Apollon.WPF/Commands/LoadTournamentsCommand.cs index aa8902b..4c2d710 100644 --- a/Apollon.WPF/Commands/LoadTournamentsCommand.cs +++ b/Apollon.WPF/Commands/LoadTournamentsCommand.cs @@ -21,6 +21,7 @@ namespace Apollon.WPF.Commands public override async Task ExecuteAsync(object parameter) { + _overviewViewModel.ErrorMessage = null; _overviewViewModel.IsLoading = true; try @@ -29,7 +30,7 @@ namespace Apollon.WPF.Commands } catch (Exception) { - throw; + _overviewViewModel.ErrorMessage = "Daten konnten nicht geladen werden! Bitte starten Sie die Anwendung neu!"; } finally { diff --git a/Apollon.WPF/ViewModels/AddEditDetailsViewModel.cs b/Apollon.WPF/ViewModels/AddEditDetailsViewModel.cs index 7078853..7f5ea6c 100644 --- a/Apollon.WPF/ViewModels/AddEditDetailsViewModel.cs +++ b/Apollon.WPF/ViewModels/AddEditDetailsViewModel.cs @@ -139,7 +139,24 @@ namespace Apollon.WPF.ViewModels } } - public bool CanSubmit => !string.IsNullOrEmpty(TournamentName); + private string _errorMessage; + public string ErrorMessage + { + get + { + return _errorMessage; + } + set + { + _errorMessage = value; + OnPropertyChanged(nameof(ErrorMessage)); + OnPropertyChanged(nameof(HasErrorMessage)); + } + } + + public bool HasErrorMessage => !string.IsNullOrEmpty(ErrorMessage); + + public bool CanSubmit => !string.IsNullOrEmpty(TournamentName); public ICommand SubmitCommand { get; } public ICommand CancelCommand { get; } diff --git a/Apollon.WPF/ViewModels/OverviewViewModel.cs b/Apollon.WPF/ViewModels/OverviewViewModel.cs index 78542e8..4234f92 100644 --- a/Apollon.WPF/ViewModels/OverviewViewModel.cs +++ b/Apollon.WPF/ViewModels/OverviewViewModel.cs @@ -29,6 +29,23 @@ namespace Apollon.WPF.ViewModels } } + private string _errorMessage; + public string ErrorMessage + { + get + { + return _errorMessage; + } + set + { + _errorMessage = value; + OnPropertyChanged(nameof(ErrorMessage)); + OnPropertyChanged(nameof(HasErrorMessage)); + } + } + + public bool HasErrorMessage => !string.IsNullOrEmpty(ErrorMessage); + public ICommand AddTournamentCommand { get; } public ICommand LoadTournamentsCommand { get; } public ICommand NavigateNavBarCommand { get; } diff --git a/Apollon.WPF/ViewModels/WarningDeleteViewModel.cs b/Apollon.WPF/ViewModels/WarningDeleteViewModel.cs index c0745a6..a195de3 100644 --- a/Apollon.WPF/ViewModels/WarningDeleteViewModel.cs +++ b/Apollon.WPF/ViewModels/WarningDeleteViewModel.cs @@ -24,7 +24,25 @@ namespace Apollon.WPF.ViewModels OnPropertyChanged(nameof(IsDeleting)); } } - public ICommand WarningCloseCommand { get;} + + private string _errorMessage; + public string ErrorMessage + { + get + { + return _errorMessage; + } + set + { + _errorMessage = value; + OnPropertyChanged(nameof(ErrorMessage)); + OnPropertyChanged(nameof(HasErrorMessage)); + } + } + + public bool HasErrorMessage => !string.IsNullOrEmpty(ErrorMessage); + + public ICommand WarningCloseCommand { get;} public ICommand DeleteCommand { get; } public WarningDeleteViewModel(ModalNavigationStore modalNavigationStore,TournamentsStore tournamentsStore, OverviewListingItemViewModel overviewListingItemViewModel) { diff --git a/Apollon.WPF/Views/Components/AddEditDetails.xaml b/Apollon.WPF/Views/Components/AddEditDetails.xaml index 42c4f6d..af9d9c0 100644 --- a/Apollon.WPF/Views/Components/AddEditDetails.xaml +++ b/Apollon.WPF/Views/Components/AddEditDetails.xaml @@ -6,6 +6,9 @@ xmlns:local="clr-namespace:Apollon.WPF.Views.Components" xmlns:custom="clr-namespace:LoadingSpinnerControl;assembly=LoadingSpinnerControl" mc:Ignorable="d"> + + + @@ -127,6 +130,14 @@ HorizontalAlignment="Left" Background="LightGray"/> + + + FontSize="14"> - + + + + + + + + + + + + + + + + @@ -51,6 +54,15 @@ Color="{StaticResource BrushPrimary1}" IsLoading="{Binding IsDeleting}"/> +