WhoIsResponsibleForService works

This commit is contained in:
2024-05-05 16:58:26 +02:00
parent a1727ec5c9
commit 9cf8ce697e
2 changed files with 19 additions and 4 deletions

View File

@@ -285,7 +285,7 @@ namespace WD7UVN_SzTGUI_2023242.Client.WPF
bool hasSignalR; bool hasSignalR;
Type type = typeof(T); 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; hasSignalR = hub != null;
this.rest = new RestService(baseurl, endpoint); this.rest = new RestService(baseurl, endpoint);
@@ -325,7 +325,14 @@ namespace WD7UVN_SzTGUI_2023242.Client.WPF
} }
else 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)); CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
} }
private async Task InitCustomEndpointSingle(string endpoint)
{
items = new List<T>();
T res = await rest.GetSingleAsync<T>(endpoint);
items.Add(res);
CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
}
private async Task Init() private async Task Init()
{ {
items = await rest.GetAsync<T>("api/" + typeof(T).Name); items = await rest.GetAsync<T>("api/" + typeof(T).Name);

View File

@@ -2,12 +2,12 @@
using System.ComponentModel; using System.ComponentModel;
using System.Windows; using System.Windows;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using System.Collections.Generic;
namespace WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels namespace WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels
{ {
public class GetResponsibleEmployeeViewModel : ObservableRecipient public class GetResponsibleEmployeeViewModel : ObservableRecipient
{ {
//Hiába egyetlen eredmény van, meghagyom RestCollection-nek a SignalR miatt
public RestCollection<Employee> Employees { get; set; } public RestCollection<Employee> Employees { get; set; }
public static bool IsInDesignMode public static bool IsInDesignMode
@@ -23,7 +23,7 @@ namespace WD7UVN_SzTGUI_2023242.Client.WPF.ViewModels
{ {
if (!IsInDesignMode) if (!IsInDesignMode)
{ {
Employees = new RestCollection<Employee>("http://localhost:5000/", "api/WhoIsResponsibleForService?id=" + s.ID.ToString(), "hub", true); Employees = new RestCollection<Employee>("http://localhost:5000/", "api/WhoIsResponsibleForService?id=" + s.ID.ToString(), "hub", true, true);
} }
} }
} }