diff --git a/TransactionProcessor.BusinessLogic/Services/FloatDomainService.cs b/TransactionProcessor.BusinessLogic/Services/FloatDomainService.cs index f76e375..73dd5fe 100644 --- a/TransactionProcessor.BusinessLogic/Services/FloatDomainService.cs +++ b/TransactionProcessor.BusinessLogic/Services/FloatDomainService.cs @@ -186,6 +186,19 @@ public async Task RecordTransaction(FloatActivityCommands.RecordTransact public static class DomainServiceHelper { + public static async Task> GetAggregateOrFailure(Func>> fetchFunc, + Guid aggregateId, + CancellationToken cancellationToken, + Boolean isNotFoundError = true) where TAggregate : Aggregate, new() + { + Result result = await fetchFunc(cancellationToken); + return result.IsFailed switch + { + true => DomainServiceHelper.HandleGetAggregateResult(result, aggregateId, isNotFoundError), + _ => Result.Success(result.Data) + }; + } + public static Result HandleGetAggregateResult(Result result, Guid aggregateId, bool isNotFoundError = true) where T : Aggregate, new() // Constraint: T is a subclass of Aggregate and has a parameterless constructor { diff --git a/TransactionProcessor.BusinessLogic/Services/MerchantDomainService.cs b/TransactionProcessor.BusinessLogic/Services/MerchantDomainService.cs index 793f923..9231307 100644 --- a/TransactionProcessor.BusinessLogic/Services/MerchantDomainService.cs +++ b/TransactionProcessor.BusinessLogic/Services/MerchantDomainService.cs @@ -71,25 +71,25 @@ public MerchantDomainService(Func aggregateService, #region Methods - private async Task> GetAggregateOrFailure(Func>> fetchFunc, - Guid aggregateId, - CancellationToken cancellationToken, - Boolean isNotFoundError = true) where TAggregate : Aggregate, new() - { - Result result = await fetchFunc(cancellationToken); - return result.IsFailed switch { - true => DomainServiceHelper.HandleGetAggregateResult(result, aggregateId, isNotFoundError), - _ => Result.Success(result.Data) - }; - } + //private async Task> GetAggregateOrFailure(Func>> fetchFunc, + // Guid aggregateId, + // CancellationToken cancellationToken, + // Boolean isNotFoundError = true) where TAggregate : Aggregate, new() + //{ + // Result result = await fetchFunc(cancellationToken); + // return result.IsFailed switch { + // true => DomainServiceHelper.HandleGetAggregateResult(result, aggregateId, isNotFoundError), + // _ => Result.Success(result.Data) + // }; + //} public async Task AddDeviceToMerchant(MerchantCommands.AddMerchantDeviceCommand command, CancellationToken cancellationToken) { try { - Result estateResult = await this.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(estateResult); - Result merchantResult = await this.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); + Result merchantResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(merchantResult); @@ -118,11 +118,11 @@ public async Task AssignOperatorToMerchant(MerchantCommands.AssignOperat CancellationToken cancellationToken) { try { - Result estateResult = await GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken); + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(estateResult); - Result merchantResult = await GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); + Result merchantResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(merchantResult); @@ -187,7 +187,7 @@ public async Task CreateMerchant(MerchantCommands.CreateMerchantCommand // Check if we have been sent a merchant id to use Guid merchantId = command.RequestDto.MerchantId ?? Guid.NewGuid(); - Result estateResult = await GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken); + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(estateResult); @@ -198,7 +198,7 @@ public async Task CreateMerchant(MerchantCommands.CreateMerchantCommand return Result.Invalid($"Estate Id {estateAggregate.AggregateId} has not been created"); } - Result merchantResult = await GetAggregateOrFailure(ct => this.AggregateService.GetLatest(merchantId, ct), merchantId, cancellationToken, false); + Result merchantResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(merchantId, ct), merchantId, cancellationToken, false); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(merchantResult); @@ -247,11 +247,11 @@ public async Task CreateMerchantUser(MerchantCommands.CreateMerchantUser createUserRequest.Claims.Add("estateId", command.EstateId.ToString()); createUserRequest.Claims.Add("merchantId", command.MerchantId.ToString()); - Result estateResult = await GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken); + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(estateResult); - Result merchantResult = await GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); + Result merchantResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(merchantResult); @@ -294,11 +294,11 @@ public async Task MakeMerchantDeposit(MerchantCommands.MakeMerchantDepos { try { - Result estateResult = await this.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(estateResult); - Result merchantResult = await this.GetAggregateOrFailure(ct => this.AggregateService.Get(command.MerchantId, ct), command.MerchantId, cancellationToken); + Result merchantResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.MerchantId, ct), command.MerchantId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(merchantResult); @@ -310,7 +310,7 @@ public async Task MakeMerchantDeposit(MerchantCommands.MakeMerchantDepos if (validateResult.IsFailed) return ResultHelpers.CreateFailure(validateResult); - Result getDepositListResult = await this.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken, false).ConfigureAwait(false); + Result getDepositListResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken, false).ConfigureAwait(false); if (getDepositListResult.IsFailed) return ResultHelpers.CreateFailure(getDepositListResult); @@ -346,11 +346,11 @@ public async Task MakeMerchantWithdrawal(MerchantCommands.MakeMerchantWi try { - Result estateResult = await this.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(estateResult); - Result merchantResult = await this.GetAggregateOrFailure(ct => this.AggregateService.Get(command.MerchantId, ct), command.MerchantId, cancellationToken); + Result merchantResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.MerchantId, ct), command.MerchantId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(merchantResult); @@ -362,7 +362,7 @@ public async Task MakeMerchantWithdrawal(MerchantCommands.MakeMerchantWi if (validateResult.IsFailed) return ResultHelpers.CreateFailure(validateResult); - Result getDepositListResult = await this.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken).ConfigureAwait(false); + Result getDepositListResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken).ConfigureAwait(false); if (getDepositListResult.IsFailed) return ResultHelpers.CreateFailure(getDepositListResult); @@ -407,11 +407,11 @@ public async Task MakeMerchantWithdrawal(MerchantCommands.MakeMerchantWi public async Task AddContractToMerchant(MerchantCommands.AddMerchantContractCommand command, CancellationToken cancellationToken) { try { - Result estateResult = await this.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(estateResult); - Result merchantResult = await this.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); + Result merchantResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(merchantResult); @@ -449,11 +449,11 @@ public async Task UpdateMerchant(MerchantCommands.UpdateMerchantCommand { try { - Result estateResult = await this.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(estateResult); - Result merchantResult = await this.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); + Result merchantResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(merchantResult); @@ -486,11 +486,11 @@ public async Task AddMerchantAddress(MerchantCommands.AddMerchantAddress { try { - Result estateResult = await this.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(estateResult); - Result merchantResult = await this.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); + Result merchantResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(merchantResult); @@ -527,11 +527,11 @@ public async Task UpdateMerchantAddress(MerchantCommands.UpdateMerchantA { try { - Result estateResult = await this.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(estateResult); - Result merchantResult = await this.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); + Result merchantResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(merchantResult); @@ -569,11 +569,11 @@ public async Task AddMerchantContact(MerchantCommands.AddMerchantContact { try { - Result estateResult = await this.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(estateResult); - Result merchantResult = await this.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); + Result merchantResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(merchantResult); @@ -604,11 +604,11 @@ public async Task AddMerchantContact(MerchantCommands.AddMerchantContact public async Task UpdateMerchantContact(MerchantCommands.UpdateMerchantContactCommand command, CancellationToken cancellationToken) { try { - Result estateResult = await this.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(estateResult); - Result merchantResult = await this.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); + Result merchantResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(merchantResult); @@ -636,11 +636,11 @@ public async Task UpdateMerchantContact(MerchantCommands.UpdateMerchantC public async Task RemoveOperatorFromMerchant(MerchantCommands.RemoveOperatorFromMerchantCommand command, CancellationToken cancellationToken) { try { - Result estateResult = await this.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(estateResult); - Result merchantResult = await this.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); + Result merchantResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(merchantResult); @@ -668,11 +668,11 @@ public async Task RemoveContractFromMerchant(MerchantCommands.RemoveMerc { try { - Result estateResult = await this.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(estateResult); - Result merchantResult = await this.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); + Result merchantResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(merchantResult); @@ -720,11 +720,11 @@ public async Task SwapMerchantDevice(MerchantCommands.SwapMerchantDevice { try { - Result estateResult = await this.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(estateResult); - Result merchantResult = await this.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); + Result merchantResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(merchantResult); diff --git a/TransactionProcessor.BusinessLogic/Services/OperatorDomainService.cs b/TransactionProcessor.BusinessLogic/Services/OperatorDomainService.cs index 0dc4000..f2f03d3 100644 --- a/TransactionProcessor.BusinessLogic/Services/OperatorDomainService.cs +++ b/TransactionProcessor.BusinessLogic/Services/OperatorDomainService.cs @@ -26,27 +26,30 @@ public class OperatorDomainService : IOperatorDomainService public OperatorDomainService(Func aggregateService) { this.AggregateService = aggregateService(); } - - private async Task ApplyUpdates(Func<(EstateAggregate, OperatorAggregate), Result> action, Guid estateId, Guid operatorId, CancellationToken cancellationToken, Boolean isNotFoundError = true) + + public async Task CreateOperator(OperatorCommands.CreateOperatorCommand command, CancellationToken cancellationToken) { - try - { - Result getEstateResult = await this.AggregateService.Get(estateId, cancellationToken); - if (getEstateResult.IsFailed) { - return ResultHelpers.CreateFailure(getEstateResult); + try { + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); + if (estateResult.IsFailed) + return ResultHelpers.CreateFailure(estateResult); + + Result operatorResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.RequestDto.OperatorId, ct), command.RequestDto.OperatorId, cancellationToken, false); + if (estateResult.IsFailed) + return ResultHelpers.CreateFailure(operatorResult); + + EstateAggregate estateAggregate = estateResult.Data; + OperatorAggregate operatorAggregate = operatorResult.Data; + + if (estateAggregate.IsCreated == false) { + return Result.Forbidden($"Estate with Id {command.EstateId} not created"); } - EstateAggregate estateAggregate = getEstateResult.Data; - Result getOperatorResult = await this.AggregateService.GetLatest(operatorId, cancellationToken); - Result operatorAggregateResult = - DomainServiceHelper.HandleGetAggregateResult(getOperatorResult, operatorId, isNotFoundError); - if (operatorAggregateResult.IsFailed) - return ResultHelpers.CreateFailure(operatorAggregateResult); - OperatorAggregate operatorAggregate = operatorAggregateResult.Data; + if (operatorAggregate.IsCreated) { + return Result.Forbidden($"Operator with Id {command.RequestDto.OperatorId} already created"); + } - Result result = action((estateAggregate, operatorAggregate)); - if (result.IsFailed) - return ResultHelpers.CreateFailure(result); + operatorAggregate.Create(command.EstateId, command.RequestDto.Name, command.RequestDto.RequireCustomMerchantNumber.GetValueOrDefault(), command.RequestDto.RequireCustomTerminalNumber.GetValueOrDefault()); Result saveResult = await this.AggregateService.Save(operatorAggregate, cancellationToken); if (saveResult.IsFailed) @@ -54,48 +57,46 @@ private async Task ApplyUpdates(Func<(EstateAggregate, OperatorAggregate return Result.Success(); } - catch (Exception ex) - { + catch (Exception ex) { return Result.Failure(ex.GetExceptionMessages()); } } - public async Task CreateOperator(OperatorCommands.CreateOperatorCommand command, CancellationToken cancellationToken) + public async Task UpdateOperator(OperatorCommands.UpdateOperatorCommand command, CancellationToken cancellationToken) { - Result result = await ApplyUpdates(((EstateAggregate estateAggregate, OperatorAggregate operatorAggregate) aggregates) => { - if (aggregates.estateAggregate.IsCreated == false) - { - return Result.Forbidden($"Estate with Id {command.EstateId} not created"); - } - - if (aggregates.operatorAggregate.IsCreated) - { - return Result.Forbidden($"Operator with Id {command.RequestDto.OperatorId} already created"); - } + try + { + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); + if (estateResult.IsFailed) + return ResultHelpers.CreateFailure(estateResult); - aggregates.operatorAggregate.Create(command.EstateId, command.RequestDto.Name, - command.RequestDto.RequireCustomMerchantNumber.GetValueOrDefault(), - command.RequestDto.RequireCustomTerminalNumber.GetValueOrDefault()); + Result operatorResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.OperatorId, ct), command.OperatorId, cancellationToken); + if (estateResult.IsFailed) + return ResultHelpers.CreateFailure(operatorResult); - return Result.Success(); + EstateAggregate estateAggregate = estateResult.Data; + OperatorAggregate operatorAggregate = operatorResult.Data; - }, command.EstateId, command.RequestDto.OperatorId, cancellationToken, isNotFoundError: false); + if (estateAggregate.IsCreated == false) + { + return Result.Forbidden($"Estate with Id {command.EstateId} not created"); + } - return result; - } + operatorAggregate.UpdateOperator(command.RequestDto.Name, + command.RequestDto.RequireCustomMerchantNumber.GetValueOrDefault(), + command.RequestDto.RequireCustomTerminalNumber.GetValueOrDefault()); - public async Task UpdateOperator(OperatorCommands.UpdateOperatorCommand command, CancellationToken cancellationToken) - { - Result result = await ApplyUpdates(((EstateAggregate estateAggregate, OperatorAggregate operatorAggregate) aggregates) => { - aggregates.operatorAggregate.UpdateOperator(command.RequestDto.Name, - command.RequestDto.RequireCustomMerchantNumber.GetValueOrDefault(), - command.RequestDto.RequireCustomTerminalNumber.GetValueOrDefault()); + Result saveResult = await this.AggregateService.Save(operatorAggregate, cancellationToken); + if (saveResult.IsFailed) + return ResultHelpers.CreateFailure(saveResult); return Result.Success(); + } + catch (Exception ex) + { + return Result.Failure(ex.GetExceptionMessages()); + } - }, command.EstateId, command.OperatorId, cancellationToken); - - return result; } } }