public static TransactionHistoryEntity Create(FeeCollectedOperationDto operation)
 {
     return(new TransactionHistoryEntity
     {
         CustomerId = operation.CustomerId,
         Timestamp = operation.Timestamp,
         Type = OperationType.FeeCollected.ToString(),
         AssetSymbol = operation.AssetSymbol,
         TransactionId = operation.OperationId
     });
 }
 public static FeeCollectedOperationEntity Create(FeeCollectedOperationDto operation)
 {
     return(new FeeCollectedOperationEntity
     {
         Id = operation.OperationId,
         Fee = operation.Fee,
         CustomerId = operation.CustomerId,
         Timestamp = operation.Timestamp,
         AssetSymbol = operation.AssetSymbol,
         Reason = operation.Reason,
     });
 }
        public async Task ProcessFeeCollectedAsync(FeeCollectedOperationDto feeCollectedOperation)
        {
            var isValid = ValidateFeeCollectedOperation(feeCollectedOperation);

            if (!isValid)
            {
                return;
            }

            feeCollectedOperation.AssetSymbol = _tokenSymbol;
            feeCollectedOperation.Timestamp   = DateTime.UtcNow;

            await _feeCollectedOperationsRepository.AddAsync(feeCollectedOperation);
        }
Esempio n. 4
0
        protected override async Task ProcessMessageAsync(FeeCollectedEvent message)
        {
            var dto = new FeeCollectedOperationDto
            {
                CustomerId  = message.CustomerId,
                Fee         = message.Amount,
                OperationId = message.EventId,
                Reason      = (FeeCollectionReason)message.Reason
            };

            await _operationsService.ProcessFeeCollectedAsync(dto);

            _log.Info("Processed FeeCollectedEvent", message);
        }
Esempio n. 5
0
        public async Task AddAsync(FeeCollectedOperationDto operation)
        {
            using (var context = _contextFactory.CreateDataContext())
            {
                var entity = FeeCollectedOperationEntity.Create(operation);

                var historyEntity = TransactionHistoryEntity.Create(operation);

                context.FeeCollectedOperations.Add(entity);

                context.TransactionHistories.Add(historyEntity);

                await context.SaveChangesAsync();
            }
        }
        private bool ValidateFeeCollectedOperation(FeeCollectedOperationDto feeCollectedOperation)
        {
            bool isValid = true;

            if (feeCollectedOperation.Fee < 0)
            {
                isValid = false;
                _log.Warning("Fee Collected operation with negative fee amount", context: feeCollectedOperation);
            }

            if (string.IsNullOrEmpty(feeCollectedOperation.CustomerId))
            {
                isValid = false;
                _log.Warning("Fee Collected operation without customer id", context: feeCollectedOperation);
            }

            if (string.IsNullOrEmpty(feeCollectedOperation.OperationId))
            {
                isValid = false;
                _log.Warning("Fee Collected operation without operationId", context: feeCollectedOperation);
            }

            return(isValid);
        }