From 2c4d9ea20505f4bea2122d1481852b2ffb7ca6dc Mon Sep 17 00:00:00 2001 From: "Valeriano A.R" Date: Sat, 6 Jun 2015 01:53:11 +0200 Subject: [PATCH] Users: Add persistence to users list --- Scrummer/Code/BusinessLogic/Users.cs | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Scrummer/Code/BusinessLogic/Users.cs b/Scrummer/Code/BusinessLogic/Users.cs index 9f8b19b..da662f8 100644 --- a/Scrummer/Code/BusinessLogic/Users.cs +++ b/Scrummer/Code/BusinessLogic/Users.cs @@ -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(PersistenceFile); + } + + private void SaveData() + { + Persistence.SaveList(PersistenceFile, _users); + } + + #endregion + + #endregion } } \ No newline at end of file