using DaSaSo.Domain.Model; using DaSaSo.Domain.Services; using DaSaSo.ViewModel.Commands; using DaSaSo.ViewModel.Enums; using DaSaSo.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.ViewModel { public class ClientListViewModel : BaseViewModel { public ObservableCollection Clients { get; } private Client? _selectedClient; private IDataService _dataService; private readonly IRenavigator renavigator; IEnumerable? result; bool _isLoading = true; public ICommand SelectCommand { get; set; } 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 dataService, IActualProject actualProject, IRenavigator renavigator) { Clients = new ObservableCollection(); _dataService = dataService; this.renavigator = renavigator; LoadClient(); SelectCommand = new SelectClientCommand(actualProject, this); //= new RelayCommand(SelectClient, () => SelectedClient != null); EditCommand = new EditClientCommand(_dataService,actualProject,renavigator,this); AddNewClientCommand = new AddClientCommand(_dataService, actualProject, renavigator, this); } public async void LoadClient() { IsLoading = true; var clients = await _dataService.GetAll(); // InitCollection(Clients, clients); IsLoading = false; } private void InitCollection(ObservableCollection target, IEnumerable source) { target.Clear(); foreach (var i in source) target.Add(i); } } }