mirror of
https://git.battle-of-pip.de/root/vpr-mitarbeiterverwaltung.git
synced 2025-06-20 15:53:16 +02:00
37 lines
912 B
C#
37 lines
912 B
C#
using System.Text.Json;
|
|
|
|
namespace Server;
|
|
|
|
public class DbConfig
|
|
{
|
|
private const string CONFIG_PATH = "config.json";
|
|
|
|
public string Username { get; set; } = "";
|
|
public string Password { get; set; } = "";
|
|
public string Server { get; set; } = "";
|
|
public string Port { get; set; } = ""; // new
|
|
public string Database { get; set; } = "";
|
|
|
|
public void Save()
|
|
{
|
|
var options = new JsonSerializerOptions { WriteIndented = true };
|
|
string json = JsonSerializer.Serialize(this, options);
|
|
File.WriteAllText(CONFIG_PATH, json);
|
|
}
|
|
|
|
public static DbConfig? Load()
|
|
{
|
|
if (!File.Exists(CONFIG_PATH))
|
|
return null;
|
|
|
|
try
|
|
{
|
|
string json = File.ReadAllText(CONFIG_PATH);
|
|
return JsonSerializer.Deserialize<DbConfig>(json);
|
|
}
|
|
catch
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
} |