Exemplo n.º 1
0
        /// <summary>
        /// ანგარიშზე თანხის ჩარიხვის ოპერაცია
        /// </summary>
        public async Task <long> Deposit(DepositByAccountId command)
        {
            var account = await _accountRepo.GetByIdAsync(command.AccountId);

            var deposit = new Money(command.Currency, command.Amount);

            account.Balance += deposit;

            await _accountRepo.UpdateAsync(account);

            return(await _operationRepo.AddAsync(new Operation(0)
            {
                AccountId = account.Id,
                CustomerId = account.CustomerId,
                Amount = deposit.Amount,
                Currency = deposit.Currency,
                Type = OperationType.Deposit,
                HappenedAt = command.HappenedAt,
                CreatedAt = _dateTime.Now
            }));
        }
Exemplo n.º 2
0
        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);
        }