viewmodel ins wpf gepackt, build failed
This commit is contained in:
89
DaSaSo.Wpf/ViewModel/ClientListViewModel.cs
Normal file
89
DaSaSo.Wpf/ViewModel/ClientListViewModel.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using DaSaSo.Domain.Model;
|
||||
using DaSaSo.Domain.Services;
|
||||
using DaSaSo.Wpf.ViewModel.Commands;
|
||||
using DaSaSo.Wpf.ViewModel.Enums;
|
||||
using DaSaSo.Wpf.ViewModel.Interface;
|
||||
using Microsoft.Toolkit.Mvvm.Input;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace DaSaSo.Wpf.ViewModel
|
||||
{
|
||||
public class ClientListViewModel : BaseViewModel
|
||||
{
|
||||
public ObservableCollection<Client> Clients { get; }
|
||||
private Client? _selectedClient;
|
||||
private readonly IDataService<Client> _dataService;
|
||||
bool _isLoading = true;
|
||||
|
||||
public ICommand EditCommand { get; set; }
|
||||
public ICommand AddNewClientCommand { get; set; }
|
||||
|
||||
public Client SelectedClient
|
||||
{
|
||||
get => _selectedClient;
|
||||
set
|
||||
{
|
||||
if(_selectedClient != value)
|
||||
{
|
||||
_selectedClient = value;
|
||||
|
||||
OnPropertyChanged();
|
||||
OnPropertyChanged(nameof(CanSelectClient));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsLoading
|
||||
{
|
||||
get => _isLoading;
|
||||
set
|
||||
{
|
||||
if(_isLoading != value)
|
||||
{
|
||||
_isLoading = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanSelectClient => _selectedClient != null;
|
||||
|
||||
public ClientListViewModel(IDataService<Client> dataService, IActualProject actualProject, IRenavigator editRenavigator)
|
||||
{
|
||||
Clients = new ObservableCollection<Client>();
|
||||
_dataService = dataService;
|
||||
|
||||
LoadClient();
|
||||
|
||||
EditCommand = new EditClientCommand(_dataService,actualProject, editRenavigator, this);
|
||||
AddNewClientCommand = new AddClientCommand(_dataService, actualProject, editRenavigator, this);
|
||||
|
||||
}
|
||||
|
||||
public async void LoadClient()
|
||||
{
|
||||
IsLoading = true;
|
||||
var clients = await _dataService.GetAll();
|
||||
//
|
||||
InitCollection(Clients, clients);
|
||||
|
||||
IsLoading = false;
|
||||
}
|
||||
|
||||
private static void InitCollection(ObservableCollection<Client> target, IEnumerable<Client> source)
|
||||
{
|
||||
target.Clear();
|
||||
foreach (var i in source)
|
||||
target.Add(i);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user