Beispiel #1
0
        public ICommandResult Handle(InactivateResidentCommand command)
        {
            // Fail Fast Validation
            command.Validate();
            if (command.Invalid)
            {
                return(new GenericCommandResult(false, "Ops, erro ao inativar morador.", command.Notifications));
            }

            // Hidrata morador
            var resident = _repository.GetById(command.Id, command.User);

            if (resident == null)
            {
                return(new GenericCommandResult(false, "Ops, erro ao inativar morador.", command.Id));
            }

            resident.Inactivate();

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

            return(new GenericCommandResult(true, "Morador inativado com sucesso!", null));
        }
Beispiel #2
0
        public GenericCommandResult Inactivate(
            Guid id,
            [FromServices] ResidentHandler handler
            )
        {
            var user    = User.Claims.FirstOrDefault(x => x.Type == "user_id")?.Value;
            var command = new InactivateResidentCommand(id, user);

            return((GenericCommandResult)handler.Handle(command));
        }