fixed an error where get command cant serlialize employee

This commit is contained in:
Tim G. | SnapixLP
2025-06-06 11:56:37 +02:00
parent 8630c4c346
commit 78a7597689
3 changed files with 124 additions and 48 deletions

View File

@@ -36,6 +36,7 @@ public class Tester
"clock in",
"clock out",
"clock break",
"clockhistory",
"help"
};
@@ -105,12 +106,46 @@ public class Tester
var responseLines = response.Split("%break").ToList();
await messageBox.ShowAsync("Command Result: clock break", responseLines);
}
else if (command == "clockhistory")
{
List<string> history = new List<string>();
string historyString = server.FullClockHistory().Result;
ClockHistoryResponse historyResponse;
try
{
historyResponse = JsonSerializer.Deserialize<ClockHistoryResponse>(historyString);
}
catch (Exception e)
{
ms.Error(e.Message);
return;
}
Dictionary<int, Employee> employees = new Dictionary<int, Employee>();
foreach (ClockEntry clockEntry in historyResponse.data)
{
if (!employees.ContainsKey(clockEntry.EmployeeId))
{
Employee newEmployee = await server.GetEmployee(id: clockEntry.EmployeeId);
employees.Add(clockEntry.EmployeeId, newEmployee);
ms.Log(newEmployee.ToJson());
}
history.Add($"{clockEntry.EmployeeId}-{employees[clockEntry.EmployeeId].Code} - {clockEntry.NewState} - {clockEntry.ChangeTime}");
//Console.WriteLine($"{clockEntry.EmployeeId}-{employees[clockEntry.EmployeeId].Code} - {clockEntry.NewState} - {clockEntry.ChangeTime}");
}
ItemSelector selectorTemp = new ItemSelector(ms);
selectorTemp.SetTitle("Clock History");
selectorTemp.SelectItemFromList(history.ToArray());
//Console.ReadKey();
}
}
catch (Exception ex)
{
await messageBox.ShowAsync("Error", new List<string> { ex.Message });
}
/*
string input = "";
if (command.Contains("login"))
@@ -140,4 +175,15 @@ public class Tester
*/
}
}
}
public class ClockEntry
{
public int EmployeeId { get; set; }
public int NewState { get; set; }
public DateTime ChangeTime { get; set; }
}
public class ClockHistoryResponse
{
public bool error { get; set; }
public List<ClockEntry> data { get; set; } = new();
}