From 9cf8ce697ee77b1c92f1705cd49f15e226259509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miskolczi=20Rich=C3=A1rd?= Date: Sun, 5 May 2024 16:58:26 +0200 Subject: [PATCH] WhoIsResponsibleForService works --- .../RestCollection.cs | 19 +++++++++++++++++-- .../GetResponsibleEmployeeViewModel.cs | 4 ++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/WD7UVN_SzTGUI_2023242.Client.WPF/RestCollection.cs b/WD7UVN_SzTGUI_2023242.Client.WPF/RestCollection.cs index 3d8c21f..3765e1e 100644 --- a/WD7UVN_SzTGUI_2023242.Client.WPF/RestCollection.cs +++ b/WD7UVN_SzTGUI_2023242.Client.WPF/RestCollection.cs @@ -285,7 +285,7 @@ namespace WD7UVN_SzTGUI_2023242.Client.WPF bool hasSignalR; Type type = typeof(T); - public RestCollection(string baseurl, string endpoint, string hub = null, bool nonCrud = false) + public RestCollection(string baseurl, string endpoint, string hub = null, bool nonCrud = false, bool expectSingle = false) { hasSignalR = hub != null; this.rest = new RestService(baseurl, endpoint); @@ -325,7 +325,14 @@ namespace WD7UVN_SzTGUI_2023242.Client.WPF } else { - InitCustomEndpoint(endpoint); + if (expectSingle) + { + InitCustomEndpointSingle(endpoint); + } + else + { + InitCustomEndpoint(endpoint); + } } } @@ -335,6 +342,14 @@ namespace WD7UVN_SzTGUI_2023242.Client.WPF CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); } + private async Task InitCustomEndpointSingle(string endpoint) + { + items = new List(); + T res = await rest.GetSingleAsync(endpoint); + items.Add(res); + CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); + } + private async Task Init() { items = await rest.GetAsync("api/" + typeof(T).Name); diff --git a/WD7UVN_SzTGUI_2023242.Client.WPF/ViewModels/GetResponsibleEmployeeViewModel.cs b/WD7UVN_SzTGUI_2023242.Client.WPF/ViewModels/GetResponsibleEmployeeViewModel.cs index edf1bc1..489727a 100644 --- a/WD7UVN_SzTGUI_2023242.Client.WPF/ViewModels/GetResponsibleEmployeeViewModel.cs +++ b/WD7UVN_SzTGUI_2023242.Client.WPF/ViewModels/GetResponsibleEmployeeViewModel.cs @@ -2,12 +2,12 @@ using System.ComponentModel; using System.Windows; using CommunityToolkit.Mvvm.ComponentModel; +using System.Collections.Generic; namespace WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels { public class GetResponsibleEmployeeViewModel : ObservableRecipient { - //Hiába egyetlen eredmény van, meghagyom RestCollection-nek a SignalR miatt public RestCollection Employees { get; set; } public static bool IsInDesignMode @@ -23,7 +23,7 @@ namespace WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels { if (!IsInDesignMode) { - Employees = new RestCollection("http://localhost:5000/", "api/WhoIsResponsibleForService?id=" + s.ID.ToString(), "hub", true); + Employees = new RestCollection("http://localhost:5000/", "api/WhoIsResponsibleForService?id=" + s.ID.ToString(), "hub", true, true); } } }