Exemplo n.º 1
0
        public Task <bool> Handle(UpdateCondominium request, CancellationToken cancellationToken)
        {
            var currentCondominium = _condominiumRepository.FindById(request.Id);

            if (currentCondominium == null)
            {
                Mediator.RaiseNotification(new DomainNotification(nameof(Condominium), "Condomínio não existe", NotificationType.Error));

                return(Task.FromResult(false));
            }

            var address = new AddressInfo(request.AddressStreet, request.AddressNumber, request.AddressComplement, request.AddressNeighbourhood, request.AddressCity, request.AddressState, request.AddressZipCode);

            currentCondominium.UpdateCondominium(User.GetUserId(), request.Name, address);

            if (!IsAValidCondominium(currentCondominium))
            {
                return(Task.FromResult(false));
            }

            _condominiumRepository.Update(currentCondominium);

            if (Commit())
            {
                Mediator.RaiseNotification(new DomainNotification(nameof(Condominium), "Operação realizada com sucesso", NotificationType.Info));

                return(Task.FromResult(true));
            }

            Mediator.RaiseNotification(new DomainNotification(nameof(Condominium), "Erro ao realizar a operação", NotificationType.Error));

            return(Task.FromResult(false));
        }
 public ActionResult Edit([Bind(Include = "Id,SubsidiaryId,Code,Name,Address")] CondominiumViewModel condominium)
 {
     if (ModelState.IsValid)
     {
         _condominiumRepo.Update(_mapCondominiumMV2Condominium.Run(condominium));
         return(RedirectToAction("Index"));
     }
     return(View(condominium));
 }
Exemplo n.º 3
0
        public ICommandResult Handle(UpdateCondominiumCommand command)
        {
            // Fail Fast Validation
            command.Validate();
            if (command.Invalid)
            {
                return(new GenericCommandResult(false, "Ops, erro ao atualizar condomínio.", command.Notifications));
            }

            // Hidrata condomínio
            var condominium = _repository.GetById(command.Id, command.User);

            if (condominium == null)
            {
                return(new GenericCommandResult(false, "Ops, erro ao atualizar condomínio.", command.Id));
            }

            condominium.Update(command.Name, command.Street, command.Number, command.Neighborhood, command.City, command.State, command.Country, command.ZipCode);

            try
            {
                // Atualiza Condomínio
                _repository.Update(condominium);
            }
            catch (Exception ex)
            {
                return(new GenericCommandResult(false, "Erro inesperado!", ex.Message));
            }

            var condominiumResult = new CondominiumCommandResult
            {
                City         = condominium.City,
                Country      = condominium.Country,
                Name         = condominium.Name,
                Neighborhood = condominium.Neighborhood,
                Number       = condominium.Number,
                State        = condominium.State,
                Street       = condominium.Street
            };

            return(new GenericCommandResult(true, "Condomínio atualizado com sucesso!", condominiumResult));
        }
Exemplo n.º 4
0
 public void Update(Condominium entity)
 {
     _condominiumRepository.Update(entity);
 }