예제 #1
0
        protected IActionResult ResponseWithFirstNotification()
        {
            if (_domainNotification.HasNotifications())
            {
                return(BadRequest(_domainNotification.GetFirstNotification()));
            }

            return(Ok());
        }
예제 #2
0
        public BaseResponse Commit()
        {
            var response = new BaseResponse();

            if (_notifications.HasNotifications())
            {
                response.Fail();
                return(response);
            }

            try
            {
                var saveResult = _unitOfWork.Save();
                if (saveResult > 0)
                {
                    return(response);
                }

                var errorMessage = "Erro ao salvar os dados no banco";
                _bus.RaiseEvent(new DomainNotification("Commit", errorMessage));
                response.Fail(errorMessage);
            }
            catch (Exception e)
            {
                response.Fail(e.Message);
            }

            return(response);
        }
예제 #3
0
 public IHttpActionResult Response(object result)
 {
     if (!_notifications.HasNotifications())
     {
         try
         {
             _unitOfWork.Commit();
             return(Ok(new
             {
                 success = true,
                 data = result
             }));
         }
         catch
         {
             // Logar o erro (Elmah)
             return(Content(HttpStatusCode.BadRequest, new
             {
                 success = false,
                 errors = new[] { "Ocorreu uma falha interna no servidor." }
             }));
         }
     }
     else
     {
         return(Content(HttpStatusCode.BadRequest, new
         {
             success = false,
             errors = _notifications.Notify().Select(n => n.Value)
         }));
     }
 }
예제 #4
0
        protected bool Commit()
        {
            if (_notifications.HasNotifications())
            {
                return(false);
            }
            var commandResponse = _uow.Commit();

            if (commandResponse.Success)
            {
                return(true);
            }

            _bus.RaiseEvent(new DomainNotification("Commit", "Ocorreu um erro ao salvar os dados no banco."));
            return(false);
        }
예제 #5
0
        public ActionResult Post(LancamentosViewModel collection)
        {
            if (!ModelState.IsValid)
            {
                return(NotFound(collection));
            }
            context.Lancamentos(collection);

            if (!_notifications.HasNotifications())
            {
                return(Ok(collection));
            }
            else
            {
                return(NotFound(_notifications));
            }
        }
        public bool Commit()
        {
            if (_notifications.HasNotifications())
            {
                return(false);
            }
            //commit
            //if (commandResponse.Success) return true;

            _bus.RaiseEvent(new DomainNotification("Commit", "Tivemos um problema salbando seus dados."));

            return(false);
        }
        protected IActionResult GetResponse(object result)
        {
            if (_notifications != null && _notifications.HasNotifications())
            {
                return(BadRequest(_notifications.GetNotifications().Select(n => n.Value)));
            }

            if (result == null)
            {
                return(Ok());
            }

            return(Ok(result));
        }
예제 #8
0
        public bool Commit()
        {
            if (_notifications.HasNotifications())
            {
                return(false);
            }
            if (_unitOfWork.Commit())
            {
                return(true);
            }

            _bus.RaiseEvent(new Core.Notifications.DomainNotification("Commit", "Não foi possivel realizar a operação."));
            return(false);
        }
예제 #9
0
        public void Handle(RegistrarNoticiaCommand message)
        {
            var noticia = Noticia.NoticiaFactory.NovaNoticiaCompleta(message.Id, message.Titulo, message.Subtitulo, message.Descricao, message.Autor);

            var noticiaExistente = _noticiaRepository.Buscar(n => n.Titulo == noticia.Titulo);

            if (noticiaExistente.Any())
            {
                _bus.RaiseEvent(new DomainNotification(message.MessageType, "Titulo já existente"));
            }

            if (!NoticiaValido(noticia))
            {
                return;
            }

            if (_notifications.HasNotifications())
            {
                return;
            }
            _noticiaRepository.Adicionar(noticia);

            _bus.RaiseEvent(new NoticiaRegistradaEvent(message.Id, message.Titulo, message.Subtitulo, message.Descricao, message.Autor));
        }
예제 #10
0
        protected bool Commit()
        {
            if (_notifications.HasNotifications())
            {
                return(false);
            }

            if (_uow.Commit())
            {
                return(true);
            }

            _bus.SendEvent(new DomainNotification("Commit", "Error while saving data into database"));
            return(false);
        }
예제 #11
0
        public bool Commit()
        {
            if (_notifications.HasNotifications())
            {
                return(false);
            }
            var commandResponse = _uow.Commit();

            if (commandResponse.Success)
            {
                return(true);
            }

            return(false);
        }
예제 #12
0
        public bool Commit()
        {
            if (_notifications.HasNotifications())
            {
                return(false);
            }
            var commandResponse = _uow.Commit();

            if (commandResponse.Success)
            {
                return(true);
            }

            _bus.RaiseEvent(new DomainNotification("Commit", "We had a problem during saving your data."));
            return(false);
        }
예제 #13
0
        public bool Commit()
        {
            if (_notifications.HasNotifications())
            {
                return(false);
            }
            var commandResponse = _uow.Commit();

            if (commandResponse.Success)
            {
                return(true);
            }

            _bus.RaizeEvent(new DomainNotification("Commit", "Algum erro ocorreu ao atualizar o banco de dados"));
            return(false);
        }
예제 #14
0
        protected bool Commit()
        {
            if (_notifications.HasNotifications())
            {
                return(false);
            }
            var commandResponse = _uow.Commit();

            if (commandResponse.Success)
            {
                return(true);
            }
            //TODO: Translate the texts for all languages
            _bus.RaiseEvent(new DomainDotification("Commit", "Ocorreu um erro ao salvar os dados no banco"));
            return(false);
        }
예제 #15
0
        protected bool Commit()
        {
            if (_notifications.HasNotifications())
            {
                return(false);
            }

            var commandResponse = _unitOfWork.Commit();

            if (commandResponse.Success)
            {
                return(true);
            }

            _bus.RaiseEvent(new DomainNotification("Commit", "There was an error saving the data."));
            return(false);
        }
예제 #16
0
        protected bool Commit()
        {
            if (_notifications.HasNotifications())
            {
                return(false);
            }
            var commandResponse = _uow.Commit();

            if (commandResponse.Success)
            {
                return(true);
            }

            _bus.RaiseEvent(new DomainNotification("Commit", "Não foi possível salvar."));

            return(false);
        }
        protected bool Commit()
        {
            if (_notification.HasNotifications())
            {
                return(false);
            }

            var commandResponse = _uow.Commit();

            if (commandResponse.Success)
            {
                return(true);
            }

            _bus.RaiseEvent(new DomainNotification("Commit", "Error on saving the data."));
            return(false);
        }
예제 #18
0
        protected bool Commit()
        {
            if (_DomainNotificationHandler.HasNotifications())
            {
                return(false);
            }
            var commandResponse = _unitOfWork.Commit();

            if (commandResponse.Success)
            {
                return(true);
            }

            Console.WriteLine("Ocorreu um erro ao salvar os dados no banco");
            _Bus.RaiseEvent(new DomainNotification("Commit", "Ocorreu um erro ao salvar os dados no banco"));

            return(false);
        }
예제 #19
0
        protected bool Commit()
        {
            // Se já houver erro não continua pro commit
            if (_notifications.HasNotifications())
            {
                return(false);
            }

            var commandResponse = _uow.Commit();

            if (commandResponse.Success)
            {
                return(true);
            }

            _bus.RaiseEvent(new DomainNotification("Commit", "Erro ao salvar dados no banco"));
            return(false);
        }
예제 #20
0
        protected bool Commit()
        {
            if (_notifications.HasNotifications())
            {
                return(false);
            }
            // TODO: Validar se há alguma validcao de negócio com erro!
            var commandResponse = _uow.Commit();

            if (commandResponse.Success)
            {
                return(true);
            }

            Console.WriteLine("Ocorreu um erro ao salvar os dados no banco");
            _bus.RaiseEvent(new DomainNotification("Commit", "Ocorreu um erro ao salvar os dados no banco"));
            return(false);
        }
예제 #21
0
        /// <summary>
        /// Commits this instance.
        /// </summary>
        /// <returns></returns>
        public bool Commit()
        {
            if (_notifications.HasNotifications())
            {
                return(false);
            }
            var commandResponse = _uow.Commit();

            if (commandResponse.Success)
            {
                return(true);
            }

            _bus.RaiseEvent(new DomainNotification(
                                Const.CONST_DOMAIN_NOTIFICATION_KEY_COMMIT,
                                Const.CONST_DOMAIN_NOTIFICATION_KEY_COMMIT_VALUE));
            return(false);
        }
예제 #22
0
        protected bool Commit()
        {
            // TODO: Check business validations !
            if (_domainNotificationHandler.HasNotifications())
            {
                return(false);
            }

            var commandResponse = _unitOfWork.Commit();

            if (commandResponse.Success)
            {
                return(true);
            }

            Console.WriteLine("Error when saving data");
            _bus.RaiseEvent(new DomainNotification("Commit", "Error when saving data"));
            return(false);
        }
예제 #23
0
        protected bool Commit()
        {
            //TODO: Validate whether there are some error business validation or not.

            if (_notifications.HasNotifications())
            {
                return(false);
            }
            var commandResponse = _uow.Commit();

            if (commandResponse.Success)
            {
                return(true);
            }

            Console.WriteLine("An error has occured saving data");
            _bus.RaiseEvent(new DomainNotification("Commit", "An error has occured saving data"));
            return(false);
        }
예제 #24
0
        public bool Commit()
        {
            if (_notifications.HasNotifications())
            {
                return(false);
            }

            var commandResponse = _uow.Commit();

            if (commandResponse.Success)
            {
                return(true);
            }

            Console.WriteLine("FAZER ALGO P VALIDAR O ERRO");
            _bus.RaiseEvent(new DomainNotification("Commit", "Ocorreu um erro ao salvar os dados no banco"));

            return(false);
        }
예제 #25
0
        protected bool Commit()
        {
            // TODO: há agluma validação de negocio com erro
            if (_notifications.HasNotifications())
            {
                return(false);
            }

            var commandResponse = _uow.Commit();

            if (commandResponse.Success)
            {
                return(true);
            }

            Console.WriteLine("Erro ao salvar");
            _bus.RaiseEvent(new DomainNotification("Commmit", "Erro ao salvar"));

            return(false);
        }
예제 #26
0
        //CreateReponse always check for Domain Notifications (errors) before send results
        //This will secure that the application never will deliver wrong or incomplete data
        //DomainNotificationHandler notifications are filled on the AppServices operations
        protected IActionResult CreateResponse(object result = null, HttpStatusCode statusCode = HttpStatusCode.OK)
        {
            if (_domainNotificationHandler.HasNotifications())
            {
                return(BadRequest(new
                {
                    success = false,
                    result = "Ocorreu um erro ao retornar os resultados.",
                    data = _domainNotificationHandler
                           .GetNotifications()
                }));
            }

            return(StatusCode((int)statusCode, new
            {
                success = true,
                result = "A operação foi concluída com sucesso.",
                data = result
            }));
        }
예제 #27
0
        protected bool Commit()
        {
            //TODO: validar se a há alguma validacao de negocio com erro!
            //se houver nao entra em commit
            if (_notifications.HasNotifications())
            {
                return(false);
            }


            var commandResponse = _unitOfWork.Commit();

            if (commandResponse.Success)
            {
                return(true);
            }

            Console.WriteLine("Erro ao salvar dados no banco");
            _bus.RiseEvent(new DomainNotification("Commit", "Erro ao salvar dados no banco"));
            return(false);
        }
예제 #28
0
        protected IActionResult CreateResponse(object result = null, HttpStatusCode statusCode = HttpStatusCode.OK)
        {
            if (_domainNotificationHandler.HasNotifications())
            {
                _logger.LogWarning("Retornando resposta do Controller: BadRequest devido à {notifications}.", _domainNotificationHandler.GetNotifications());

                return(BadRequest(new
                {
                    success = false,
                    result = "Ocorreu um erro ao retornar os resultados.",
                    data = _domainNotificationHandler
                           .GetNotifications()
                }));
            }

            _logger.LogInformation("Retornando resposta do Controller: Operação concluída com sucesso, dados retornados: {data}.", result);

            return(StatusCode((int)statusCode, new
            {
                success = true,
                result = "A operação foi concluída com sucesso.",
                data = result
            }));
        }
예제 #29
0
        public async Task <bool> CommitAsync()
        {
            if (!_notificationHandler.HasNotifications())
            {
                foreach (var entry in ChangeTracker.Entries().Where(entry => entry.Entity.GetType().GetProperty("DataCriacao") != null))
                {
                    if (entry.State == EntityState.Added)
                    {
                        entry.Property("DataCriacao").CurrentValue = DateTime.Now;
                    }

                    if (entry.State == EntityState.Modified)
                    {
                        entry.Property("DataCriacao").IsModified = false;
                    }
                }

                var sucesso = await base.SaveChangesAsync() > 0;

                //if (sucesso) await _mediatorHandler.PublicarEventos(this);
                return(sucesso);
            }
            return(false);
        }
예제 #30
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);
        }