Task done

This commit is contained in:
2025-09-27 23:01:24 +02:00
parent 6c5579809d
commit 6fb3ffb680
8 changed files with 95 additions and 19 deletions

View File

@@ -5,5 +5,5 @@ namespace Repository;
public interface IRepository
{
public User? Read();
public void Write(User item);
public int Write(User item);
}

View File

@@ -32,24 +32,28 @@ public class JsonRepository : IRepository
return null;
}
public void Write(User item)
public int Write(User item)
{
try
{
string json = JsonSerializer.Serialize(item);
File.WriteAllText(_fileName, json);
return 0;
}
catch (JsonException e)
{
WriteToStdErr($"JSON error: {e.Message}");
return e.GetHashCode();
}
catch (IOException e)
{
WriteToStdErr($"File I/O error: {e.Message}");
return e.GetHashCode();
}
catch (Exception e)
{
WriteToStdErr($"Unexpected error: {e.Message}");
return e.GetHashCode();
}
}