mirror of
https://git.battle-of-pip.de/root/vpr-mitarbeiterverwaltung.git
synced 2025-06-20 15:53:16 +02:00
56 lines
1.7 KiB
C#
56 lines
1.7 KiB
C#
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace Library;
|
|
|
|
public class Employee
|
|
{
|
|
public int Id { get; set; }
|
|
public string Code { get; set; }
|
|
public string Surname { get; set; }
|
|
public string Forename { get; set; }
|
|
public string Email { get; set; }
|
|
public string Phone { get; set; }
|
|
public string Street { get; set; }
|
|
public string City { get; set; }
|
|
public string Postcode { get; set; }
|
|
public string Country { get; set; }
|
|
public string Department { get; set; }
|
|
public string Position { get; set; }
|
|
public EmployeeState EmployeeState { get; set; }
|
|
|
|
public Employee() { }
|
|
|
|
public Employee(string code, string surname, string forename, string email)
|
|
{
|
|
Code = code;
|
|
Surname = surname;
|
|
Forename = forename;
|
|
Email = email;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Serialisiert dieses Employee-Objekt in einen JSON-String (nur öffentliche Eigenschaften).
|
|
/// </summary>
|
|
public string ToJson()
|
|
{
|
|
var options = new JsonSerializerOptions
|
|
{
|
|
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
|
};
|
|
return JsonSerializer.Serialize(this, options);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Deserialisiert aus dem JSON-String ein neues Employee-Objekt (öffentliche Eigenschaften).
|
|
/// </summary>
|
|
public static Employee FromJson(string json)
|
|
{
|
|
var options = new JsonSerializerOptions
|
|
{
|
|
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
|
};
|
|
return JsonSerializer.Deserialize<Employee>(json, options)
|
|
?? throw new InvalidOperationException("Deserialization to Employee failed.");
|
|
}
|
|
} |