Edit Function are available

This commit is contained in:
Natlinux81
2022-08-18 17:49:23 +02:00
parent 99c3bd58e1
commit 44e2e17c15
17 changed files with 203 additions and 100 deletions

View File

@@ -17,15 +17,15 @@ namespace Apollon.WPF
public partial class App : Application public partial class App : Application
{ {
private readonly ModalNavigationStore _modalNavigationStore; private readonly ModalNavigationStore _modalNavigationStore;
private readonly TournamentStore _tournamentStore; private readonly TournamentsStore _tournamentStore;
private readonly SelectedTournamentStore _selectedTournamentStore; private readonly SelectedTournamentsStore _selectedTournamentStore;
public App() public App()
{ {
_modalNavigationStore = new ModalNavigationStore(); _modalNavigationStore = new ModalNavigationStore();
_tournamentStore = new TournamentStore(); _tournamentStore = new TournamentsStore();
_selectedTournamentStore = new SelectedTournamentStore(); _selectedTournamentStore = new SelectedTournamentsStore(_tournamentStore);
} }
protected override void OnStartup(StartupEventArgs e) protected override void OnStartup(StartupEventArgs e)
{ {

View File

@@ -11,18 +11,18 @@ namespace Apollon.WPF.Commands
{ {
public class AddTournamentCommand : AsyncCommandBase public class AddTournamentCommand : AsyncCommandBase
{ {
private readonly TournamentStore _tournamentStore; private readonly TournamentsStore _tournamentStore;
private readonly ModalNavigationStore _modalNavigationStore; private readonly ModalNavigationStore _modalNavigationStore;
private AddTournamentViewModel _addTournamentViewModel; private AddTournamentViewModel _addTournamentViewModel;
public AddTournamentCommand(TournamentStore tournamentStore, ModalNavigationStore modalNavigationStore) public AddTournamentCommand(TournamentsStore tournamentStore, ModalNavigationStore modalNavigationStore)
{ {
_tournamentStore = tournamentStore; _tournamentStore = tournamentStore;
_modalNavigationStore = modalNavigationStore; _modalNavigationStore = modalNavigationStore;
} }
public AddTournamentCommand(AddTournamentViewModel addTournamentViewModel, TournamentStore tournamentStore, ModalNavigationStore modalNavigationStore) public AddTournamentCommand(AddTournamentViewModel addTournamentViewModel, TournamentsStore tournamentStore, ModalNavigationStore modalNavigationStore)
{ {
_addTournamentViewModel = addTournamentViewModel; _addTournamentViewModel = addTournamentViewModel;
_tournamentStore = tournamentStore; _tournamentStore = tournamentStore;
@@ -31,15 +31,16 @@ namespace Apollon.WPF.Commands
public override async Task ExecuteAsync(object parameter) public override async Task ExecuteAsync(object parameter)
{ {
AddEditDetailsViewModel formViewModel = _addTournamentViewModel.AddEditDetailsViewModel; AddEditDetailsViewModel detailsViewModel = _addTournamentViewModel.AddEditDetailsViewModel;
Tournament tournament = new Tournament( Tournament tournament = new Tournament(
formViewModel.Organisation, Guid.NewGuid(),
formViewModel.TournamentName, detailsViewModel.Organisation,
formViewModel.Competition, detailsViewModel.TournamentName,
formViewModel.StartDate, detailsViewModel.Competition,
formViewModel.EndDate, detailsViewModel.StartDate,
formViewModel.Location, detailsViewModel.EndDate,
formViewModel.Rounds); detailsViewModel.Location,
detailsViewModel.Rounds);
try try
{ {

View File

@@ -1,4 +1,6 @@
using Apollon.WPF.Stores; using Apollon.WPF.Models;
using Apollon.WPF.Stores;
using Apollon.WPF.ViewModels;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -9,18 +11,41 @@ namespace Apollon.WPF.Commands
{ {
public class EditTournamentCommand : AsyncCommandBase public class EditTournamentCommand : AsyncCommandBase
{ {
private readonly EditTournamentViewModel _editTournamentViewModel;
private readonly TournamentsStore _tournamentStore;
private readonly ModalNavigationStore _modalNavigationStore; private readonly ModalNavigationStore _modalNavigationStore;
public EditTournamentCommand(ModalNavigationStore modalNavigationStore) public EditTournamentCommand(EditTournamentViewModel editTournamentViewModel, TournamentsStore tournamentStore, ModalNavigationStore modalNavigationStore)
{ {
_editTournamentViewModel = editTournamentViewModel;
_tournamentStore = tournamentStore;
_modalNavigationStore = modalNavigationStore; _modalNavigationStore = modalNavigationStore;
} }
public override async Task ExecuteAsync(object parameter) public override async Task ExecuteAsync(object parameter)
{ {
// Edit Tournament to Database AddEditDetailsViewModel detailsViewModel = _editTournamentViewModel.AddEditDetailsViewModel;
Tournament tournament = new Tournament(
_editTournamentViewModel.TournamentId,
detailsViewModel.Organisation,
detailsViewModel.TournamentName,
detailsViewModel.Competition,
detailsViewModel.StartDate,
detailsViewModel.EndDate,
detailsViewModel.Location,
detailsViewModel.Rounds);
_modalNavigationStore.Close(); try
{
await _tournamentStore.Update(tournament);
_modalNavigationStore.Close();
}
catch (Exception)
{
throw;
}
} }
} }
} }

View File

@@ -10,10 +10,10 @@ namespace Apollon.WPF.Commands
{ {
public class OpenAddTournamentCommand : CommandBase public class OpenAddTournamentCommand : CommandBase
{ {
private readonly TournamentStore _tournamentStore; private readonly TournamentsStore _tournamentStore;
private readonly ModalNavigationStore _modalNavigationStore; private readonly ModalNavigationStore _modalNavigationStore;
public OpenAddTournamentCommand(TournamentStore tournamentStore, ModalNavigationStore modalNavigationStore) public OpenAddTournamentCommand(TournamentsStore tournamentStore, ModalNavigationStore modalNavigationStore)
{ {
_tournamentStore = tournamentStore; _tournamentStore = tournamentStore;
_modalNavigationStore = modalNavigationStore; _modalNavigationStore = modalNavigationStore;

View File

@@ -12,17 +12,21 @@ namespace Apollon.WPF.Commands
public class OpenEditTournamentCommand : CommandBase public class OpenEditTournamentCommand : CommandBase
{ {
private readonly ModalNavigationStore _modalNavigationStore; private readonly ModalNavigationStore _modalNavigationStore;
private readonly OverviewListingItemViewModel _overviewListingItemViewModel;
private readonly TournamentsStore _tournamentStore;
public OpenEditTournamentCommand(OverviewListingItemViewModel overviewListingItemViewModel, TournamentsStore tournamentStore, ModalNavigationStore modalNavigationStore)
public OpenEditTournamentCommand(ModalNavigationStore modalNavigationStore)
{ {
_overviewListingItemViewModel = overviewListingItemViewModel;
_tournamentStore = tournamentStore;
_modalNavigationStore = modalNavigationStore; _modalNavigationStore = modalNavigationStore;
} }
public override void Execute(object parameter) public override void Execute(object parameter)
{ {
EditTournamentViewModel editTournamentViewModel = new EditTournamentViewModel(_modalNavigationStore); Tournament tournament = _overviewListingItemViewModel.Tournament;
EditTournamentViewModel editTournamentViewModel = new EditTournamentViewModel(_modalNavigationStore, _tournamentStore, tournament);
_modalNavigationStore.CurrentViewModel = editTournamentViewModel; _modalNavigationStore.CurrentViewModel = editTournamentViewModel;
} }
} }

View File

@@ -8,17 +8,7 @@ namespace Apollon.WPF.Models
{ {
public class Tournament public class Tournament
{ {
public Tournament(string organisation, string tournamentName, string competition, DateTime startDate, DateTime endDate, string location, int rounds = 0) public Guid Id { get; }
{
Organisation = organisation;
TournamentName = tournamentName;
Competition = competition;
StartDate = startDate;
EndDate = endDate;
Location = location;
Rounds = rounds;
}
public string Organisation { get; } public string Organisation { get; }
public string TournamentName { get; } public string TournamentName { get; }
public string Competition { get; } public string Competition { get; }
@@ -27,5 +17,16 @@ namespace Apollon.WPF.Models
public string Location { get; } public string Location { get; }
public int Rounds { get; } public int Rounds { get; }
public Tournament(Guid id, string organisation, string tournamentName, string competition, DateTime startDate, DateTime endDate, string location, int rounds = 0)
{
Id = id;
Organisation = organisation;
TournamentName = tournamentName;
Competition = competition;
StartDate = startDate;
EndDate = endDate;
Location = location;
Rounds = rounds;
}
} }
} }

View File

@@ -1,29 +0,0 @@
using Apollon.WPF.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Apollon.WPF.Stores
{
public class SelectedTournamentStore
{
private Tournament _selectedTournament;
public Tournament SelectedTournament
{
get
{
return _selectedTournament;
}
set
{
_selectedTournament = value;
SelectedTournamentChanged?.Invoke();
}
}
public event Action SelectedTournamentChanged;
}
}

View File

@@ -0,0 +1,46 @@
using Apollon.WPF.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Apollon.WPF.Stores
{
public class SelectedTournamentsStore
{
private readonly TournamentsStore _tournamentStore;
private Tournament _selectedTournament;
public Tournament SelectedTournament
{
get
{
return _selectedTournament;
}
set
{
_selectedTournament = value;
SelectedTournamentChanged?.Invoke();
}
}
public event Action SelectedTournamentChanged;
public SelectedTournamentsStore(TournamentsStore tournamentstore)
{
_tournamentStore = tournamentstore;
_tournamentStore.TournamentUpdated += TournamentStore_TournamentUpdated;
}
private void TournamentStore_TournamentUpdated(Tournament tournament)
{
if(tournament.Id == SelectedTournament?.Id)
{
SelectedTournament = tournament;
}
}
}
}

View File

@@ -7,13 +7,19 @@ using System.Threading.Tasks;
namespace Apollon.WPF.Stores namespace Apollon.WPF.Stores
{ {
public class TournamentStore public class TournamentsStore
{ {
public event Action<Tournament> TournamentAdded; public event Action<Tournament> TournamentAdded;
public event Action<Tournament> TournamentUpdated;
public async Task Add(Tournament tournament) public async Task Add(Tournament tournament)
{ {
TournamentAdded?.Invoke(tournament); TournamentAdded?.Invoke(tournament);
} }
public async Task Update (Tournament tournament)
{
TournamentUpdated?.Invoke(tournament);
}
} }
} }

View File

@@ -13,7 +13,7 @@ namespace Apollon.WPF.ViewModels
{ {
public AddEditDetailsViewModel AddEditDetailsViewModel { get; } public AddEditDetailsViewModel AddEditDetailsViewModel { get; }
public AddTournamentViewModel(TournamentStore tournamentStore, ModalNavigationStore modalNavigationStore) public AddTournamentViewModel(TournamentsStore tournamentStore, ModalNavigationStore modalNavigationStore)
{ {
ICommand submitCommand = new AddTournamentCommand(this, tournamentStore,modalNavigationStore); ICommand submitCommand = new AddTournamentCommand(this, tournamentStore,modalNavigationStore);
ICommand cancelCommand = new CloseModalCommand(modalNavigationStore); ICommand cancelCommand = new CloseModalCommand(modalNavigationStore);

View File

@@ -12,13 +12,26 @@ namespace Apollon.WPF.ViewModels
{ {
public class EditTournamentViewModel : ViewModelBase public class EditTournamentViewModel : ViewModelBase
{ {
public Guid TournamentId { get;}
public AddEditDetailsViewModel AddEditDetailsViewModel { get; } public AddEditDetailsViewModel AddEditDetailsViewModel { get; }
public EditTournamentViewModel(ModalNavigationStore modalNavigationStore) public EditTournamentViewModel(ModalNavigationStore modalNavigationStore, TournamentsStore tournamentStore, Tournament tournament)
{ {
ICommand submitCommand = new EditTournamentCommand(modalNavigationStore); TournamentId = tournament.Id;
ICommand submitCommand = new EditTournamentCommand(this, tournamentStore, modalNavigationStore);
ICommand cancelCommand = new CloseModalCommand(modalNavigationStore); ICommand cancelCommand = new CloseModalCommand(modalNavigationStore);
AddEditDetailsViewModel = new AddEditDetailsViewModel(submitCommand, cancelCommand); AddEditDetailsViewModel = new AddEditDetailsViewModel(submitCommand, cancelCommand)
{
Organisation = tournament.Organisation,
TournamentName = tournament.TournamentName,
Competition = tournament.Competition,
StartDate = tournament.StartDate,
EndDate = tournament.EndDate,
Location = tournament.Location,
Rounds = tournament.Rounds,
};
} }
} }

View File

@@ -10,7 +10,7 @@ namespace Apollon.WPF.ViewModels
{ {
public class OverviewDetailsViewModel : ViewModelBase public class OverviewDetailsViewModel : ViewModelBase
{ {
private readonly SelectedTournamentStore _selectedTournamentStore; private readonly SelectedTournamentsStore _selectedTournamentStore;
private Tournament SelectedTournament => _selectedTournamentStore.SelectedTournament; private Tournament SelectedTournament => _selectedTournamentStore.SelectedTournament;
@@ -23,7 +23,7 @@ namespace Apollon.WPF.ViewModels
public string Location => SelectedTournament?.Location ?? "kein Ort"; public string Location => SelectedTournament?.Location ?? "kein Ort";
public int Rounds => SelectedTournament?.Rounds ?? 0; public int Rounds => SelectedTournament?.Rounds ?? 0;
public OverviewDetailsViewModel(SelectedTournamentStore selectedTournamentStore) public OverviewDetailsViewModel(SelectedTournamentsStore selectedTournamentStore)
{ {
_selectedTournamentStore = selectedTournamentStore; _selectedTournamentStore = selectedTournamentStore;

View File

@@ -1,4 +1,6 @@
using Apollon.WPF.Models; using Apollon.WPF.Commands;
using Apollon.WPF.Models;
using Apollon.WPF.Stores;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -10,15 +12,27 @@ namespace Apollon.WPF.ViewModels
{ {
public class OverviewListingItemViewModel : ViewModelBase public class OverviewListingItemViewModel : ViewModelBase
{ {
public Tournament Tournament { get;} public Tournament Tournament { get; private set; }
public string TournamentName => Tournament.TournamentName; public string TournamentName => Tournament.TournamentName;
public string Location => Tournament.Location; public string Location => Tournament.Location;
public ICommand EditCommand { get; }
public ICommand DeleteCommand { get; } public ICommand DeleteCommand { get; }
public OverviewListingItemViewModel(Tournament tournament) public OverviewListingItemViewModel(Tournament tournament, TournamentsStore tournamentStore, ModalNavigationStore modalNavigationStore)
{ {
Tournament = tournament; Tournament = tournament;
EditCommand = new OpenEditTournamentCommand(this, tournamentStore, modalNavigationStore);
}
public void Update(Tournament tournament)
{
Tournament = tournament;
OnPropertyChanged(nameof(TournamentName));
OnPropertyChanged(nameof(Location));
} }
} }
} }

View File

@@ -14,9 +14,9 @@ namespace Apollon.WPF.ViewModels
public class OverviewListingViewModel : ViewModelBase public class OverviewListingViewModel : ViewModelBase
{ {
private readonly ObservableCollection<OverviewListingItemViewModel> _overviewListingItemViewModels; private readonly ObservableCollection<OverviewListingItemViewModel> _overviewListingItemViewModels;
private readonly SelectedTournamentStore _selectedTournamentStore; private readonly SelectedTournamentsStore _selectedTournamentStore;
private readonly ModalNavigationStore _modalNavigationStore; private readonly ModalNavigationStore _modalNavigationStore;
private readonly TournamentStore _tournamentStore; private readonly TournamentsStore _tournamentStore;
public IEnumerable<OverviewListingItemViewModel> OverviewListingItemViewModels => _overviewListingItemViewModels; public IEnumerable<OverviewListingItemViewModel> OverviewListingItemViewModels => _overviewListingItemViewModels;
@@ -38,7 +38,7 @@ namespace Apollon.WPF.ViewModels
} }
} }
public OverviewListingViewModel(SelectedTournamentStore selectedTournamentStore, ModalNavigationStore modalNavigationStore, TournamentStore tournamentStore) public OverviewListingViewModel(SelectedTournamentsStore selectedTournamentStore, ModalNavigationStore modalNavigationStore, TournamentsStore tournamentStore)
{ {
_tournamentStore = tournamentStore; _tournamentStore = tournamentStore;
_selectedTournamentStore = selectedTournamentStore; _selectedTournamentStore = selectedTournamentStore;
@@ -46,11 +46,13 @@ namespace Apollon.WPF.ViewModels
_overviewListingItemViewModels = new ObservableCollection<OverviewListingItemViewModel>(); _overviewListingItemViewModels = new ObservableCollection<OverviewListingItemViewModel>();
_tournamentStore.TournamentAdded += TournamentStore_TournamentAdded; _tournamentStore.TournamentAdded += TournamentStore_TournamentAdded;
_tournamentStore.TournamentUpdated += TournamentStore_TournamentUpdated;
} }
protected override void Dispose() protected override void Dispose()
{ {
_tournamentStore.TournamentAdded -= TournamentStore_TournamentAdded; _tournamentStore.TournamentAdded -= TournamentStore_TournamentAdded;
_tournamentStore.TournamentUpdated -= TournamentStore_TournamentUpdated;
base.Dispose(); base.Dispose();
} }
@@ -59,10 +61,21 @@ namespace Apollon.WPF.ViewModels
AddTournament(tournament); AddTournament(tournament);
} }
private void TournamentStore_TournamentUpdated(Tournament tournament)
{
OverviewListingItemViewModel overviewViewModel =
_overviewListingItemViewModels.FirstOrDefault(y => y.Tournament.Id == tournament.Id);
if(overviewViewModel != null)
{
overviewViewModel.Update(tournament);
}
}
private void AddTournament(Tournament tournament) private void AddTournament(Tournament tournament)
{ {
// TO DO EditTournamentCommand OverviewListingItemViewModel itemViewModel = new OverviewListingItemViewModel(tournament, _tournamentStore, _modalNavigationStore);
_overviewListingItemViewModels.Add(new OverviewListingItemViewModel(tournament)); _overviewListingItemViewModels.Add(itemViewModel);
} }
} }
} }

View File

@@ -16,19 +16,13 @@ namespace Apollon.WPF.ViewModels
public OverviewDetailsViewModel OverviewDetailsViewModel{ get; } public OverviewDetailsViewModel OverviewDetailsViewModel{ get; }
public ICommand AddTournamentCommand { get; } public ICommand AddTournamentCommand { get; }
public ICommand EditTournamentCommand { get;}
public OverviewViewModel(TournamentsStore tournamentStore, SelectedTournamentsStore selectedTournamentStore, ModalNavigationStore modalNavigationStore)
public OverviewViewModel(TournamentStore tournamentStore, SelectedTournamentStore selectedTournamentStore, ModalNavigationStore modalNavigationStore)
{ {
OverviewListingViewModel = new OverviewListingViewModel(selectedTournamentStore, modalNavigationStore, tournamentStore); OverviewListingViewModel = new OverviewListingViewModel(selectedTournamentStore, modalNavigationStore, tournamentStore);
OverviewDetailsViewModel = new OverviewDetailsViewModel(selectedTournamentStore); OverviewDetailsViewModel = new OverviewDetailsViewModel(selectedTournamentStore);
AddTournamentCommand = new OpenAddTournamentCommand(tournamentStore, modalNavigationStore); AddTournamentCommand = new OpenAddTournamentCommand(tournamentStore, modalNavigationStore);
EditTournamentCommand = new OpenEditTournamentCommand(modalNavigationStore);
} }
} }
} }

View File

@@ -37,19 +37,35 @@
Margin="0 0 4 0"/> Margin="0 0 4 0"/>
<TextBlock Text="{Binding Location}"/> <TextBlock Text="{Binding Location}"/>
</WrapPanel> </WrapPanel>
<WrapPanel Grid.Column="1">
<Button Grid.Column="1" <Button
Background="Transparent"
BorderThickness="0"
Cursor="Hand"
ToolTip="Löschen"
Command="{Binding EditCommand}">
<iconPacks:PackIconMaterial Kind="Pencil"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Grid.Column="1"
Foreground="#0000a0"
Margin="4"/>
</Button>
<Button Grid.Column="1"
Background="Transparent" Background="Transparent"
BorderThickness="0" BorderThickness="0"
Cursor="Hand" Cursor="Hand"
ToolTip="Löschen" ToolTip="Löschen"
Command="{Binding DeleteCommand}"> Command="{Binding DeleteCommand}">
<iconPacks:PackIconMaterial Kind="TrashCan" <iconPacks:PackIconMaterial Kind="TrashCan"
VerticalAlignment="Center" VerticalAlignment="Center"
HorizontalAlignment="Center" HorizontalAlignment="Center"
Grid.Column="1" Grid.Column="1"
Foreground="Red"/> Foreground="Red"/>
</Button> </Button>
</WrapPanel>
</Grid> </Grid>
</DataTemplate> </DataTemplate>

View File

@@ -113,8 +113,7 @@
Height="40" Height="40"
Width="210" Width="210"
Margin="40" Margin="40"
Cursor="Hand" Cursor="Hand"/>
Command="{Binding EditTournamentCommand}"/>
</StackPanel> </StackPanel>
</Grid> </Grid>