80 lines
2.4 KiB
C#
80 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Immutable;
|
|
using BlueWest.Collections;
|
|
using BlueWest.Data;
|
|
using PerformanceSolution.Tools;
|
|
|
|
namespace PerformanceSolution.Data
|
|
{
|
|
public static class MemoryData
|
|
{
|
|
public static UserList UserList = new UserList(new FastDictionary<int, User>());
|
|
|
|
private const string SavePathName = "userData";
|
|
|
|
public static TimeSpan DateKey = new TimeSpan(2386, 0,0,0,0 );
|
|
|
|
private static bool DEBUG = true;
|
|
|
|
static MemoryData()
|
|
{
|
|
if (DEBUG)
|
|
{
|
|
UserList = GenerateMockData();
|
|
//SaveUserList();
|
|
}
|
|
|
|
//LoadUsers();
|
|
}
|
|
|
|
public static void SaveUserList(UserList userList)
|
|
{
|
|
//UserList = userList;
|
|
//SaveLoadManager.Save(UserList, SavePathName);
|
|
}
|
|
|
|
public static void LoadUsers()
|
|
{
|
|
UserList = SaveLoadManager.Load<UserList>(SavePathName);
|
|
UserList ??= new UserList(new FastDictionary<int, User>());
|
|
}
|
|
|
|
public static DataQueryResult<FinanceTransaction> GetTransactionById(int userId, int transactionId) => UserList.GetTransactionById(userId, transactionId);
|
|
|
|
|
|
private static void SaveUserList() => SaveUserList(UserList);
|
|
|
|
public static User AddOrModifyUser(UserUpdateDto userUpdateDto, int userId = -1)
|
|
{
|
|
return UserList.AddUser(userId, userUpdateDto);
|
|
|
|
}
|
|
|
|
private static UserList GenerateMockData()
|
|
{
|
|
|
|
|
|
var transactions = new FastDictionary<int, FinanceTransaction>();
|
|
|
|
var u = new User(DateTime.Now.TimeOfDay, "Rui Sousa", "Sagres", "NOADD", "NOADD", 0, 0, transactions);
|
|
var list = new FastDictionary<int, User>(10);
|
|
var financeTransaction = new FinanceTransaction(TimeSpan.FromTicks(DateTime.Now.Ticks), u.Id, "", 0.00, 0.00, 0.00,
|
|
TimeSpan.FromTicks(DateTime.Now.Ticks), TimeSpan.FromTicks(DateTime.Now.Ticks));
|
|
transactions.Add(1, financeTransaction);
|
|
|
|
list.Add(0, u);
|
|
|
|
return new UserList(list);
|
|
}
|
|
|
|
public static DataQueryResult<User> GetUserById(int userId)
|
|
{
|
|
return UserList.GetUserById(userId);
|
|
}
|
|
|
|
public static ImmutableArray<FinanceTransaction> GetUserTransactions(int userId)
|
|
{
|
|
return UserList.GetUserTransactions(userId);
|
|
}
|
|
}
|
|
} |