mirror of
https://git.battle-of-pip.de/root/vpr-mitarbeiterverwaltung.git
synced 2025-10-14 10:04:52 +02:00
fixed an error where get command cant serlialize employee
This commit is contained in:
@@ -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();
|
||||
}
|
Reference in New Issue
Block a user