public HttpResponseMessage Post(CreateCustomer customer)
        {
            _processor.Send(customer);

            if (!ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState));
            }
            if (_notifications.HasNotifications())
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, _notifications.GetNotifications()));
            }
            return(Request.CreateResponse(HttpStatusCode.Created));
        }
 public IActionResult CreateResponse()
 {
     if (!DomainNotification.HasNotifications())
     {
         return(Ok(EnvelopResult.Ok()));
     }
     return(BadRequest(EnvelopResult.Fail(DomainNotification.Notify())));
 }
Example #3
0
        public void Handle(CreateCustomer command)

        {
            ValidateCommand(command);
            var exists = false;

            if (EmailExists(command.Email))
            {
                AddNotification(command.Action, "The customer e-mail has already been taken.");
                exists = true;
            }
            if (exists)
            {
                return;
            }

            var idAdress   = Guid.NewGuid();
            var idCustomer = Guid.NewGuid();


            if (_notifications.HasNotifications())
            {
                return;
            }
            AddAddress(command, idAdress);
            AddCustomer(command, idAdress, idCustomer);

            var action = "Customer Created";

            Commit(idCustomer, command, "Customer Created");
        }
Example #4
0
        protected bool Commit()
        {
            if (_notifications.HasNotifications())
            {
                return(false);
            }
            var commandResponse = _unitOfWork.Commit();

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

            _notifications.AddNotification(new Notification("Commit", "Ocorreu um erro ao salvar os dados no banco"));
            return(false);
        }
Example #5
0
        protected void Commit(Event evet)
        {
            if (_notifications.HasNotifications())
            {
                return;
            }
            if (_architectureContext.SaveChanges() > 0)
            {
                var anterior = _eventRepository.GetLastEvent(evet.AggregateId);
                var objJson  = anterior != null
                    ? ReadToObject(((StoredEvent)anterior).Data, ((StoredEvent)anterior).Assembly)
                    : null;

                _eventRepository.Save(evet, objJson);
            }
            else
            {
                AddNotification(new DomainNotification("Commit", "We had a problem during saving your data."));
            }
        }
 protected void Commit(Event evet)
 {
     if (_notifications.HasNotifications())
     {
         return;
     }
     if (_architectureContext.SaveChanges() > 0)
     {
         _eventRepository.Save(evet);
     }
     else
     {
         AddNotification(new DomainNotification("Commit", "We had a problem during saving your data."));
     }
 }
Example #7
0
        public async Task <bool> CommitAsync()
        {
            if (Notifications.HasNotifications())
            {
                return(false);
            }

            if (await Uow.SaveChangesAsync())
            {
                return(true);
            }

            Notifications.Handle(new Notification("Ocorreu um erro ao salvar os dados"));

            return(false);
        }
Example #8
0
 public bool IsValidOperation()
 {
     return(!_notifications.HasNotifications());
 }
Example #9
0
 public bool InvalidTransaction()
 {
     return(_notifications.HasNotifications());
 }
Example #10
0
 protected bool OperacaoValida()
 {
     return(!_notifications.HasNotifications());
 }