public async Task <Result <PaymentMethodViewModel> > HandleAsync(AddPaymentMethodCommand command, User currentUser, CancellationToken cancellationToken = default) { if (command == null) { throw new ArgumentNullException(nameof(command)); } if (currentUser == null) { return(FailureResult <PaymentMethodViewModel> .Unauthorized()); } if (currentUser.Role < Role.SystemAdmin) { return(FailureResult <PaymentMethodViewModel> .Forbidden()); } var paymentMethod = await paymentMethodRepository.FindByNameAsync(command.Name, cancellationToken); if (paymentMethod != null) { return(FailureResult <PaymentMethodViewModel> .Create(FailureResultCode.PaymentMethodAlreadyExists)); } paymentMethod = paymentMethodFactory.Create(command.Name, command.Description); await paymentMethodRepository.StoreAsync(paymentMethod, cancellationToken); return(SuccessResult <PaymentMethodViewModel> .Create(PaymentMethodViewModel.FromPaymentMethod(paymentMethod))); }
public async Task <Result <bool> > HandleAsync(ChangePaymentMethodCommand command, User currentUser, CancellationToken cancellationToken = default) { if (command == null) { throw new ArgumentNullException(nameof(command)); } if (currentUser == null) { return(FailureResult <bool> .Unauthorized()); } if (currentUser.Role < Role.SystemAdmin) { return(FailureResult <bool> .Forbidden()); } var paymentMethod = await paymentMethodRepository.FindByPaymentMethodIdAsync(command.PaymentMethodId, cancellationToken); if (paymentMethod == null) { return(FailureResult <bool> .Create(FailureResultCode.PaymentMethodDoesNotExist)); } paymentMethod.Change(command.Name, command.Description); await paymentMethodRepository.StoreAsync(paymentMethod, cancellationToken); return(SuccessResult <bool> .Create(true)); }