public async Task <string> GuardarLogAuditoria(DateTime Fecha, string Usuario, string Tabla, string Clave, string Accion)
        {
            try
            {
                //consultar la ip
                var    ip1 = GetLocalIPv4(NetworkInterfaceType.Ethernet).FirstOrDefault();
                var    ip2 = GetLocalIPv4(NetworkInterfaceType.Wireless80211).FirstOrDefault();
                String ip  = string.Empty;
                if (string.IsNullOrEmpty(ip1))
                {
                    ip = ip2;
                }
                else
                {
                    ip = ip1;
                }

                //string codigoCompania = _context.Empleado.SingleOrDefault(u => u.NombreUsuario == Usuario).CodigoCompania;

                LogAuditoria logAuditoria = new LogAuditoria();
                //logAuditoria.CodigoCompania = codigoCompania;

                //Fecha
                logAuditoria.Fecha = Fecha;

                //usuario
                if (string.IsNullOrEmpty(Usuario))
                {
                    logAuditoria.Usuario = Environment.UserName;
                }
                else if ((!string.IsNullOrEmpty(Usuario)) && (Usuario.Length > 32))
                {
                    logAuditoria.Usuario = Usuario.Substring(0, 32);
                }
                else
                {
                    logAuditoria.Usuario = Usuario;
                }

                //tabla
                if ((!string.IsNullOrEmpty(Tabla)) && (Tabla.Length > 32))
                {
                    Tabla = Tabla.Substring(0, 32);
                }

                logAuditoria.Tabla = Tabla;
                logAuditoria.Clave = Clave;
                //accion
                logAuditoria.Accion      = string.IsNullOrEmpty(Accion) ? "A" : Accion.Substring(0, 1);
                logAuditoria.DireccionIp = ip;
                _context.LogAuditoria.Add(logAuditoria);
                await _context.SaveChangesAsync();

                return("Save");
            }
            catch (Exception e)
            {
                return(e.Message.ToString());
            }
        }
Ejemplo n.º 2
0
        public async Task <Guid> SaveAuditAsync(string identifier, string message, string detail, LogSourceEnum source, LogTypeEnum type)
        {
            var model = new LogAuditoria(identifier, message, detail, source, type);
            await _logAudit.AddAsync(model);

            return(model.Id);
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <long> > CadastraLogAuditoria(LogAuditoria logAuditoria)
        {
            try
            {
                LogAuditoria novaAuditoria = new LogAuditoria()
                {
                    Id = (listaAuditoria.Max(l => l.Id) + 1), IdTransacao = logAuditoria.IdTransacao, IdPedido = logAuditoria.IdPedido, LoginUsuario = logAuditoria.LoginUsuario, Data = logAuditoria.Data
                };
                listaAuditoria.Add(novaAuditoria);

                return(novaAuditoria.Id);
            }
            catch (Exception)
            {
                return(0);
            }
        }
Ejemplo n.º 4
0
        public ICommandResult Handle(AdicionarCentroCustoCommand command)
        {
            // Fail Fast Validations
            command.Validar();
            if (command.Invalid)
            {
                AddNotifications(command);
                return(new CommandResult(false, "Não foi possível adicionar a empresa"));
            }



            //Validar Empresa
            var empresa = _empresaRepository.Buscar(e => e.CodEmpresa == command.CodEmpresa && e.IdSituacao == (int)ESituacao.Ativo).FirstOrDefault();

            if (empresa == null)
            {
                AddNotification("Cod Empresa", "O Código de Empresa informado não existe ou Empresa não está ativa");

                return(new CommandResult(false, "Não foi possível adicionar o registro"));
            }



            //Validar Grupo
            var grupo = _grupoRepository.Buscar(g => g.Codigo == command.CodGrupo).FirstOrDefault();

            if (grupo == null)
            {
                AddNotification("Cod Grupo", "O Código de Grupo informado não existe");

                return(new CommandResult(false, "Não foi possível adicionar o registro"));
            }



            //Validar Classe
            var classe = _classeContabilRepository.Buscar(c => c.Codigo == command.CodClasse).FirstOrDefault();

            if (classe == null)
            {
                AddNotification("Cod Classe", "O Código de Classe informado não existe");

                return(new CommandResult(false, "Não foi possível adicionar o registro"));
            }



            //Validar TipoBloqueio
            var tipoBloqueio = _tipoBloqueioRepository.Buscar(t => t.Codigo == command.CodTipoBloqueio).FirstOrDefault();

            if (tipoBloqueio == null)
            {
                AddNotification("Tipo Bloqueio", "O Tipo de Bloqueio informado não existe");

                return(new CommandResult(false, "Não foi possível adicionar o registro"));
            }



            //Validar Centro de Custo
            var centroCusto = _centroCustoRepository.Buscar(c => c.CodEmpresa == command.CodEmpresa && c.CodCentroCusto == command.CodCentroCusto).FirstOrDefault();

            if (centroCusto != null)
            {
                AddNotification("Duplicidade", "O registro já esta cadastrado na base");

                return(new CommandResult(false, "Não foi possível adicionar o registro"));
            }



            //Gerar as Entidades
            var centroCustoModel = new CentroCusto(command.CodEmpresa, command.CodCentroCusto, command.NomeCentroCusto, command.CodGrupo, command.CodClasse, command.CodTipoBloqueio);


            //Auditoria
            var auditoria = new LogAuditoria("Cadastro", centroCustoModel.GetType().Name, EAcao.Adicionar, centroCustoModel.GetType().Namespace, JsonConvert.SerializeObject(command), UserIdLogado);



            // Relacionamentos (Se houver)



            // Agrupar as Validações
            AddNotifications(centroCustoModel);



            // Checar as notificações
            if (Invalid)
            {
                return(new CommandResult(false, "Não foi possível realizar esta operação"));
            }


            // Salvar as Informações
            _centroCustoRepository.Adicionar(centroCustoModel);



            _logAuditoriaRepository.Adicionar(auditoria);



            // Enviar E-mail de boas vindas (Se houver necessidade)



            // Retornar informações
            return(new CommandResult(true, "Operação realizada com sucesso"));
        }
Ejemplo n.º 5
0
        public ICommandResult Handle(AdicionarEmpresaCommand command)
        {
            // Fail Fast Validations
            command.Validar();
            if (command.Invalid)
            {
                AddNotifications(command);
                return(new CommandResult(false, "Não foi possível adicionar a empresa"));
            }


            //Verificar se o Codigo ou Nome informado já está em Uso
            if (_empresaRepository.ChecarSeEmpresaExiste((int)EAcao.Adicionar, command.CodEmpresa, command.Nome, command.Cnpj))
            {
                AddNotification("Código/Nome/CNPJ", "O Código, Nome ou CNPJ já estão em uso");
            }


            //Gerar os VOs (Se houver)
            var cnpj = new CNPJ(command.Cnpj);

            if (cnpj.Invalid)
            {
                AddNotifications(cnpj);
                return(new CommandResult(false, "Não foi possível adicionar a empresa"));
            }

            //Gerar as Entidades
            var empresa = new Empresa(command.CodEmpresa, command.Nome, cnpj, command.IdSituacao);


            //Auditoria
            var auditoria = new LogAuditoria("Cadastro", empresa.GetType().Name, EAcao.Adicionar, empresa.GetType().Namespace, JsonConvert.SerializeObject(command), UserIdLogado);



            // Relacionamentos (Se houver)



            // Agrupar as Validações
            AddNotifications(empresa);



            // Checar as notificações
            if (Invalid)
            {
                return(new CommandResult(false, "Não foi possível realizar esta operação"));
            }


            // Salvar as Informações
            _empresaRepository.Adicionar(empresa);



            _logAuditoriaRepository.Adicionar(auditoria);



            // Enviar E-mail de boas vindas (Se houver necessidade)



            // Retornar informações
            return(new CommandResult(true, "Operação realizada com sucesso"));
        }
Ejemplo n.º 6
0
        public async Task <Guid> SaveAuditAsync(LogAuditoria log)
        {
            await _logAudit.AddAsync(log);

            return(log.Id);
        }