Exemple #1
0
        public override async Task <CommandResponse> HandleCommand(CreateDepositCommandModel request, CancellationToken cancellationToken)
        {
            var validModel = await CheckIfModelIsValid <CreateDepositCommandValidator>(request);

            if (!validModel)
            {
                return(ReplyFlowFailure());
            }

            var chargeValue = await TryTransformIntToDecimal(request.Value);

            if (chargeValue == 0M)
            {
                return(ReplyFlowFailure());
            }

            var charge  = new Charge(request.ProviderChargeId, chargeValue, request.CreatedAt);
            var deposit = new Depos(request.AccountId, charge);

            await _depositRepository.CreateAsync(deposit);

            await _depositRepository.Commit();

            return(ReplySuccessful(deposit.Id));
        }
Exemple #2
0
        public async Task <ActionResult <DepositDto> > PostAsync(CreateDepositDto depositDto)
        {
            var deposit = new DepositEntity
            {
                CustomerCID = depositDto.CustomerCID,
                LastAmount  = depositDto.LastAmount,
                Balance     = depositDto.Balance
            };

            await _depositRepository.CreateAsync(deposit);

            await _publishEndpoint.Publish(new DepositCreated(
                                               deposit.CustomerCID, deposit.LastAmount, deposit.Balance
                                               ));

            return(CreatedAtAction(nameof(GetByIDAsync), new { id = deposit.CustomerCID }, deposit));
        }