Exemplo n.º 1
0
        protected ValidationResult Validate <T, TValidation>(T command, TValidation validation) where T : CommandBase where TValidation : IValidation <T>
        {
            var result = validation.Validate(command);

            foreach (var validationMessage in result.Messages)
            {
                _notifications.Handle(new DomainNotification(validationMessage.Type.ToString(), validationMessage.Message));
            }
            return(result);
        }
Exemplo n.º 2
0
 protected void NotifyValidationErrors(ValidationResult validationResult)
 {
     foreach (var error in validationResult.Errors)
     {
         _notifications.Handle(new DomainNotification(error.PropertyName, error.ErrorMessage),
                               CancellationToken.None);
     }
 }
Exemplo n.º 3
0
        public async Task <bool> CommitAsync()
        {
            var result = (await _context.SaveChangesAsync()) > 0;

            if (!result)
            {
                _notification.Handle(new DomainNotification(string.Empty, "an error occurred"));
            }

            return(result);
        }
Exemplo n.º 4
0
        public async Task <Entities.Payment> CreateAsync(decimal value, int installments, int debitAccountNumber, int creditAccountNumber)
        {
            #region Verifica se as contas existem
            var debitAccount = (await _unitOfWork
                                .CheckingAccountRepository
                                .ListAsync(new CheckingAccountFilterSpecification(debitAccountNumber)))
                               .FirstOrDefault();

            if (debitAccount == null)
            {
                _notifications.Handle(new DomainNotification(string.Empty, "Debit Account not found"));
            }

            var creditAccount = (await _unitOfWork
                                 .CheckingAccountRepository
                                 .ListAsync(new CheckingAccountFilterSpecification(creditAccountNumber)))
                                .FirstOrDefault();

            if (debitAccount == null)
            {
                _notifications.Handle(new DomainNotification(string.Empty, "Credit Account not found"));
            }

            if (_notifications.HasNotifications())
            {
                return(await Task.FromResult <Entities.Payment>(null));
            }
            #endregion

            #region Calculas as taxas
            var netValue = CalculateTax(value, installments);
            #endregion

            #region Verifica o saldo da conta de débito
            if (debitAccount.Balance < netValue)
            {
                _notifications.Handle(new DomainNotification(string.Empty, "The debit account is not enough"));
            }
            #endregion

            #region Insere os lançamentos
            var debitEntry = new Entry
            {
                CheckingAccountNumber = debitAccount.Number,
                Type  = "D",
                Value = netValue
            };

            var creditEntry = new Entry
            {
                CheckingAccountNumber = creditAccount.Number,
                Type  = "C",
                Value = netValue
            };
            #endregion

            #region Criação do pagamento
            var payment = new Domain.Entities.Payment
            {
                GrossValue          = value,
                NetValue            = netValue,
                Installments        = installments,
                CreditAccountNumber = creditAccount.Number,
                DebitAccountNumber  = debitAccount.Number
            };
            #endregion

            #region Atualiza o saldo das contas
            debitAccount.Balance  -= netValue;
            creditAccount.Balance += netValue;
            #endregion

            #region Commit
            _unitOfWork.EntryRepository.Add(debitEntry);
            _unitOfWork.EntryRepository.Add(creditEntry);
            _unitOfWork.PaymentRepository.Add(payment);
            _unitOfWork.CheckingAccountRepository.Update(debitAccount);
            _unitOfWork.CheckingAccountRepository.Update(creditAccount);

            if (!(await _unitOfWork.CommitAsync()))
            {
                return(await Task.FromResult <Entities.Payment>(null));
            }
            #endregion

            return(payment);
        }
 public async Task EnviarNotificacao(DomainNotification notification)
 {
     await _notification.Handle(notification, CancellationToken.None);
 }
 public Task Handle(DomainNotification notification, CancellationToken cancellationToken)
 {
     return(_notifications.Handle(notification, cancellationToken));
 }
Exemplo n.º 7
0
 protected void NotifyError(string code, string message)
 {
     _notifications.Handle(new DomainNotification(code, message));
 }