public async Task Handle(OperationRejectedEvent evt, ICommandSender sender) { var aggregate = await _riskControlRepository.TryGetAsync(evt.OperationId); if (aggregate == null) { return; // not a cashout operation } if (aggregate.OnOperationRejected(evt.Message)) { // just send a regular CashoutFailed notification sender.SendCommand ( new NotifyCashoutFailedCommand { OperationId = aggregate.OperationId, ClientId = aggregate.ClientId, AssetId = aggregate.AssetId, Amount = aggregate.Amount, StartMoment = aggregate.StartMoment.Value, FinishMoment = aggregate.OperationRejectionMoment.Value, Error = aggregate.Error, ErrorCode = CashoutErrorCode.Unknown }, CqrsModule.Self ); _chaosKitty.Meow(evt.OperationId); await _riskControlRepository.SaveAsync(aggregate); _chaosKitty.Meow(evt.OperationId); } }
private async Task Handle(OperationRejectedEvent evt, ICommandSender sender) { var aggregate = await _cashinRepository.TryGetAsync(evt.OperationId); if (aggregate == null) { // This is not a cashin operation return; } var transitionResult = aggregate.OnOperationRejected(evt.Message); if (transitionResult.ShouldSaveAggregate()) { await _cashinRepository.SaveAsync(aggregate); } if (transitionResult.ShouldSendCommands()) { sender.SendCommand ( new ReleaseDepositWalletLockCommand { OperationId = aggregate.OperationId, BlockchainType = aggregate.BlockchainType, BlockchainAssetId = aggregate.BlockchainAssetId, DepositWalletAddress = aggregate.DepositWalletAddress }, Self ); _chaosKitty.Meow(aggregate.OperationId); } }
public async Task <Unit> Handle(CreateQuizOperationEvent request, CancellationToken cancellationToken) { var exist = _operationRepository.GetAsync(request.OperationId); if (exist == null) { var rejectectedEvent = new OperationRejectedEvent { Id = request.OperationId, Reason = "There is an operations with such Id" }; await _busPublisher.PublishAsync(rejectectedEvent); return(Unit.Value); } //the operation contains only one step - a quiz creating var quizId = Guid.NewGuid(); var operation = new Operation { Id = request.OperationId, State = OperationState.Pending, Steps = new List <Step> { new Step { Id = Guid.NewGuid(), EntityId = quizId, RejectEventName = typeof(DeleteQuizEvent).Name, State = OperationState.Pending } } }; await _operationRepository.AddAsync(operation); //Guid for a new Quiz will be generated by Mapper var createQuizEvent = _mapper.Map <CreateQuizEvent>(request); createQuizEvent.Id = quizId; await _busPublisher.PublishAsync(createQuizEvent); return(Unit.Value); }