Fixed some Server bugs where the Employee is not send as full object

This commit is contained in:
Tim G. | SnapixLP
2025-06-06 00:00:46 +02:00
parent c0462e01b1
commit 830c94d5e4
3 changed files with 64 additions and 44 deletions

View File

@@ -117,7 +117,7 @@ public class Server
public string Response { get; set; }
}
public Task<Employee?> GetEmployee(int? id = null, string code = null)
public Task<Employee> GetEmployee(int? id = null, string code = null)
{
if (id == null && code == null)
{
@@ -128,8 +128,6 @@ public class Server
{
throw new ArgumentException("Only one of id or code should be provided.");
}
Employee? employee = null;
string commandResult;
// Implement logic to get a worker by ID or code
@@ -141,15 +139,14 @@ public class Server
// Deserialize the command result to an Employee object
try
{
employee = JsonSerializer.Deserialize<Employee>(commandResult);
return Task.FromResult(employee);
return Task.FromResult(Employee.FromJson(commandResult));
}
catch (JsonException)
{
Console.WriteLine("Failed to deserialize the command result.");
}
return Task.FromException<Employee?>(new Exception("Failed to get worker."));
return Task.FromException<Employee>(new Exception("Failed to get worker."));
}
public Task<string> Login(string username, string password)
@@ -182,7 +179,7 @@ public class Server
var commandResult = ExecuteCommandAsync("getSelfUser").Result;
try
{
var employee = JsonSerializer.Deserialize<Employee>(commandResult);
var employee = Employee.FromJson(commandResult);
if (employee != null)
{
return Task.FromResult(employee);