Initial commit: demo 24.11
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
using System.IO;
|
||||
|
||||
namespace RentalApp.Helpers;
|
||||
|
||||
public static class LockHelper
|
||||
{
|
||||
private static readonly string Path = "lock.txt";
|
||||
|
||||
public static void SetLock(DateTime until)
|
||||
=> File.WriteAllText(Path, until.ToString("o"));
|
||||
|
||||
public static DateTime? GetLock()
|
||||
=> File.Exists(Path) && DateTime.TryParse(File.ReadAllText(Path), out var dt)
|
||||
? dt : null;
|
||||
|
||||
public static bool IsLocked()
|
||||
=> GetLock() is DateTime dt && dt > DateTime.Now;
|
||||
}
|
||||
Reference in New Issue
Block a user