public IActionResult Delete(string codEmpresa, long codCentroCusto) { var command = new ExcluirCentroCustoCommand(codEmpresa, codCentroCusto); var result = _handler.Handle(command); return(Response(result, _handler.Notifications)); }
public ICommandResult Handle(ExcluirCentroCustoCommand command) { //Verificar se o Centro de Custo existe var registro = _centroCustoRepository.Buscar(c => c.CodEmpresa == command.CodEmpresa && c.CodCentroCusto == command.CodCentroCusto).FirstOrDefault(); if (registro == null) { return(new CommandResult(false, "Não foi possível realizar esta operação. O registro informado não existe")); } if (registro.OrigemLegado == true) { return(new CommandResult(false, "Não é permitido a exclusão deste registro. Pertence a um sistema legado")); } //Auditoria //var auditoria = new LogAuditoria("Cadastro", registro.GetType().Name, EAcao.Excluir, registro.GetType().Namespace, JsonConvert.SerializeObject(registro)); // Agrupar as Validações AddNotifications(registro); // Checar as notificações if (Invalid) { return(new CommandResult(false, "Não foi possível realizar esta operação")); } // Salvar as Informações _centroCustoRepository.Excluir(command.CodEmpresa, command.CodCentroCusto); //_auditoriaRepository.Adicionar(auditoria); // Retornar informações return(new CommandResult(true, "Operação realizada com sucesso")); }