Edit Function are available
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
try
|
||||
{
|
||||
await _tournamentStore.Update(tournament);
|
||||
|
||||
_modalNavigationStore.Close();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -12,17 +12,21 @@ namespace Apollon.WPF.Commands
|
||||
public class OpenEditTournamentCommand : CommandBase
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,17 +8,7 @@ namespace Apollon.WPF.Models
|
||||
{
|
||||
public class Tournament
|
||||
{
|
||||
public Tournament(string organisation, string tournamentName, string competition, DateTime startDate, DateTime endDate, string location, int rounds = 0)
|
||||
{
|
||||
Organisation = organisation;
|
||||
TournamentName = tournamentName;
|
||||
Competition = competition;
|
||||
StartDate = startDate;
|
||||
EndDate = endDate;
|
||||
Location = location;
|
||||
Rounds = rounds;
|
||||
}
|
||||
|
||||
public Guid Id { get; }
|
||||
public string Organisation { get; }
|
||||
public string TournamentName { get; }
|
||||
public string Competition { get; }
|
||||
@@ -27,5 +17,16 @@ namespace Apollon.WPF.Models
|
||||
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;
|
||||
StartDate = startDate;
|
||||
EndDate = endDate;
|
||||
Location = location;
|
||||
Rounds = rounds;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
46
Apollon.WPF/Stores/SelectedTournamentsStore.cs
Normal file
46
Apollon.WPF/Stores/SelectedTournamentsStore.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -10,15 +12,27 @@ 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,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;
|
||||
_selectedTournamentStore = selectedTournamentStore;
|
||||
@@ -46,11 +46,13 @@ namespace Apollon.WPF.ViewModels
|
||||
_overviewListingItemViewModels = new ObservableCollection<OverviewListingItemViewModel>();
|
||||
|
||||
_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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,19 +16,13 @@ namespace Apollon.WPF.ViewModels
|
||||
public OverviewDetailsViewModel OverviewDetailsViewModel{ get; }
|
||||
|
||||
public ICommand AddTournamentCommand { get; }
|
||||
public ICommand EditTournamentCommand { 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);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,20 @@
|
||||
Margin="0 0 4 0"/>
|
||||
<TextBlock Text="{Binding Location}"/>
|
||||
</WrapPanel>
|
||||
|
||||
<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"
|
||||
@@ -50,6 +63,9 @@
|
||||
Grid.Column="1"
|
||||
Foreground="Red"/>
|
||||
</Button>
|
||||
</WrapPanel>
|
||||
|
||||
|
||||
</Grid>
|
||||
|
||||
</DataTemplate>
|
||||
|
||||
@@ -113,8 +113,7 @@
|
||||
Height="40"
|
||||
Width="210"
|
||||
Margin="40"
|
||||
Cursor="Hand"
|
||||
Command="{Binding EditTournamentCommand}"/>
|
||||
Cursor="Hand"/>
|
||||
</StackPanel>
|
||||
|
||||
</Grid>
|
||||
|
||||
Reference in New Issue
Block a user