Exemple #1
0
        public ICommandResult Handle(UpdateBeneficioServidorCommand command)
        {
            try
            {
                var servidor = _uow
                               .GetRepository <BeneficioServidor>()
                               .GetFirstOrDefault(predicate: x => x.Id == command.ServidorId);

                if (servidor != null)
                {
                    var setorAnterior = servidor.SetorTramitacao;

                    servidor.UpdateServidor(command.Tramitacao);
                    _uow.GetRepository <BeneficioServidor>().Update(entity: servidor);
                    _uow.SaveChanges();

                    GravarTramitacao(servidor, setorAnterior, command.Tramitacao);

                    return(new CommandResult(success: true, message: "Servidor alterado com sucesso", data: command));
                }

                return(new CommandResult(success: false, message: "Servidor nao encontrada", data: command));
            }
            catch (Exception ex)
            {
                return(new CommandResult(success: false, message: ex.Message, data: null));
            }
        }
        public ICommandResult UpdateServidor(UpdateBeneficioServidorCommand command)
        {
            command.Validate();

            if (!command.Valid)
            {
                return(new CommandResult(success: false, message: null, data: command.Notifications));
            }

            return(_handler.Handle(command));
        }
        public IActionResult Put([FromBody] UpdateBeneficioServidorCommand command)
        {
            try
            {
                var result = _servidorService.UpdateServidor(command);

                if (result.Success)
                {
                    return(Ok(result));
                }
                return(BadRequest(result));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }