public override async Task <GetOperationResponse> GetOperationsForWallet(GetOperationForWalletRequest request, ServerCallContext context)
        {
            var operations = await _operationRepository.GetAsync(
                request.BlockchainId,
                request.WalletAddress,
                request.Skip,
                request.Take);

            var response = new GetOperationResponse();

            if (operations != null && operations.Any())
            {
                response.Operations.AddRange(operations.Select(x =>
                                                               new OperationResponse()
                {
                    WalletKey = new WalletKey()
                    {
                        BlockchainId      = x.Key.BlockchainId,
                        BlockchainAssetId = x.Key.BlockchainAssetId,
                        WalletAddress     = x.Key.WalletAddress
                    },
                    BalanceChange = x.BalanceChange.ToString(),
                    OperationId   = x.OperationId,
                    Block         = x.Block
                }));
            }

            return(response);
        }
Exemplo n.º 2
0
        public async Task <Unit> Handle(CreateQuizRejectedEvent request, CancellationToken cancellationToken)
        {
            var operation = await _operationRepository.GetAsync(request.OperationId);

            if (operation == null)
            {
                return(Unit.Value);
            }

            var step = operation.Steps.FirstOrDefault(i => i.EntityId == request.Id);

            if (step == null)
            {
                return(Unit.Value);
            }

            //there is no other step
            step.State                = OperationState.Rejected;
            operation.State           = OperationState.Rejected;
            operation.RejectionReason = request.Reason;
            step.RejectionReason      = request.Reason;

            await _operationRepository.UpdateAsync(operation);

            await _busPublisher.PublishAsync(new OperationRejectedEvent { Id = operation.Id, Reason = request.Reason });

            return(Unit.Value);
        }
Exemplo n.º 3
0
        public async Task <Unit> Handle(QuizCreatedEvent request, CancellationToken cancellationToken)
        {
            var operation = await _operationRepository.GetAsync(request.OperationId);

            if (operation == null)
            {
                return(Unit.Value);
            }

            var step = operation.Steps.FirstOrDefault(i => i.EntityId == request.Id);

            if (step == null)
            {
                return(Unit.Value);
            }

            step.State = OperationState.Completed;
            if (operation.Steps.All(i => i.State == OperationState.Completed))
            {
                operation.State = OperationState.Completed;
            }

            await _operationRepository.UpdateAsync(operation);

            if (operation.State == OperationState.Completed)
            {
                await _busPublisher.PublishAsync(new OperationCompletedEvent { Id = request.OperationId });
            }

            return(Unit.Value);
        }
Exemplo n.º 4
0
        public async Task <BaseResponse> EditAsync(EditOperationRequest request)
        {
            var operation = await _operationRepository.GetAsync(operation => operation.Id == request.Id);

            if (operation == null)
            {
                return(new BaseResponse("Operation is not found"));
            }

            operation.Date        = request.Date;
            operation.Description = request.Description;
            operation.Amount      = request.Amount;
            operation.CategoryId  = request.CategoryId;
            _operationRepository.Update(operation);
            await _unitOfWork.SaveChangesAsync();

            return(new BaseResponse());
        }
        public static async Task <Operation> GetOrFailAsync(this IOperationRepository repository, Guid OperationId)
        {
            var operation = await repository.GetAsync(OperationId);

            if (operation == null)
            {
                throw new Exception($"Operation with Id {OperationId} was not found");
            }
            return(operation);
        }
Exemplo n.º 6
0
        public async Task HandleAsync(OperationUpdated @event)
        {
            var operation = await _operationRepository.GetAsync(@event.RequestId);

            if (operation.HasNoValue)
            {
                return;
            }

            operation.Value.Message   = @event.Message;
            operation.Value.State     = @event.State;
            operation.Value.UpdatedAt = @event.UpdatedAt;
            await _operationRepository.UpdateAsync(operation.Value);
        }
        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);
        }
Exemplo n.º 8
0
        public async Task <IActionResult> GetOperationsAsync([FromQuery] GetOperationsRequest request)
        {
            var key        = new DepositWalletKey(request.BlockchainAssetId, request.BlockchainId, request.WalletAddress);
            var operations = await _operationRepository.GetAsync(key, request.Skip, request.Take);

            return(Ok(new GetOperationsResponse()
            {
                Operations = operations?.Select(x => new OperationResponse()
                {
                    BlockchainAssetId = x.Key.BlockchainAssetId,
                    Block = x.Block,
                    BlockchainId = x.Key.BlockchainId,
                    BalanceChange = x.BalanceChange.ToString(),
                    OperationId = x.OperationId,
                    WalletAddress = x.Key.WalletAddress,
                }).ToArray()
            }));
        }
Exemplo n.º 9
0
        public async Task AddAsync(string name, Guid categoryId, string operationName)
        {
            var category = await _categotyRepository.GetAsync(categoryId);

            //TODO: FIX :D

            //if (category == null)
            //{
            //    throw new Exception($"Category {categoryId} doesnt exist");
            //}
            var operation = await _operationRepository.GetAsync(operationName);

            if (operation == null)
            {
                throw new Exception($"Operation {operationName} doesnt exist");
            }
            var tag = new Tag(name, categoryId);

            operation.AddTag(tag);
            await _operationRepository.UpdateAsync(operation);
        }
Exemplo n.º 10
0
        public async Task <OperationDetailsDTO> GetAsync(string name)
        {
            var operation = await _operationRepository.GetAsync(name);

            return(_mapper.Map <Operation, OperationDetailsDTO>(operation));
        }
Exemplo n.º 11
0
 public async Task <Maybe <OperationDto> > GetAsync(Guid requestId) =>
 await _providerClient.GetUsingStorageAsync(_providerSettings.OperationsApiUrl,
                                            $"/operations/{requestId}", async() => await _operationRepository.GetAsync(requestId),
                                            async operation => await _operationRepository.AddAsync(operation));
Exemplo n.º 12
0
 public async Task <Maybe <Operation> > GetAsync(Guid requestId)
 => await _provider.GetAsync(
     async() => await _operationRepository.GetAsync(requestId),
     async() => await _serviceClient.GetAsync <Operation>(requestId));
Exemplo n.º 13
0
 public async Task <Maybe <Operation> > GetAsync(Guid requestId)
 => await _operationRepository.GetAsync(requestId);