A few more improvements and cleanup for the wallet

This commit is contained in:
Kwoth
2022-03-21 15:55:57 +01:00
parent b7d1fd1b47
commit cfb202cc95
3 changed files with 45 additions and 23 deletions

View File

@@ -10,6 +10,7 @@ public static class CurrencyServiceExtensions
return await wallet.GetBalance();
}
// todo transfer should be a transaction
public static async Task<bool> TransferAsync(
this ICurrencyService cs,
ulong fromId,

View File

@@ -43,17 +43,18 @@ public class DefaultWallet : IWallet
if (changed == 0)
return false;
await using var ctx2 = ctx.CreateLinqToDbContext();
await ctx2
.InsertAsync(new CurrencyTransaction()
{
Amount = -amount,
Note = txData.Note,
UserId = UserId,
Type = txData.Type,
Extra = txData.Extra,
OtherId = txData.OtherId
});
await ctx
.GetTable<CurrencyTransaction>()
.InsertAsync(() => new()
{
Amount = -amount,
Note = txData.Note,
UserId = UserId,
Type = txData.Type,
Extra = txData.Extra,
OtherId = txData.OtherId,
DateAdded = DateTime.UtcNow
});
return true;
}
@@ -88,17 +89,16 @@ public class DefaultWallet : IWallet
await tran.CommitAsync();
}
var ct = new CurrencyTransaction()
{
Amount = amount,
UserId = UserId,
Note = txData.Note,
Type = txData.Type,
Extra = txData.Extra,
OtherId = txData.OtherId
};
await using var ctx2 = ctx.CreateLinqToDbContext();
await ctx2.InsertAsync(ct);
await ctx.GetTable<CurrencyTransaction>()
.InsertAsync(() => new()
{
Amount = amount,
UserId = UserId,
Note = txData.Note,
Type = txData.Type,
Extra = txData.Extra,
OtherId = txData.OtherId,
DateAdded = DateTime.UtcNow
});
}
}