예제 #1
0
        /// <summary>
        ///     Executes the Use Case.
        /// </summary>
        /// <param name="input">Input Message.</param>
        /// <returns>Task.</returns>
        public async Task Execute(DepositInput input)
        {
            if (input is null)
            {
                this._depositGetAccountsOutputPort
                .WriteError(Messages.InputIsNull);
                return;
            }

            IAccount account = await this._accountRepository
                               .GetAccount(input.AccountId)
                               .ConfigureAwait(false);

            if (account is null)
            {
                this._depositGetAccountsOutputPort
                .NotFound($"The account {input.AccountId.ToGuid()} does not exist or is not processed yet.");
                return;
            }

            ICredit credit = await this._accountService
                             .Deposit(account, input.Amount)
                             .ConfigureAwait(false);

            await this._unitOfWork
            .Save()
            .ConfigureAwait(false);

            this.BuildOutput(credit, account);
        }
예제 #2
0
        /// <summary>
        ///     Executes the Use Case.
        /// </summary>
        /// <param name="input">Input Message.</param>
        /// <returns>Task.</returns>
        public async Task Execute(DepositInput input)
        {
            if (input is null)
            {
                this._outputPort.WriteError(Messages.InputIsNull);
                return;
            }

            try
            {
                var account = await this._accountRepository.GetAccount(input.AccountId)
                              .ConfigureAwait(false);

                var credit = await this._accountService.Deposit(account, input.Amount)
                             .ConfigureAwait(false);

                await this._unitOfWork.Save()
                .ConfigureAwait(false);

                this.BuildOutput(credit, account);
            }
            catch (AccountNotFoundException ex)
            {
                this._outputPort.NotFound(ex.Message);
            }
        }
예제 #3
0
        public override Empty Deposit(DepositInput input)
        {
            // (All) DApp Contract can't use TransferFrom method directly.
            State.TokenContract.TransferToContract.Send(new TransferToContractInput
            {
                Symbol = State.TokenContract.GetPrimaryTokenSymbol.Call(new Empty()).Value,
                Amount = input.Amount
            });

            State.TokenContract.Issue.Send(new IssueInput
            {
                Symbol = State.Symbol.Value,
                Amount = input.Amount,
                To     = Context.Sender
            });

            // Update profile.
            var profile = State.Profiles[Context.Sender];

            profile.Records.Add(new Record
            {
                Type        = RecordType.Deposit,
                Timestamp   = Context.CurrentBlockTime,
                Description = $"{State.Symbol.Value} +{input.Amount}"
            });
            State.Profiles[Context.Sender] = profile;

            return(new Empty());
        }
예제 #4
0
        public async Task Execute(DepositInput input)
        {
            IAccount account = await _accountRepository.Get(input.AccountId);

            if (account == null)
            {
                _outputHandler.Error($"The account {input.AccountId} does not exist or is already closed.");
                return;
            }

            ICredit credit = account.Deposit(_entityFactory, input.Amount);

            await _accountRepository.Update(account, credit);

            // Publish the event to the enterprice service bus
            await _serviceBus.PublishEventAsync(new Shared.Events.DepositCompleted()
            {
                AccountId = input.AccountId, Amount = input.Amount.ToMoney().ToDecimal()
            });

            await _unitOfWork.Save();

            DepositOutput output = new DepositOutput(
                credit,
                account.GetCurrentBalance()
                );

            _outputHandler.Default(output);
        }
예제 #5
0
        public override Empty Deposit(DepositInput input)
        {
            // User Address -> DApp Contract.
            State.TokenContract.TransferToContract.Send(new TransferToContractInput
            {
                Symbol = "ELF",
                Amount = input.Amount
            });

            State.TokenContract.Issue.Send(new IssueInput
            {
                Symbol = State.Symbol.Value,
                Amount = input.Amount,
                To     = Context.Sender
            });

            // Update profile.
            var profile = State.Profiles[Context.Sender];

            profile.Records.Add(new Record
            {
                Type        = RecordType.Deposit,
                Timestamp   = Context.CurrentBlockTime,
                Description = $"{State.Symbol.Value} +{input.Amount}"
            });
            State.Profiles[Context.Sender] = profile;

            return(new Empty());
        }
예제 #6
0
        /// <summary>
        ///     ///     Executes the Use Case.
        /// </summary>
        /// <param name="input">Input Message.</param>
        /// <returns>Task.</returns>
        public async Task Execute(DepositInput input)
        {
            if (input is null)
            {
                this._depositOutputPort
                .WriteError(Messages.InputIsNull);
                return;
            }

            IAccount account = await this._accountRepository
                               .GetAccount(input.AccountId)
                               .ConfigureAwait(false);

            if (account is null)
            {
                this._depositOutputPort
                .NotFound(Messages.AccountDoesNotExist);
                return;
            }

            PositiveMoney amountConverted = await this._currencyExchange
                                            .ConvertToUSD(input.Amount)
                                            .ConfigureAwait(false);

            ICredit credit = await this._accountService
                             .Deposit(account, amountConverted)
                             .ConfigureAwait(false);

            await this._unitOfWork
            .Save()
            .ConfigureAwait(false);

            this.BuildOutput(credit, account);
        }
예제 #7
0
        public void GivenValidData_InputCreated()
        {
            var actual = new DepositInput(
                new AccountId(Guid.NewGuid()),
                new PositiveMoney(10));

            Assert.NotNull(actual);
        }
예제 #8
0
        public async Task <IActionResult> Deposit([FromBody] DepositRequest message)
        {
            var request = new DepositInput(message.AccountId, message.Amount);

            await depositInput.Process(request);

            return(depositPresenter.ViewModel);
        }
        public void GivenValidData_InputCreated()
        {
            var actual = new DepositInput(
                Guid.NewGuid(),
                new PositiveAmount(10)
                );

            Assert.NotNull(actual);
        }
예제 #10
0
        public async Task Execute(DepositInput input)
        {
            var account = await _accountRepository.Get(input.AccountId);
            var credit = account.Deposit(_entityFactory, input.Amount);

            await _accountRepository.Update(account, credit);
            await _unitOfWork.Save();

            BuildOutput(credit, account);
        }
        public async Task <IActionResult> Deposit([FromForm][Required] DepositRequest request)
        {
            var input = new DepositInput(
                new AccountId(request.AccountId),
                new PositiveMoney(request.Amount));

            await this.mediator.PublishAsync(input);

            return(this.presenter.ViewModel);
        }
        public async Task<IActionResult> Deposit([FromBody][Required] DepositRequest request)
        {
            var input = new DepositInput(
                request.AccountId,
                new PositiveMoney(request.Amount)
            );

            await _mediator.PublishAsync(input);
            return _presenter.ViewModel;
        }
        public async Task <IActionResult> Deposit(
            [FromServices] IMediator mediator, [FromServices] DepositPresenter presenter,
            [FromForm][Required] DepositRequest request)
        {
            var input = new DepositInput(request.AccountId, request.Amount);
            await mediator.PublishAsync(input)
            .ConfigureAwait(false);

            return(presenter.ViewModel);
        }
        public async Task <IActionResult> Deposit([FromBody][Required] DepositRequest request)
        {
            var depositInput = new DepositInput(
                request.AccountId,
                new PositiveMoney(request.Amount)
                );

            await _depositUseCase.Execute(depositInput);

            return(_presenter.ViewModel);
        }
예제 #15
0
        public async Task <IActionResult> Deposit(
            [FromServices] IMediator mediator,
            [FromServices] DepositGetAccountsPresenter getAccountsPresenter,
            [FromForm][Required] DepositRequest request)
        {
            var input = new DepositInput(
                new AccountId(request.AccountId),
                new PositiveMoney(request.Amount));

            await mediator.PublishAsync(input)
            .ConfigureAwait(false);

            return(getAccountsPresenter.ViewModel);
        }
예제 #16
0
        public async Task Execute(DepositInput input)
        {
            try
            {
                var account = await _accountRepository.Get(input.AccountId);

                var credit = await _accountService.Deposit(account, input.Amount);

                await _unitOfWork.Save();

                BuildOutput(credit, account);
            }
            catch (AccountNotFoundException ex)
            {
                _outputPort.NotFound(ex.Message);
                return;
            }
        }
예제 #17
0
        public async Task Execute(DepositInput input)
        {
            IAccount account = await _accountRepository.Get(input.AccountId);

            if (account == null)
            {
                _outputHandler.Error($"The account {input.AccountId} does not exist or is already closed.");
                return;
            }

            ICredit credit = account.Deposit(_entityFactory, input.Amount);

            await _accountRepository.Update(account, credit);

            await _unitOfWork.Save();

            DepositOutput output = new DepositOutput(
                credit,
                account.GetCurrentBalance());

            _outputHandler.Default(output);
        }
예제 #18
0
        public async Task Execute(DepositInput input)
        {
            IAccount account;

            try
            {
                account = await _accountRepository.Get(input.AccountId);
            }
            catch (AccountNotFoundException ex)
            {
                _outputPort.NotFound(ex.Message);
                return;
            }

            var credit = account.Deposit(_entityFactory, input.Amount);

            await _accountRepository.Update(account, credit);

            await _unitOfWork.Save();

            BuildOutput(credit, account);
        }
        public void GivenValidData_InputCreated()
        {
            DepositInput actual = new DepositInput(Guid.NewGuid(), 10);

            Assert.NotNull(actual);
        }