示例#1
0
        public async Task <IOperationResult> HandleAsync(IDeletePayment command, ICorrelationContext context)
        {
            var payment = await _paymentsRepository.GetAsync(command.Id);

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

            await _paymentsRepository.DeleteAsync(payment);

            await _paymentsRepository.SaveChanges();

            await _busPublisher.Publish(new PaymentDeleted(command.Id));

            return(OperationResult.Ok());
        }
示例#2
0
        public async Task <IIdentifierResult> HandleAsync(ICreatePayment command, ICorrelationContext context)
        {
            await _userVerifier.AssertExists(command.UserId);

            var payment = new Domain.Payment(command.Id, command.Amount, command.UserId, command.Source, command.ExternalId);
            await _paymentsRepository.AddAsync(payment);

            try
            {
                await _paymentsRepository.SaveChanges();
            }
            catch (EntityAlreadyExistsException)
            {
                throw new BaristaException("payment_already_exists", $"A payment with the ID '{command.Id}' already exists.");
            }

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

            return(new IdentifierResult(payment.Id));
        }
示例#3
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());
        }