From 320391bd06f5e4c035072d3c4a3f008486fd62d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miskolczi=20Rich=C3=A1rd?= Date: Tue, 30 Apr 2024 15:26:02 +0200 Subject: [PATCH] stuff --- .../ViewModels/GetAllEmployeesViewModel.cs | 13 ++- .../ViewModels/GetSubordinatesViewModel.cs | 67 +++++++++++++++ .../Windows/NonCRUD/GetSubordinates.xaml | 81 +++++++++++++++++++ .../Windows/NonCRUD/GetSubordinates.xaml.cs | 26 ++++++ 4 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 WD7UVN_SzTGUI_2023242.Client.WPF/ViewModels/GetSubordinatesViewModel.cs create mode 100644 WD7UVN_SzTGUI_2023242.Client.WPF/Windows/NonCRUD/GetSubordinates.xaml create mode 100644 WD7UVN_SzTGUI_2023242.Client.WPF/Windows/NonCRUD/GetSubordinates.xaml.cs diff --git a/WD7UVN_SzTGUI_2023242.Client.WPF/ViewModels/GetAllEmployeesViewModel.cs b/WD7UVN_SzTGUI_2023242.Client.WPF/ViewModels/GetAllEmployeesViewModel.cs index 12b7bc8..2060e7f 100644 --- a/WD7UVN_SzTGUI_2023242.Client.WPF/ViewModels/GetAllEmployeesViewModel.cs +++ b/WD7UVN_SzTGUI_2023242.Client.WPF/ViewModels/GetAllEmployeesViewModel.cs @@ -4,6 +4,7 @@ using System.Windows; using CommunityToolkit.Mvvm.ComponentModel; using System.Windows.Input; using CommunityToolkit.Mvvm.Input; +using WD7UVN_SzTGUI_2023242.Client.WPF.Windows; namespace WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels { @@ -42,7 +43,7 @@ namespace WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels { if (!IsInDesignMode) { - Employees = new RestCollection("http://localhost:5000/", "api/GetSubordinates", "hub"); + Employees = new RestCollection("http://localhost:5000/", "api/Employee", "hub"); UpdateEmployeeCommand = new RelayCommand(() => { @@ -61,6 +62,16 @@ namespace WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels { return SelectedEmployee != null; }); + + GetSubordinatesCommand = new RelayCommand(() => + { + Window window = new GetSubordinates(SelectedEmployee); + window.Show(); + }, + () => + { + return SelectedEmployee != null; + }); } } } diff --git a/WD7UVN_SzTGUI_2023242.Client.WPF/ViewModels/GetSubordinatesViewModel.cs b/WD7UVN_SzTGUI_2023242.Client.WPF/ViewModels/GetSubordinatesViewModel.cs new file mode 100644 index 0000000..3b0aca9 --- /dev/null +++ b/WD7UVN_SzTGUI_2023242.Client.WPF/ViewModels/GetSubordinatesViewModel.cs @@ -0,0 +1,67 @@ +using WD7UVN_HFT_2023241.Models; +using System.ComponentModel; +using System.Windows; +using CommunityToolkit.Mvvm.ComponentModel; +using System.Windows.Input; +using CommunityToolkit.Mvvm.Input; + +namespace WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels +{ + public class GetSubordinatesViewModel : ObservableRecipient + { + public RestCollection Employees { get; set; } + + private Employee selectedEmployee; + + public Employee SelectedEmployee + { + get { return selectedEmployee; } + set + { + SetProperty(ref selectedEmployee, value); + (UpdateEmployeeCommand as RelayCommand).NotifyCanExecuteChanged(); + (DeleteEmployeeCommand as RelayCommand).NotifyCanExecuteChanged(); + (GetSubordinatesCommand as RelayCommand).NotifyCanExecuteChanged(); + } + } + + public ICommand UpdateEmployeeCommand { get; set; } + public ICommand DeleteEmployeeCommand { get; set; } + public ICommand GetSubordinatesCommand { get; set; } + + public static bool IsInDesignMode + { + get + { + var prop = DesignerProperties.IsInDesignModeProperty; + return (bool)DependencyPropertyDescriptor.FromProperty(prop, typeof(FrameworkElement)).Metadata.DefaultValue; + } + } + + public GetSubordinatesViewModel(Employee e) + { + if (!IsInDesignMode) + { + Employees = new RestCollection("http://localhost:5000/", "api/GetSubordinates/" + e.ID.ToString(), "hub"); + + UpdateEmployeeCommand = new RelayCommand(() => + { + Employees.Update(SelectedEmployee); + }, + () => + { + return SelectedEmployee != null; + }); + + DeleteEmployeeCommand = new RelayCommand(() => + { + Employees.Delete(SelectedEmployee.ID); + }, + () => + { + return SelectedEmployee != null; + }); + } + } + } +} diff --git a/WD7UVN_SzTGUI_2023242.Client.WPF/Windows/NonCRUD/GetSubordinates.xaml b/WD7UVN_SzTGUI_2023242.Client.WPF/Windows/NonCRUD/GetSubordinates.xaml new file mode 100644 index 0000000..2b900af --- /dev/null +++ b/WD7UVN_SzTGUI_2023242.Client.WPF/Windows/NonCRUD/GetSubordinates.xaml @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +