2021-12-06 02:49:27 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2021-12-26 20:43:27 +03:00
|
|
|
|
using System.Collections.Immutable;
|
2021-12-10 03:04:48 +03:00
|
|
|
|
using System.Transactions;
|
2021-12-06 02:49:27 +03:00
|
|
|
|
using BlueWest.Collections;
|
|
|
|
|
using BlueWest.Data;
|
|
|
|
|
using PerformanceSolution.Tools;
|
|
|
|
|
|
|
|
|
|
namespace PerformanceSolution.Data
|
|
|
|
|
{
|
|
|
|
|
public static class MemoryData
|
|
|
|
|
{
|
2021-12-10 03:04:48 +03:00
|
|
|
|
public static UserList UserList = new UserList(new FastDictionary<int, User>());
|
2021-12-06 02:49:27 +03:00
|
|
|
|
|
|
|
|
|
private const string SavePathName = "userData";
|
|
|
|
|
|
|
|
|
|
private static bool DEBUG = true;
|
|
|
|
|
|
|
|
|
|
static MemoryData()
|
|
|
|
|
{
|
|
|
|
|
if (DEBUG)
|
|
|
|
|
{
|
|
|
|
|
UserList = GenerateMockData();
|
2021-12-26 20:43:27 +03:00
|
|
|
|
//SaveUserList();
|
2021-12-06 02:49:27 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-26 20:43:27 +03:00
|
|
|
|
//LoadUsers();
|
2021-12-06 02:49:27 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void SaveUserList(UserList userList)
|
|
|
|
|
{
|
2021-12-26 20:43:27 +03:00
|
|
|
|
//UserList = userList;
|
|
|
|
|
//SaveLoadManager.Save(UserList, SavePathName);
|
2021-12-06 02:49:27 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void LoadUsers()
|
|
|
|
|
{
|
|
|
|
|
UserList = SaveLoadManager.Load<UserList>(SavePathName);
|
2021-12-10 03:04:48 +03:00
|
|
|
|
UserList ??= new UserList(new FastDictionary<int, User>());
|
2021-12-06 02:49:27 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-26 20:43:27 +03:00
|
|
|
|
public static DataQueryResult<FinanceTransaction> GetTransactionById(int userId, int transactionId) => UserList.GetTransactionById(userId, transactionId);
|
2021-12-06 02:49:27 +03:00
|
|
|
|
|
|
|
|
|
|
2021-12-08 02:57:27 +03:00
|
|
|
|
private static void SaveUserList() => SaveUserList(UserList);
|
2021-12-06 02:49:27 +03:00
|
|
|
|
|
2021-12-10 03:04:48 +03:00
|
|
|
|
public static User AddOrModifyUser(UserUpdateDto userUpdateDto, int userId = -1)
|
2021-12-06 02:49:27 +03:00
|
|
|
|
{
|
2021-12-10 03:04:48 +03:00
|
|
|
|
return UserList.AddUser(userId, userUpdateDto);
|
2021-12-08 02:57:27 +03:00
|
|
|
|
|
2021-12-06 02:49:27 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-10 03:04:48 +03:00
|
|
|
|
private static UserList GenerateMockData()
|
2021-12-06 02:49:27 +03:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
2021-12-26 20:43:27 +03:00
|
|
|
|
var transactions = new FastDictionary<int, FinanceTransaction>();
|
2021-12-10 03:04:48 +03:00
|
|
|
|
var financeTransaction = new FinanceTransaction(0, 1, FinanceTransactionType.Buy, FinanceSymbol.BTC_EUR, 0,
|
|
|
|
|
0, 0.1, DateTime.Now);
|
2021-12-26 20:43:27 +03:00
|
|
|
|
transactions.Add(1, financeTransaction);
|
2021-12-10 03:04:48 +03:00
|
|
|
|
|
|
|
|
|
var u = new User(1, "Rui Sousa", "Sagres", "NOADD", "NOADD", 0, 0, transactions);
|
|
|
|
|
var list = new FastDictionary<int, User>(10);
|
|
|
|
|
list.Add(0, u);
|
2021-12-06 02:49:27 +03:00
|
|
|
|
|
2021-12-10 03:04:48 +03:00
|
|
|
|
return new UserList(list);
|
2021-12-06 02:49:27 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-26 20:43:27 +03:00
|
|
|
|
public static DataQueryResult<User> GetUserById(int userId)
|
2021-12-06 02:49:27 +03:00
|
|
|
|
{
|
2021-12-10 03:04:48 +03:00
|
|
|
|
return UserList.GetUserById(userId);
|
2021-12-06 02:49:27 +03:00
|
|
|
|
}
|
2021-12-10 03:04:48 +03:00
|
|
|
|
|
2021-12-26 20:43:27 +03:00
|
|
|
|
public static ImmutableArray<FinanceTransaction> GetUserTransactions(int userId)
|
2021-12-06 02:49:27 +03:00
|
|
|
|
{
|
2021-12-10 03:04:48 +03:00
|
|
|
|
return UserList.GetUserTransactions(userId);
|
2021-12-06 02:49:27 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|