CodeLiturgy.Dashboard/BlueWest.Data/User/User.cs

54 lines
1.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Transactions;
using BlueWest.Collections;
using MapTo;
using MessagePack;
using Newtonsoft.Json;
using BlueWest.Collections;
namespace BlueWest.Data
{
[MessagePackObject]
[UseUpdate]
[MapFrom(typeof(UserUpdateDto))]
public partial class User
{
[Key(1)] public TimeSpan Id { get; }
[Key(2)] public string Name { get; set; }
[Key(8)] public FastDictionary<int, FinanceTransaction> FinanceTransactions { get; }
public User(TimeSpan id, string name, string address, string btcAddress, string ltcAddress, double btcAmount, double ltcAmount, FastDictionary<int, FinanceTransaction> financeTransactions)
{
Id = id;
Name = name;
FinanceTransactions = financeTransactions;
}
public void AddTransaction(FinanceTransaction financeTransaction)
{
FinanceTransactions.Add(FinanceTransactions.Count + 1, financeTransaction);
}
public void AddTransaction(FinanceTransactionInsertDto financeTransaction)
{
FinanceTransactions.Add(FinanceTransactions.Count + 1,
new FinanceTransaction(financeTransaction, TimeSpan.FromTicks(DateTime.Now.Ticks), Id));
}
internal bool HasTransaction(int transactionId)
{
return FinanceTransactions.Contains(transactionId);
}
internal FinanceTransaction GetTransactionById(int transactionId)
{
return FinanceTransactions[transactionId];
}
}
}