Skip to content

Commit

Permalink
Modifying currency in creation Wallet entity
Browse files Browse the repository at this point in the history
  • Loading branch information
Edrisym committed Nov 20, 2024
1 parent c28e948 commit 1d1e93a
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions EWallet.Api/Common/Models/Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,21 @@ public WalletStatus Status

public static Wallet Create(
decimal balance,
Currency currency,
CurrencyId currencyId,
WalletStatus initialStatus = WalletStatus.UnderReview)
{
if (decimal.IsNegative(balance))
NegativeBalanceException.Throw(balance);
else if (InitialBalance > balance)
InsufficientInitialBalanceException.Throw(balance);

ArgumentNullException.ThrowIfNull(currency);
if (!IsValidRatio(currency))
InvalidCurrencyRatioException.Throw(currency.Ratio);
ArgumentNullException.ThrowIfNull(currencyId);

return new Wallet
{
Id = Guid.NewGuid(),
Balance = balance,
Currency = currency,
CurrencyId = currency.Id,
CurrencyId = currencyId,
StatusId = (int)initialStatus,
CreatedOnUtc = DateTime.UtcNow,
};
Expand Down Expand Up @@ -78,11 +75,6 @@ public void Withdraw(decimal amount)
Balance -= amount;
}

private static bool IsValidRatio(Currency currency)
{
return decimal.IsPositive(currency.Ratio) && currency.Ratio > 1.0m;
}


private Wallet SwitchStatus(WalletStatus newStatus, Action<Wallet>? operation = null)
{
Expand Down

0 comments on commit 1d1e93a

Please sign in to comment.