Commands auf Async umgestellt
This commit is contained in:
40
DaSaSo.ViewModel/Commands/AsyncCommandBase.cs
Normal file
40
DaSaSo.ViewModel/Commands/AsyncCommandBase.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace DaSaSo.ViewModel.Commands
|
||||
{
|
||||
public abstract class AsyncCommandBase : ICommand
|
||||
{
|
||||
bool _isExecuting = false;
|
||||
public event EventHandler? CanExecuteChanged;
|
||||
|
||||
public bool IsExecuting
|
||||
{
|
||||
get => _isExecuting;
|
||||
set
|
||||
{
|
||||
_isExecuting = value;
|
||||
CanExecuteChanged?.Invoke(this, new EventArgs());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool CanExecute(object? parameter)
|
||||
{
|
||||
return !IsExecuting;
|
||||
}
|
||||
|
||||
public async void Execute(object? parameter)
|
||||
{
|
||||
IsExecuting = true;
|
||||
await ExecuteAsync(parameter);
|
||||
IsExecuting = false;
|
||||
}
|
||||
|
||||
public abstract Task ExecuteAsync(object? parameter);
|
||||
}
|
||||
}
|
||||
@@ -11,16 +11,14 @@ using System.Windows.Input;
|
||||
|
||||
namespace DaSaSo.ViewModel.Commands
|
||||
{
|
||||
public class EditClientCommand : ICommand
|
||||
public class EditClientCommand : AsyncCommandBase
|
||||
{
|
||||
private readonly IDataService<Client> dataservice;
|
||||
private readonly IActualProject actualProject;
|
||||
private readonly IRenavigator renavigator;
|
||||
private readonly ClientListViewModel clientListViewModel;
|
||||
|
||||
public event EventHandler? CanExecuteChanged;
|
||||
|
||||
|
||||
|
||||
|
||||
public EditClientCommand(IDataService<Client> dataservice, IActualProject actualProject,IRenavigator renavigator, ClientListViewModel clientListViewModel)
|
||||
{
|
||||
@@ -30,12 +28,8 @@ namespace DaSaSo.ViewModel.Commands
|
||||
this.clientListViewModel = clientListViewModel;
|
||||
}
|
||||
|
||||
public bool CanExecute(object? parameter)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Execute(object? parameter)
|
||||
|
||||
public override async Task ExecuteAsync(object? parameter)
|
||||
{
|
||||
actualProject.SetClient(clientListViewModel.SelectedClient);
|
||||
renavigator.Renavigate(new ClientEditViewModel(dataservice,actualProject,renavigator));
|
||||
|
||||
@@ -8,9 +8,9 @@ using System.Windows.Input;
|
||||
|
||||
namespace DaSaSo.ViewModel.Commands
|
||||
{
|
||||
public class SelectClientCommand : ICommand
|
||||
public class SelectClientCommand : AsyncCommandBase
|
||||
{
|
||||
public event EventHandler? CanExecuteChanged;
|
||||
|
||||
private readonly IActualProject _actualProject;
|
||||
private readonly ClientListViewModel _clientListViewModel;
|
||||
public SelectClientCommand(IActualProject actualProject, ClientListViewModel clientListViewModel)
|
||||
@@ -19,15 +19,11 @@ namespace DaSaSo.ViewModel.Commands
|
||||
_clientListViewModel = clientListViewModel;
|
||||
}
|
||||
|
||||
public bool CanExecute(object? parameter)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Execute(object? parameter)
|
||||
public override async Task ExecuteAsync(object? parameter)
|
||||
{
|
||||
var s = _clientListViewModel.SelectedClient;
|
||||
_actualProject.SetClient(s);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,8 @@ using System.Windows.Input;
|
||||
|
||||
namespace DaSaSo.ViewModel.Commands
|
||||
{
|
||||
class UpdateCurrentViewModelCommand : ICommand
|
||||
class UpdateCurrentViewModelCommand : AsyncCommandBase
|
||||
{
|
||||
public event EventHandler? CanExecuteChanged;
|
||||
private INavigator _navigator;
|
||||
private readonly IViewModelAbstractFactory _viewModelFactory;
|
||||
|
||||
@@ -16,12 +15,9 @@ namespace DaSaSo.ViewModel.Commands
|
||||
_viewModelFactory = viewModelFactory;
|
||||
}
|
||||
|
||||
public bool CanExecute(object? parameter)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void Execute(object? parameter)
|
||||
public override async Task ExecuteAsync(object? parameter)
|
||||
{
|
||||
if(parameter is EViewType)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user