/// <summary> /// ანგარიშიდან თანხის ჩამოჭრის ოპერაცია /// </summary> public async Task <long> WithdrawAsync(WithdrawByAccountId command) { var account = await _accountRepo.GetByIdAsync(command.AccountId); var operationAmount = new Money(command.Currency, command.Amount); if (account.Balance < operationAmount) { throw new InsufficientFundsException(account.Id); } account.Balance -= operationAmount; await _accountRepo.UpdateAsync(account); return(await _operationRepo.AddAsync(new Operation(0) { AccountId = account.Id, Amount = operationAmount.Amount, Currency = operationAmount.Currency, CustomerId = account.CustomerId, Type = OperationType.Withdraw, HappenedAt = command.HappenedAt, CreatedAt = _dateTime.Now })); }
private OperationCommand CreateCommand(string command) { OperationCommand operationCommand; if (command == "d") { operationCommand = new WithdrawByAccountId(); } else if (command == "c") { operationCommand = new DepositByAccountId(); } else { throw new ArgumentOutOfRangeException(nameof(command)); } operationCommand.HappenedAt = DateTime.ParseExact(ReadLine("HappenedAt: "), "yyyy/mm/dd", CultureInfo.InvariantCulture); operationCommand.AccountId = int.Parse(ReadLine("AccountId: ")); operationCommand.Currency = Enum.Parse <CurrencyCode>(ReadLine("Currency: ")); operationCommand.Amount = decimal.Parse(ReadLine("Amount: ")); return(operationCommand); }