diff --git a/WD7UVN_HFT_2023241.Client/Shared/WD7UVN_HFT_2023241.Client.Shared.csproj b/WD7UVN_HFT_2023241.Client/Shared/WD7UVN_HFT_2023241.Client.Shared.csproj
index 26dd80b..0ee4ce4 100644
--- a/WD7UVN_HFT_2023241.Client/Shared/WD7UVN_HFT_2023241.Client.Shared.csproj
+++ b/WD7UVN_HFT_2023241.Client/Shared/WD7UVN_HFT_2023241.Client.Shared.csproj
@@ -1,4 +1,4 @@
-
+
net5.0
diff --git a/WD7UVN_HFT_2023241.Client/TUI/CRUD.cs b/WD7UVN_HFT_2023241.Client/TUI/CRUD.cs
index 176a7d1..fe4071a 100644
--- a/WD7UVN_HFT_2023241.Client/TUI/CRUD.cs
+++ b/WD7UVN_HFT_2023241.Client/TUI/CRUD.cs
@@ -1,10 +1,7 @@
using System;
-using System.Linq;
-using System.Net.NetworkInformation;
using System.Reflection;
using ConsoleTools;
using WD7UVN_HFT_2023241.Models;
-using WD7UVN_HFT_2023241.Client.Shared;
namespace WD7UVN_HFT_2023241.Client.TUI
{
diff --git a/WD7UVN_HFT_2023241.Client/TUI/NonCRUD.cs b/WD7UVN_HFT_2023241.Client/TUI/NonCRUD.cs
index 67879a6..64e956a 100644
--- a/WD7UVN_HFT_2023241.Client/TUI/NonCRUD.cs
+++ b/WD7UVN_HFT_2023241.Client/TUI/NonCRUD.cs
@@ -1,8 +1,5 @@
using System;
-using System.Linq;
-using System.Collections.Generic;
using ConsoleTools;
-using WD7UVN_HFT_2023241.Client.Shared;
using WD7UVN_HFT_2023241.Models;
namespace WD7UVN_HFT_2023241.Client.TUI
diff --git a/WD7UVN_HFT_2023241.Client/TUI/Program.cs b/WD7UVN_HFT_2023241.Client/TUI/Program.cs
index e6061cc..4f9b769 100644
--- a/WD7UVN_HFT_2023241.Client/TUI/Program.cs
+++ b/WD7UVN_HFT_2023241.Client/TUI/Program.cs
@@ -2,7 +2,6 @@
using System.Threading;
using System.Threading.Tasks;
using ConsoleTools;
-using WD7UVN_HFT_2023241.Client.Shared;
namespace WD7UVN_HFT_2023241.Client.TUI
{
diff --git a/WD7UVN_HFT_2023241.Client/TUI/RestService.cs b/WD7UVN_HFT_2023241.Client/TUI/RestService.cs
new file mode 100644
index 0000000..65907bc
--- /dev/null
+++ b/WD7UVN_HFT_2023241.Client/TUI/RestService.cs
@@ -0,0 +1,264 @@
+using System;
+using System.Collections.Generic;
+using System.Net;
+using System.Net.Http;
+using System.Net.Security;
+using WD7UVN_HFT_2023241.Models;
+
+namespace WD7UVN_HFT_2023241.Client.TUI
+{
+ public class RestService
+ {
+ private static HttpClient client;
+
+ private static bool Ping(string url)
+ {
+ try
+ {
+ ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
+
+ WebClient wc = new WebClient();
+ wc.DownloadData(url);
+ return true;
+ }
+ catch
+ {
+ return false;
+ }
+ }
+
+ public static void Init(string baseurl = "https://localhost:5001", string pingableEndpoint = "/swagger")
+ {
+ int tries = 0;
+ bool isOk = false;
+ do
+ {
+ isOk = Ping(baseurl + pingableEndpoint);
+ tries++;
+ } while (isOk == false && tries < 5);
+
+ if (isOk == false)
+ {
+ throw new EndpointNotAvailableException("Endpoint is not available!");
+ }
+
+ HttpClientHandler handler = new HttpClientHandler();
+ handler.ClientCertificateOptions = ClientCertificateOption.Manual;
+ handler.ServerCertificateCustomValidationCallback =
+ (httpRequestMessage, cert, cetChain, policyErrors) =>
+ {
+ return true;
+ };
+
+ client = new HttpClient(handler);
+ client.BaseAddress = new Uri(baseurl);
+ client.DefaultRequestHeaders.Accept.Clear();
+ client.DefaultRequestHeaders.Accept.Add(
+ new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue
+ ("application/json"));
+ try
+ {
+ client.GetAsync("").GetAwaiter().GetResult();
+ }
+ catch (HttpRequestException e)
+ {
+ Console.WriteLine(e.Message);
+ throw new ArgumentException("Endpoint is not available!");
+ }
+
+ }
+
+ public static List Get(string endpoint)
+ {
+ List items = new List();
+ HttpResponseMessage response = client.GetAsync(endpoint).GetAwaiter().GetResult();
+ if (response.IsSuccessStatusCode)
+ {
+ items = response.Content.ReadAsAsync>().GetAwaiter().GetResult();
+ }
+ else
+ {
+ var error = response.Content.ReadAsAsync().GetAwaiter().GetResult();
+ throw new ArgumentException(error.Msg);
+ }
+ return items;
+ }
+
+ public static T GetSingle(string endpoint)
+ {
+ T item = default(T);
+ HttpResponseMessage response = client.GetAsync(endpoint).GetAwaiter().GetResult();
+ if (response.IsSuccessStatusCode)
+ {
+ item = response.Content.ReadAsAsync().GetAwaiter().GetResult();
+ }
+ else
+ {
+ var error = response.Content.ReadAsAsync().GetAwaiter().GetResult();
+ throw new ArgumentException(error.Msg);
+ }
+ return item;
+ }
+
+ public static T Get(int id, string endpoint)
+ {
+ T item = default(T);
+ HttpResponseMessage response = client.GetAsync(endpoint + id.ToString()).GetAwaiter().GetResult();
+ if (response.IsSuccessStatusCode)
+ {
+ item = response.Content.ReadAsAsync().GetAwaiter().GetResult();
+ }
+ else
+ {
+ var error = response.Content.ReadAsAsync().GetAwaiter().GetResult();
+ throw new ArgumentException(error.Msg);
+ }
+ return item;
+ }
+
+ public static void Post(T item, string endpoint)
+ {
+ HttpResponseMessage response =
+ client.PostAsJsonAsync(endpoint, item).GetAwaiter().GetResult();
+
+ if (!response.IsSuccessStatusCode)
+ {
+ var error = response.Content.ReadAsAsync().GetAwaiter().GetResult();
+ throw new ArgumentException(error.Msg);
+ }
+ response.EnsureSuccessStatusCode();
+ }
+
+ public static void Delete(int id, string endpoint)
+ {
+ HttpResponseMessage response =
+ client.DeleteAsync(endpoint + id.ToString()).GetAwaiter().GetResult();
+
+ if (!response.IsSuccessStatusCode)
+ {
+ var error = response.Content.ReadAsAsync().GetAwaiter().GetResult();
+ throw new ArgumentException(error.Msg);
+ }
+
+ response.EnsureSuccessStatusCode();
+ }
+
+ public static void Put(T item, string endpoint)
+ {
+ HttpResponseMessage response =
+ client.PutAsJsonAsync(endpoint, item).GetAwaiter().GetResult();
+
+ if (!response.IsSuccessStatusCode)
+ {
+ var error = response.Content.ReadAsAsync().GetAwaiter().GetResult();
+ throw new ArgumentException(error.Msg);
+ }
+
+ response.EnsureSuccessStatusCode();
+ }
+
+ public static List WhoWorksInMaintainerTeam(int id)
+ {
+ var item = default(List);
+ HttpResponseMessage response = client.GetAsync("/api/WhoWorksInMaintainerTeam?id=" + id.ToString()).GetAwaiter().GetResult();
+ if (response.IsSuccessStatusCode)
+ {
+ item = response.Content.ReadAsAsync>().GetAwaiter().GetResult();
+ }
+ else
+ {
+ var error = response.Content.ReadAsAsync().GetAwaiter().GetResult();
+ throw new ArgumentException(error.Msg);
+ }
+ return item;
+ }
+
+ public static List GetSubordinates(int id)
+ {
+ var item = default(List);
+ HttpResponseMessage response = client.GetAsync("/api/GetSubordinates?id=" + id.ToString()).GetAwaiter().GetResult();
+ if (response.IsSuccessStatusCode)
+ {
+ item = response.Content.ReadAsAsync>().GetAwaiter().GetResult();
+ }
+ else
+ {
+ var error = response.Content.ReadAsAsync().GetAwaiter().GetResult();
+ throw new ArgumentException(error.Msg);
+ }
+ return item;
+ }
+
+ public static List WhoUsesService(int id)
+ {
+ var item = default(List);
+ HttpResponseMessage response = client.GetAsync("/api/WhoUsesService?id=" + id.ToString()).GetAwaiter().GetResult();
+ if (response.IsSuccessStatusCode)
+ {
+ item = response.Content.ReadAsAsync>().GetAwaiter().GetResult();
+ }
+ else
+ {
+ var error = response.Content.ReadAsAsync().GetAwaiter().GetResult();
+ throw new ArgumentException(error.Msg);
+ }
+ return item;
+ }
+
+ public static Employee WhoIsResponsibleForService(int id)
+ {
+ Employee item = default(Employee);
+ HttpResponseMessage response = client.GetAsync("/api/WhoIsResponsibleForService?id=" + id.ToString()).GetAwaiter().GetResult();
+ if (response.IsSuccessStatusCode)
+ {
+ item = response.Content.ReadAsAsync().GetAwaiter().GetResult();
+ }
+ else
+ {
+ var error = response.Content.ReadAsAsync().GetAwaiter().GetResult();
+ throw new ArgumentException(error.Msg);
+ }
+ return item;
+ }
+
+ public static List WhoMaintainsService(int id)
+ {
+ var item = default(List);
+ HttpResponseMessage response = client.GetAsync("/api/WhoMaintainsService?id=" + id.ToString()).GetAwaiter().GetResult();
+ if (response.IsSuccessStatusCode)
+ {
+ item = response.Content.ReadAsAsync>().GetAwaiter().GetResult();
+ }
+ else
+ {
+ var error = response.Content.ReadAsAsync().GetAwaiter().GetResult();
+ throw new ArgumentException(error.Msg);
+ }
+ return item;
+ }
+ }
+
+ public class RestExceptionInfo
+ {
+ public RestExceptionInfo()
+ {
+
+ }
+ public string Msg { get; set; }
+ }
+
+ public class EndpointNotAvailableException : Exception
+ {
+ public EndpointNotAvailableException() : base("The client could not reach the API endpoint.")
+ {
+ }
+
+ public EndpointNotAvailableException(string message) : base(message)
+ {
+ }
+
+ public EndpointNotAvailableException(string message, Exception innerException) : base(message, innerException)
+ {
+ }
+ }
+}
diff --git a/WD7UVN_HFT_2023241.Client/TUI/WD7UVN_HFT_2023241.Client.TUI.csproj b/WD7UVN_HFT_2023241.Client/TUI/WD7UVN_HFT_2023241.Client.TUI.csproj
index 1157649..f0af545 100644
--- a/WD7UVN_HFT_2023241.Client/TUI/WD7UVN_HFT_2023241.Client.TUI.csproj
+++ b/WD7UVN_HFT_2023241.Client/TUI/WD7UVN_HFT_2023241.Client.TUI.csproj
@@ -7,11 +7,11 @@
-
-
+
+
diff --git a/WD7UVN_HFT_2023241.sln b/WD7UVN_HFT_2023241.sln
index 36d6821..29b79c0 100644
--- a/WD7UVN_HFT_2023241.sln
+++ b/WD7UVN_HFT_2023241.sln
@@ -21,9 +21,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{18D51E
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WD7UVN_HFT_2023241.Client.TUI", "WD7UVN_HFT_2023241.Client\TUI\WD7UVN_HFT_2023241.Client.TUI.csproj", "{F68C5B1A-C3B9-4AFC-BBD3-9DCC02A22EA0}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WD7UVN_HFT_2023241.Client.Shared", "WD7UVN_HFT_2023241.Client\Shared\WD7UVN_HFT_2023241.Client.Shared.csproj", "{77C8BEDB-0D81-4703-8FBC-B4DCD32584BD}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WD7UVN_SzTGUI_2023242.Client.WPF", "WD7UVN_SzTGUI_2023242.Client.WPF\WD7UVN_SzTGUI_2023242.Client.WPF.csproj", "{0A994D03-066F-43E7-872E-4D239FC6F764}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WD7UVN_SzTGUI_2023242.Client.WPF", "WD7UVN_SzTGUI_2023242.Client.WPF\WD7UVN_SzTGUI_2023242.Client.WPF.csproj", "{0A994D03-066F-43E7-872E-4D239FC6F764}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -55,10 +53,6 @@ Global
{F68C5B1A-C3B9-4AFC-BBD3-9DCC02A22EA0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F68C5B1A-C3B9-4AFC-BBD3-9DCC02A22EA0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F68C5B1A-C3B9-4AFC-BBD3-9DCC02A22EA0}.Release|Any CPU.Build.0 = Release|Any CPU
- {77C8BEDB-0D81-4703-8FBC-B4DCD32584BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {77C8BEDB-0D81-4703-8FBC-B4DCD32584BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {77C8BEDB-0D81-4703-8FBC-B4DCD32584BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {77C8BEDB-0D81-4703-8FBC-B4DCD32584BD}.Release|Any CPU.Build.0 = Release|Any CPU
{0A994D03-066F-43E7-872E-4D239FC6F764}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0A994D03-066F-43E7-872E-4D239FC6F764}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0A994D03-066F-43E7-872E-4D239FC6F764}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -74,7 +68,6 @@ Global
{316342CA-7521-4A01-8BDB-5AA76D4DE855} = {E7A96BA5-BFD6-4265-A90F-880015BEFE07}
{63F3B585-3E8C-41F5-8D6C-FB59932D0819} = {E7A96BA5-BFD6-4265-A90F-880015BEFE07}
{F68C5B1A-C3B9-4AFC-BBD3-9DCC02A22EA0} = {8FABCF39-D228-4E36-927D-09B4CCF88935}
- {77C8BEDB-0D81-4703-8FBC-B4DCD32584BD} = {8FABCF39-D228-4E36-927D-09B4CCF88935}
{0A994D03-066F-43E7-872E-4D239FC6F764} = {8FABCF39-D228-4E36-927D-09B4CCF88935}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
diff --git a/WD7UVN_SzTGUI_2023242.Client.WPF/MainWindow.xaml b/WD7UVN_SzTGUI_2023242.Client.WPF/MainWindow.xaml
index c7c69d8..b8215ac 100644
--- a/WD7UVN_SzTGUI_2023242.Client.WPF/MainWindow.xaml
+++ b/WD7UVN_SzTGUI_2023242.Client.WPF/MainWindow.xaml
@@ -5,8 +5,79 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WD7UVN_SzTGUI_2023242.Client.WPF"
mc:Ignorable="d"
- Title="MainWindow" Height="450" Width="800">
+ Title="Company database manager" Height="450" Width="900">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/WD7UVN_SzTGUI_2023242.Client.WPF/MainWindow.xaml.cs b/WD7UVN_SzTGUI_2023242.Client.WPF/MainWindow.xaml.cs
index bf595d8..fb67a7e 100644
--- a/WD7UVN_SzTGUI_2023242.Client.WPF/MainWindow.xaml.cs
+++ b/WD7UVN_SzTGUI_2023242.Client.WPF/MainWindow.xaml.cs
@@ -1,17 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
+using System.Windows;
namespace WD7UVN_SzTGUI_2023242.Client.WPF
{
@@ -24,5 +11,25 @@ namespace WD7UVN_SzTGUI_2023242.Client.WPF
{
InitializeComponent();
}
+
+ private void ExpandAllServices(object sender, RoutedEventArgs e)
+ {
+
+ }
+
+ private void ExpandAllCustomers(object sender, RoutedEventArgs e)
+ {
+
+ }
+
+ private void ExpandAllClients(object sender, RoutedEventArgs e)
+ {
+
+ }
+
+ private void ExpandAllTeams(object sender, RoutedEventArgs e)
+ {
+
+ }
}
}
diff --git a/WD7UVN_SzTGUI_2023242.Client.WPF/RestCollection.cs b/WD7UVN_SzTGUI_2023242.Client.WPF/RestCollection.cs
new file mode 100644
index 0000000..14095da
--- /dev/null
+++ b/WD7UVN_SzTGUI_2023242.Client.WPF/RestCollection.cs
@@ -0,0 +1,423 @@
+using Microsoft.AspNetCore.SignalR.Client;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Collections.Specialized;
+using System.Linq;
+using System.Net;
+using System.Net.Http;
+using System.Threading.Tasks;
+using System.Windows;
+
+namespace WD7UVN_SzTGUI_2023242.Client.WPF
+{
+ public class RestService
+ {
+ HttpClient client;
+
+ public RestService(string baseurl, string pingableEndpoint = "swagger")
+ {
+ bool isOk = false;
+ do
+ {
+ isOk = Ping(baseurl + pingableEndpoint);
+ } while (isOk == false);
+ Init(baseurl);
+ }
+
+ private bool Ping(string url)
+ {
+ try
+ {
+ WebClient wc = new WebClient();
+ wc.DownloadData(url);
+ return true;
+ }
+ catch
+ {
+ return false;
+ }
+ }
+
+ private void Init(string baseurl)
+ {
+ client = new HttpClient();
+ client.BaseAddress = new Uri(baseurl);
+ client.DefaultRequestHeaders.Accept.Clear();
+ client.DefaultRequestHeaders.Accept.Add(
+ new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue
+ ("application/json"));
+ try
+ {
+ client.GetAsync("").GetAwaiter().GetResult();
+ }
+ catch (HttpRequestException)
+ {
+ throw new ArgumentException("Endpoint is not available!");
+ }
+
+ }
+
+ public async Task> GetAsync(string endpoint)
+ {
+ List items = new List();
+ HttpResponseMessage response = await client.GetAsync(endpoint);
+ if (response.IsSuccessStatusCode)
+ {
+ items = await response.Content.ReadAsAsync>();
+ }
+ else
+ {
+ var error = await response.Content.ReadAsAsync();
+ throw new ArgumentException(error.Msg);
+ }
+ return items;
+ }
+
+ public List Get(string endpoint)
+ {
+ List items = new List();
+ HttpResponseMessage response = client.GetAsync(endpoint).GetAwaiter().GetResult();
+ if (response.IsSuccessStatusCode)
+ {
+ items = response.Content.ReadAsAsync>().GetAwaiter().GetResult();
+ }
+ else
+ {
+ var error = response.Content.ReadAsAsync().GetAwaiter().GetResult();
+ throw new ArgumentException(error.Msg);
+ }
+ return items;
+ }
+
+ public async Task GetSingleAsync(string endpoint)
+ {
+ T item = default(T);
+ HttpResponseMessage response = await client.GetAsync(endpoint);
+ if (response.IsSuccessStatusCode)
+ {
+ item = await response.Content.ReadAsAsync();
+ }
+ else
+ {
+ var error = await response.Content.ReadAsAsync();
+ throw new ArgumentException(error.Msg);
+ }
+ return item;
+ }
+
+ public T GetSingle(string endpoint)
+ {
+ T item = default(T);
+ HttpResponseMessage response = client.GetAsync(endpoint).GetAwaiter().GetResult();
+ if (response.IsSuccessStatusCode)
+ {
+ item = response.Content.ReadAsAsync().GetAwaiter().GetResult();
+ }
+ else
+ {
+ var error = response.Content.ReadAsAsync().GetAwaiter().GetResult();
+ throw new ArgumentException(error.Msg);
+ }
+ return item;
+ }
+
+ public async Task GetAsync(int id, string endpoint)
+ {
+ T item = default(T);
+ HttpResponseMessage response = await client.GetAsync(endpoint + "/" + id.ToString());
+ if (response.IsSuccessStatusCode)
+ {
+ item = await response.Content.ReadAsAsync();
+ }
+ else
+ {
+ var error = await response.Content.ReadAsAsync();
+ throw new ArgumentException(error.Msg);
+ }
+ return item;
+ }
+
+ public T Get(int id, string endpoint)
+ {
+ T item = default(T);
+ HttpResponseMessage response = client.GetAsync(endpoint + "/" + id.ToString()).GetAwaiter().GetResult();
+ if (response.IsSuccessStatusCode)
+ {
+ item = response.Content.ReadAsAsync().GetAwaiter().GetResult();
+ }
+ else
+ {
+ var error = response.Content.ReadAsAsync().GetAwaiter().GetResult();
+ throw new ArgumentException(error.Msg);
+ }
+ return item;
+ }
+
+ public async Task PostAsync(T item, string endpoint)
+ {
+ HttpResponseMessage response =
+ await client.PostAsJsonAsync(endpoint, item);
+
+ if (!response.IsSuccessStatusCode)
+ {
+ var error = await response.Content.ReadAsAsync();
+ throw new ArgumentException(error.Msg);
+ }
+ response.EnsureSuccessStatusCode();
+ }
+
+ public void Post(T item, string endpoint)
+ {
+ HttpResponseMessage response =
+ client.PostAsJsonAsync(endpoint, item).GetAwaiter().GetResult();
+
+ if (!response.IsSuccessStatusCode)
+ {
+ var error = response.Content.ReadAsAsync().GetAwaiter().GetResult();
+ throw new ArgumentException(error.Msg);
+ }
+ response.EnsureSuccessStatusCode();
+ }
+
+ public async Task DeleteAsync(int id, string endpoint)
+ {
+ HttpResponseMessage response =
+ await client.DeleteAsync(endpoint + "/" + id.ToString());
+
+ if (!response.IsSuccessStatusCode)
+ {
+ var error = await response.Content.ReadAsAsync();
+ throw new ArgumentException(error.Msg);
+ }
+
+ response.EnsureSuccessStatusCode();
+ }
+
+ public void Delete(int id, string endpoint)
+ {
+ HttpResponseMessage response =
+ client.DeleteAsync(endpoint + "/" + id.ToString()).GetAwaiter().GetResult();
+
+ if (!response.IsSuccessStatusCode)
+ {
+ var error = response.Content.ReadAsAsync().GetAwaiter().GetResult();
+ throw new ArgumentException(error.Msg);
+ }
+
+ response.EnsureSuccessStatusCode();
+ }
+
+ public async Task PutAsync(T item, string endpoint)
+ {
+ HttpResponseMessage response =
+ await client.PutAsJsonAsync(endpoint, item);
+
+ if (!response.IsSuccessStatusCode)
+ {
+ var error = await response.Content.ReadAsAsync();
+ throw new ArgumentException(error.Msg);
+ }
+
+ response.EnsureSuccessStatusCode();
+ }
+
+ public void Put(T item, string endpoint)
+ {
+ HttpResponseMessage response =
+ client.PutAsJsonAsync(endpoint, item).GetAwaiter().GetResult();
+
+ if (!response.IsSuccessStatusCode)
+ {
+ var error = response.Content.ReadAsAsync().GetAwaiter().GetResult();
+ throw new ArgumentException(error.Msg);
+ }
+
+ response.EnsureSuccessStatusCode();
+ }
+
+ }
+ public class RestExceptionInfo
+ {
+ public RestExceptionInfo()
+ {
+
+ }
+ public string Msg { get; set; }
+ }
+ class NotifyService
+ {
+ private HubConnection conn;
+
+ public NotifyService(string url)
+ {
+ conn = new HubConnectionBuilder()
+ .WithUrl(url)
+ .Build();
+
+ conn.Closed += async (error) =>
+ {
+ await Task.Delay(new Random().Next(0, 5) * 1000);
+ await conn.StartAsync();
+ };
+ }
+
+ public void AddHandler(string methodname, Action value)
+ {
+ conn.On(methodname, value);
+ }
+
+ public async void Init()
+ {
+ await conn.StartAsync();
+ }
+
+ }
+
+ public class RestCollection : INotifyCollectionChanged, IEnumerable
+ {
+ public event NotifyCollectionChangedEventHandler? CollectionChanged;
+
+ NotifyService notify;
+ RestService rest;
+ List items;
+ bool hasSignalR;
+ Type type = typeof(T);
+
+ public RestCollection(string baseurl, string endpoint, string hub = null)
+ {
+ hasSignalR = hub != null;
+ this.rest = new RestService(baseurl, endpoint);
+ if (hub != null)
+ {
+ this.notify = new NotifyService(baseurl + hub);
+ this.notify.AddHandler(type.Name + "Created", (T item) =>
+ {
+ items.Add(item);
+ CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
+ });
+ this.notify.AddHandler(type.Name + "Deleted", (T item) =>
+ {
+ var element = items.FirstOrDefault(t => t.Equals(item));
+ if (element != null)
+ {
+ items.Remove(item);
+ CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
+ }
+ else
+ {
+ Init();
+ }
+
+ });
+ this.notify.AddHandler(type.Name + "Updated", (T item) =>
+ {
+ Init();
+ });
+
+ this.notify.Init();
+ }
+ Init();
+ }
+
+ private async Task Init()
+ {
+ items = await rest.GetAsync(typeof(T).Name);
+ CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
+ }
+
+ public IEnumerator GetEnumerator()
+ {
+ if (items != null)
+ {
+ return items.GetEnumerator();
+ }
+ else return new List().GetEnumerator();
+ }
+
+ public List GetItems()
+ {
+ if (items != null)
+ {
+ return items;
+ }
+ else return new List();
+ }
+
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ if (items != null)
+ {
+ return items.GetEnumerator();
+ }
+ else return new List().GetEnumerator();
+ }
+
+ public void Add(T item)
+ {
+ if (hasSignalR)
+ {
+ this.rest.PostAsync(item, typeof(T).Name);
+ }
+ else
+ {
+ this.rest.PostAsync(item, typeof(T).Name).ContinueWith((t) =>
+ {
+ Init().ContinueWith(z =>
+ {
+ Application.Current.Dispatcher.Invoke(() =>
+ {
+ CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
+ });
+ });
+ });
+ }
+
+ }
+
+ public void Update(T item)
+ {
+ if (hasSignalR)
+ {
+ this.rest.PutAsync(item, typeof(T).Name);
+ }
+ else
+ {
+ this.rest.PutAsync(item, typeof(T).Name).ContinueWith((t) =>
+ {
+ Init().ContinueWith(z =>
+ {
+ Application.Current.Dispatcher.Invoke(() =>
+ {
+ CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
+ });
+ });
+ });
+ }
+ }
+
+ public void Delete(int id)
+ {
+ if (hasSignalR)
+ {
+ this.rest.DeleteAsync(id, typeof(T).Name);
+ }
+ else
+ {
+ this.rest.DeleteAsync(id, typeof(T).Name).ContinueWith((t) =>
+ {
+ Init().ContinueWith(z =>
+ {
+ Application.Current.Dispatcher.Invoke(() =>
+ {
+ CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
+ });
+ });
+ });
+ }
+
+ }
+
+
+ }
+}
\ No newline at end of file
diff --git a/WD7UVN_SzTGUI_2023242.Client.WPF/ViewModels/ServiceViewModel.cs b/WD7UVN_SzTGUI_2023242.Client.WPF/ViewModels/ServiceViewModel.cs
new file mode 100644
index 0000000..c524014
--- /dev/null
+++ b/WD7UVN_SzTGUI_2023242.Client.WPF/ViewModels/ServiceViewModel.cs
@@ -0,0 +1,62 @@
+using CommunityToolkit.Mvvm.ComponentModel;
+using CommunityToolkit.Mvvm.Input;
+using System.ComponentModel;
+using System.Windows;
+using System.Windows.Input;
+using WD7UVN_HFT_2023241.Models;
+
+namespace WD7UVN_SzTGUI_2023242.Client.WPF
+{
+ internal class ServiceViewModel : ObservableRecipient
+ {
+ private string errorService;
+
+ public string ErrorService
+ {
+ get { return errorService; }
+ set { SetProperty(ref errorService, value); }
+ }
+
+
+ public RestCollection Services { get; set; }
+
+ private string newServiceText;
+
+ public string NewServiceText
+ {
+ get
+ {
+ return newServiceText;
+ }
+ set
+ {
+ newServiceText = value;
+ }
+ }
+
+ public ICommand SendServiceCommand { get; set; }
+
+
+ public static bool IsInDesignMode
+ {
+ get
+ {
+ var prop = DesignerProperties.IsInDesignModeProperty;
+ return (bool)DependencyPropertyDescriptor.FromProperty(prop, typeof(FrameworkElement)).Metadata.DefaultValue;
+ }
+ }
+
+
+ public ServiceViewModel()
+ {
+ if (!IsInDesignMode)
+ {
+ Services = new RestCollection("http://localhost:62005/", "Service", "hub");
+ SendServiceCommand = new RelayCommand(() =>
+ {
+ Services.Add(new Service(1, NewServiceText, DateTime.Now, new User(1, "Én")));
+ });
+ }
+ }
+ }
+}
diff --git a/WD7UVN_SzTGUI_2023242.Client.WPF/WD7UVN_SzTGUI_2023242.Client.WPF.csproj b/WD7UVN_SzTGUI_2023242.Client.WPF/WD7UVN_SzTGUI_2023242.Client.WPF.csproj
index 0f40828..7b068ac 100644
--- a/WD7UVN_SzTGUI_2023242.Client.WPF/WD7UVN_SzTGUI_2023242.Client.WPF.csproj
+++ b/WD7UVN_SzTGUI_2023242.Client.WPF/WD7UVN_SzTGUI_2023242.Client.WPF.csproj
@@ -7,4 +7,14 @@
true
+
+
+
+
+
+
+
+
+
+
diff --git a/WD7UVN_SzTGUI_2023242.Client.WPF/WD7UVN_SzTGUI_2023242.Client.WPF.csproj.user b/WD7UVN_SzTGUI_2023242.Client.WPF/WD7UVN_SzTGUI_2023242.Client.WPF.csproj.user
index 644b0a6..d04fb40 100644
--- a/WD7UVN_SzTGUI_2023242.Client.WPF/WD7UVN_SzTGUI_2023242.Client.WPF.csproj.user
+++ b/WD7UVN_SzTGUI_2023242.Client.WPF/WD7UVN_SzTGUI_2023242.Client.WPF.csproj.user
@@ -7,6 +7,14 @@
+
+ Code
+
+
+
+
+ Designer
+
Designer
diff --git a/WD7UVN_SzTGUI_2023242.Client.WPF/Windows/GetAllServices.xaml b/WD7UVN_SzTGUI_2023242.Client.WPF/Windows/GetAllServices.xaml
new file mode 100644
index 0000000..ca44173
--- /dev/null
+++ b/WD7UVN_SzTGUI_2023242.Client.WPF/Windows/GetAllServices.xaml
@@ -0,0 +1,64 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/WD7UVN_SzTGUI_2023242.Client.WPF/Windows/GetAllServices.xaml.cs b/WD7UVN_SzTGUI_2023242.Client.WPF/Windows/GetAllServices.xaml.cs
new file mode 100644
index 0000000..7bda3e9
--- /dev/null
+++ b/WD7UVN_SzTGUI_2023242.Client.WPF/Windows/GetAllServices.xaml.cs
@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+
+namespace WD7UVN_SzTGUI_2023242.Client.WPF
+{
+ ///
+ /// Interaction logic for GetAllServices.xaml
+ ///
+ public partial class GetAllServices : Window
+ {
+ public GetAllServices()
+ {
+ InitializeComponent();
+ }
+ }
+}