Users: Add persistence to users list
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Scrummer.Code.Entities;
|
||||
using Scrummer.Code.JSON;
|
||||
|
||||
namespace Scrummer.Code.BusinessLogic
|
||||
{
|
||||
@@ -31,6 +33,15 @@ namespace Scrummer.Code.BusinessLogic
|
||||
|
||||
#endregion
|
||||
|
||||
#region Life cycle
|
||||
|
||||
public Users()
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public methods
|
||||
|
||||
public User User_GetByName(string name)
|
||||
@@ -93,6 +104,8 @@ namespace Scrummer.Code.BusinessLogic
|
||||
}
|
||||
|
||||
if (isNew) { _users.Add(user); }
|
||||
|
||||
SaveData();
|
||||
}
|
||||
return user;
|
||||
}
|
||||
@@ -109,5 +122,25 @@ namespace Scrummer.Code.BusinessLogic
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private methods
|
||||
|
||||
#region Persistence
|
||||
|
||||
private const string PersistenceFile = "priv/users.json";
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
_users = Persistence.LoadList<User>(PersistenceFile);
|
||||
}
|
||||
|
||||
private void SaveData()
|
||||
{
|
||||
Persistence.SaveList(PersistenceFile, _users);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user