using System; using System.Collections.Generic; using System.Collections.ObjectModel; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using Microsoft.Extensions.DependencyInjection; using Policlinica.DB; namespace Policlinica.ViewModels; public partial class DoctorViewModel : ViewModelBase { private readonly IServiceProvider _provider; private readonly Navigation _navigation; [ObservableProperty] string _surname; [ObservableProperty] string _name; [ObservableProperty] ObservableCollection _doctorList; [ObservableProperty] Doctor _selectedDoctor; public DoctorViewModel(IServiceProvider provider, DoctorRepository repository, Navigation navigation) { _provider = provider; _doctorList = new ObservableCollection(repository.GetDoctorsByTest()); _navigation = navigation; } [RelayCommand] public void StartTest() { if (Name == null || Name.Trim() == "") return; if (Surname == null || Surname.Trim() == "") return; if (SelectedDoctor == null) return; var repository = _provider.GetRequiredService(); var vm = ActivatorUtilities.CreateInstance(_provider, SelectedDoctor, repository, Name, Surname); _navigation.Navigate(vm); } [RelayCommand] public void GoBack() { var vm = ActivatorUtilities.CreateInstance(_provider); _navigation.Navigate(vm); } }