Exemplo n.º 1
0
 public async Task <Operation> SetLoan(Operation operation, Guid loanId, CancellationToken cancellationToken)
 {
     if (await _validator.Validate(OperationType.Loan, loanId, operation.UserId, cancellationToken))
     {
         operation.SetDocument(OperationType.Loan, loanId);
     }
     return(operation);
 }
Exemplo n.º 2
0
        public async Task <Operation> Create(
            Guid id,
            Guid guildId,
            Guid userId,
            Guid?documentId,
            Decimal amount,
            OperationType type,
            String description,
            Guid?parentOperationId,
            CancellationToken cancellationToken)
        {
            if (Guid.Empty == id)
            {
                throw new ArgumentException("OperationCreator: Value mustn't be empty", nameof(id));
            }
            if (Guid.Empty == guildId)
            {
                throw new ArgumentException("OperationCreator: Value mustn't be empty", nameof(guildId));
            }
            if (Guid.Empty == userId)
            {
                throw new ArgumentException("OperationCreator: Value mustn't be empty", nameof(userId));
            }
            if (amount == 0m)
            {
                throw new ArgumentException("OperationCreator: Value mustn't be zero", nameof(amount));
            }

            if (type == OperationType.Tax && amount > 0)
            {
                amount = -1.0m * amount;
            }

            var operation = new Operation(
                id,
                guildId,
                userId,
                amount,
                parentOperationId,
                description?.Trim());

            if (documentId != null)
            {
                await _validator.Validate(type, documentId.Value, userId, cancellationToken);

                operation.SetDocument(type, documentId.Value);
            }
            else
            {
                operation.SetOperationWithoutDocument(type);
            }

            return(operation);
        }