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
{
private readonly ModalNavigationStore _modalNavigationStore;
private readonly TournamentStore _tournamentStore;
private readonly SelectedTournamentStore _selectedTournamentStore;
private readonly TournamentsStore _tournamentStore;
private readonly SelectedTournamentsStore _selectedTournamentStore;
public App()
{
_modalNavigationStore = new ModalNavigationStore();
_tournamentStore = new TournamentStore();
_selectedTournamentStore = new SelectedTournamentStore();
_tournamentStore = new TournamentsStore();
_selectedTournamentStore = new SelectedTournamentsStore(_tournamentStore);
}
protected override void OnStartup(StartupEventArgs e)
{

View File

@@ -11,18 +11,18 @@ namespace Apollon.WPF.Commands
{
public class AddTournamentCommand : AsyncCommandBase
{
private readonly TournamentStore _tournamentStore;
private readonly TournamentsStore _tournamentStore;
private readonly ModalNavigationStore _modalNavigationStore;
private AddTournamentViewModel _addTournamentViewModel;
public AddTournamentCommand(TournamentStore tournamentStore, ModalNavigationStore modalNavigationStore)
public AddTournamentCommand(TournamentsStore tournamentStore, ModalNavigationStore modalNavigationStore)
{
_tournamentStore = tournamentStore;
_modalNavigationStore = modalNavigationStore;
}
public AddTournamentCommand(AddTournamentViewModel addTournamentViewModel, TournamentStore tournamentStore, ModalNavigationStore modalNavigationStore)
public AddTournamentCommand(AddTournamentViewModel addTournamentViewModel, TournamentsStore tournamentStore, ModalNavigationStore modalNavigationStore)
{
_addTournamentViewModel = addTournamentViewModel;
_tournamentStore = tournamentStore;
@@ -31,15 +31,16 @@ namespace Apollon.WPF.Commands
public override async Task ExecuteAsync(object parameter)
{
AddEditDetailsViewModel formViewModel = _addTournamentViewModel.AddEditDetailsViewModel;
AddEditDetailsViewModel detailsViewModel = _addTournamentViewModel.AddEditDetailsViewModel;
Tournament tournament = new Tournament(
formViewModel.Organisation,
formViewModel.TournamentName,
formViewModel.Competition,
formViewModel.StartDate,
formViewModel.EndDate,
formViewModel.Location,
formViewModel.Rounds);
Guid.NewGuid(),
detailsViewModel.Organisation,
detailsViewModel.TournamentName,
detailsViewModel.Competition,
detailsViewModel.StartDate,
detailsViewModel.EndDate,
detailsViewModel.Location,
detailsViewModel.Rounds);
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.Collections.Generic;
using System.Linq;
@@ -9,18 +11,41 @@ namespace Apollon.WPF.Commands
{
public class EditTournamentCommand : AsyncCommandBase
{
private readonly EditTournamentViewModel _editTournamentViewModel;
private readonly TournamentsStore _tournamentStore;
private readonly ModalNavigationStore _modalNavigationStore;
public EditTournamentCommand(ModalNavigationStore modalNavigationStore)
public EditTournamentCommand(EditTournamentViewModel editTournamentViewModel, TournamentsStore tournamentStore, ModalNavigationStore modalNavigationStore)
{
_editTournamentViewModel = editTournamentViewModel;
_tournamentStore = tournamentStore;
_modalNavigationStore = modalNavigationStore;
}
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
{
private readonly TournamentStore _tournamentStore;
private readonly TournamentsStore _tournamentStore;
private readonly ModalNavigationStore _modalNavigationStore;
public OpenAddTournamentCommand(TournamentStore tournamentStore, ModalNavigationStore modalNavigationStore)
public OpenAddTournamentCommand(TournamentsStore tournamentStore, ModalNavigationStore modalNavigationStore)
{
_tournamentStore = tournamentStore;
_modalNavigationStore = modalNavigationStore;

View File

@@ -11,18 +11,22 @@ namespace Apollon.WPF.Commands
{
public class OpenEditTournamentCommand : CommandBase
{
private readonly ModalNavigationStore _modalNavigationStore;
private readonly ModalNavigationStore _modalNavigationStore;
private readonly OverviewListingItemViewModel _overviewListingItemViewModel;
private readonly TournamentsStore _tournamentStore;
public OpenEditTournamentCommand(ModalNavigationStore modalNavigationStore)
public OpenEditTournamentCommand(OverviewListingItemViewModel overviewListingItemViewModel, TournamentsStore tournamentStore, ModalNavigationStore modalNavigationStore)
{
_overviewListingItemViewModel = overviewListingItemViewModel;
_tournamentStore = tournamentStore;
_modalNavigationStore = modalNavigationStore;
}
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;
}
}

View File

@@ -7,9 +7,19 @@ using System.Threading.Tasks;
namespace Apollon.WPF.Models
{
public class Tournament
{
public Tournament(string organisation, string tournamentName, string competition, DateTime startDate, DateTime endDate, string location, int rounds = 0)
{
public Guid Id { get; }
public string Organisation { get; }
public string TournamentName { get; }
public string Competition { get; }
public DateTime StartDate { get; }
public DateTime EndDate { get; }
public string Location { 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;
@@ -18,14 +28,5 @@ namespace Apollon.WPF.Models
Location = location;
Rounds = rounds;
}
public string Organisation { get; }
public string TournamentName { get; }
public string Competition { get; }
public DateTime StartDate { get; }
public DateTime EndDate { get; }
public string Location { get; }
public int Rounds { get; }
}
}

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
{
public class TournamentStore
public class TournamentsStore
{
public event Action<Tournament> TournamentAdded;
public event Action<Tournament> TournamentUpdated;
public async Task Add(Tournament 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 AddTournamentViewModel(TournamentStore tournamentStore, ModalNavigationStore modalNavigationStore)
public AddTournamentViewModel(TournamentsStore tournamentStore, ModalNavigationStore modalNavigationStore)
{
ICommand submitCommand = new AddTournamentCommand(this, tournamentStore,modalNavigationStore);
ICommand cancelCommand = new CloseModalCommand(modalNavigationStore);

View File

@@ -12,13 +12,26 @@ namespace Apollon.WPF.ViewModels
{
public class EditTournamentViewModel : ViewModelBase
{
public Guid TournamentId { 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);
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
{
private readonly SelectedTournamentStore _selectedTournamentStore;
private readonly SelectedTournamentsStore _selectedTournamentStore;
private Tournament SelectedTournament => _selectedTournamentStore.SelectedTournament;
@@ -23,7 +23,7 @@ namespace Apollon.WPF.ViewModels
public string Location => SelectedTournament?.Location ?? "kein Ort";
public int Rounds => SelectedTournament?.Rounds ?? 0;
public OverviewDetailsViewModel(SelectedTournamentStore selectedTournamentStore)
public OverviewDetailsViewModel(SelectedTournamentsStore 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.Collections.Generic;
using System.Linq;
@@ -9,16 +11,28 @@ using System.Windows.Input;
namespace Apollon.WPF.ViewModels
{
public class OverviewListingItemViewModel : ViewModelBase
{
public Tournament Tournament { get;}
{
public Tournament Tournament { get; private set; }
public string TournamentName => Tournament.TournamentName;
public string Location => Tournament.Location;
public ICommand EditCommand { get; }
public ICommand DeleteCommand { get; }
public OverviewListingItemViewModel(Tournament tournament)
public OverviewListingItemViewModel(Tournament tournament, TournamentsStore tournamentStore, ModalNavigationStore modalNavigationStore)
{
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
{
private readonly ObservableCollection<OverviewListingItemViewModel> _overviewListingItemViewModels;
private readonly SelectedTournamentStore _selectedTournamentStore;
private readonly SelectedTournamentsStore _selectedTournamentStore;
private readonly ModalNavigationStore _modalNavigationStore;
private readonly TournamentStore _tournamentStore;
private readonly TournamentsStore _tournamentStore;
public IEnumerable<OverviewListingItemViewModel> OverviewListingItemViewModels => _overviewListingItemViewModels;
@@ -38,19 +38,21 @@ namespace Apollon.WPF.ViewModels
}
}
public OverviewListingViewModel(SelectedTournamentStore selectedTournamentStore, ModalNavigationStore modalNavigationStore, TournamentStore tournamentStore)
public OverviewListingViewModel(SelectedTournamentsStore selectedTournamentStore, ModalNavigationStore modalNavigationStore, TournamentsStore tournamentStore)
{
_tournamentStore = tournamentStore;
_selectedTournamentStore = selectedTournamentStore;
_modalNavigationStore = modalNavigationStore;
_overviewListingItemViewModels = new ObservableCollection<OverviewListingItemViewModel>();
_tournamentStore.TournamentAdded += TournamentStore_TournamentAdded;
}
_tournamentStore.TournamentAdded += TournamentStore_TournamentAdded;
_tournamentStore.TournamentUpdated += TournamentStore_TournamentUpdated;
}
protected override void Dispose()
{
_tournamentStore.TournamentAdded -= TournamentStore_TournamentAdded;
_tournamentStore.TournamentUpdated -= TournamentStore_TournamentUpdated;
base.Dispose();
}
@@ -59,10 +61,21 @@ namespace Apollon.WPF.ViewModels
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)
{
// TO DO EditTournamentCommand
_overviewListingItemViewModels.Add(new OverviewListingItemViewModel(tournament));
OverviewListingItemViewModel itemViewModel = new OverviewListingItemViewModel(tournament, _tournamentStore, _modalNavigationStore);
_overviewListingItemViewModels.Add(itemViewModel);
}
}
}

View File

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

View File

@@ -37,19 +37,35 @@
Margin="0 0 4 0"/>
<TextBlock Text="{Binding Location}"/>
</WrapPanel>
<Button Grid.Column="1"
<WrapPanel 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"
BorderThickness="0"
Cursor="Hand"
ToolTip="Löschen"
Command="{Binding DeleteCommand}">
<iconPacks:PackIconMaterial Kind="TrashCan"
<iconPacks:PackIconMaterial Kind="TrashCan"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Grid.Column="1"
Foreground="Red"/>
</Button>
</Button>
</WrapPanel>
</Grid>
</DataTemplate>

View File

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