Esempio n. 1
0
        public async Task <IOperationResult> HandleAsync(IUpdatePayment command, ICorrelationContext context)
        {
            var payment = await _paymentsRepository.GetAsync(command.Id);

            if (payment is null)
            {
                throw new BaristaException("payment_not_found", $"Payment with ID '{command.Id}' was not found");
            }

            await _userVerifier.AssertExists(command.UserId);

            payment.SetUserId(command.UserId);
            payment.SetAmount(command.Amount);
            payment.SetExternalId(command.ExternalId);
            payment.SetSource(command.Source);

            await _paymentsRepository.UpdateAsync(payment);

            await _paymentsRepository.SaveChanges();

            await _busPublisher.Publish(new PaymentUpdated(payment));

            return(OperationResult.Ok());
        }