public ICommandResult Handle(UpdateDocumentoCommand command) { try { var servidor = _uow .GetRepository <BeneficioServidor>() .GetFirstOrDefault(predicate: x => x.Id == command.ServidorId); if (servidor != null) { var documento = _uow .GetRepository <Documento>() .GetFirstOrDefault(predicate: x => x.Id == command.DocumentoId); documento.UpdateDocumento(DateTime.Now); _uow.GetRepository <Documento>().Update(entity: documento); _uow.SaveChanges(); 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 UpdateDocumento(UpdateDocumentoCommand command) { command.Validate(); if (!command.Valid) { return(new CommandResult(success: false, message: null, data: command.Notifications)); } return(_handler.Handle(command)); }
public IActionResult Update([FromBody] UpdateDocumentoCommand command) { try { var result = _service.UpdateDocumento(command); return(Ok(result)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }