mirror of
https://git.battle-of-pip.de/root/vpr-mitarbeiterverwaltung.git
synced 2025-12-13 22:31:38 +01:00
added mysql connection
This commit is contained in:
37
Server/DbConfig.cs
Normal file
37
Server/DbConfig.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user