public void GuardarDisContrato(DistContratos contrato) { try { using (var db = new NtLinkLocalServiceEntities()) { if (contrato.IdContrato == 0) { db.DistContratos.AddObject(contrato); } else { db.DistContratos.FirstOrDefault(p => p.IdContrato == contrato.IdContrato); db.DistContratos.ApplyCurrentValues(contrato); } db.SaveChanges(); } } catch (Exception ee) { Logger.Error(ee.Message); if (ee.InnerException != null) { Logger.Error(ee.InnerException); } } }
public List <Sistemas> GetSistemasLista(string filtro) { try { using (var db = new NtLinkLocalServiceEntities()) { if (string.IsNullOrEmpty(filtro)) { return(db.Sistemas.ToList()); } else { return(db.Sistemas.Where(p => p.RazonSocial.Contains(filtro) || p.Rfc.Contains(filtro)).ToList()); } } } catch (Exception ee) { Logger.Error(ee); if (ee.InnerException != null) { Logger.Error(ee.InnerException); } return(null); } }
public string ValidaCSD(empresa e, byte[] cert, byte[] llave, string passwordLlave) { try { using (var db = new NtLinkLocalServiceEntities()) { CreaRutas(e.RFC); string path = Path.Combine(ConfigurationManager.AppSettings["Resources"], e.RFC); if (!ValidaRfcEmisor(e.RFC, cert)) { return("El RFC del emisor no corresponde con el certificado"); } if (!ValidaCSDEmisor(cert)) { return("El Certificado no es de tipo CSD"); } string pathCer = Path.Combine(path, "Certs", "csd.cer"); string pathKey = Path.Combine(path, "Certs", "csd.key"); File.WriteAllBytes(pathCer, cert); File.WriteAllBytes(pathKey, llave); //bool result = CertUtil.CreaP12l(pathKey, pathCer, passwordLlave, Path.ChangeExtension(pathCer, ".p12")); //if (result != false) return("El Certificado CSD es correcto"); } } catch (Exception ee) { Logger.Error(ee); return(""); } return("El Password de la llave no es correcta"); }
public int GuardarPago(decimal importe, DateTime fecha, string observaciones, decimal pendiente, string referencia) { try { using (var db = new NtLinkLocalServiceEntities()) { var pago = new Pagos { Fecha = fecha, Importe = importe, Observaciones = observaciones, Referencia = referencia, Pendiente = pendiente }; db.Pagos.AddObject(pago); db.SaveChanges(); return(pago.IdPago); } } catch (Exception ee) { Logger.Error(ee); if (ee.InnerException != null) { Logger.Error(ee.InnerException); } return(-1); } }
public bool SaveList(List <vventas> lista) { try { using (var db = new NtLinkLocalServiceEntities()) { foreach (vventas ventas in lista) { vventas ventas1 = ventas; facturas f = db.facturas.Where(p => p.idVenta == ventas1.idVenta).First(); f.Cancelado = ventas.Cancelado; f.FechaPago = ventas.FechaPago; f.ReferenciaPago = ventas.ReferenciaPago; f.Vencimiento = ventas.Vencimiento; f.Proyecto = ventas.Proyecto; //_entities.facturas.ApplyCurrentValues(f); } db.SaveChanges(); } return(true); } catch (Exception ee) { Logger.Error(ee.Message); return(false); } }
public bool SaveSucursal(Sucursales sucursal) { try { if (Validar(sucursal)) { using (var db = new NtLinkLocalServiceEntities()) { if (sucursal.IdSucursal == 0) { db.Sucursales.AddObject(sucursal); } else { var y = db.Sucursales.Where(p => p.IdSucursal == sucursal.IdSucursal).FirstOrDefault(); db.Sucursales.ApplyCurrentValues(sucursal); } db.SaveChanges(); return(true); } } return(false); } catch (FaultException fe) { throw; } catch (Exception ee) { Logger.Error(ee.Message); return(false); } }
public bool SaveDatosNomina(DatosNomina datos) { try { using (var db = new NtLinkLocalServiceEntities()) { if (datos.IdDatoNomina == 0) { db.DatosNomina.AddObject(datos); } else { var y = db.DatosNomina.FirstOrDefault(p => p.IdDatoNomina == datos.IdDatoNomina); db.DatosNomina.ApplyCurrentValues(datos); } db.SaveChanges(); return(true); } } catch (FaultException fe) { throw; } catch (Exception ee) { Logger.Error(ee); if (ee.InnerException != null) { Logger.Error(ee.InnerException); } return(false); } }
public bool GuardarClientesPromotores(int idCliente, int idPromotor) { try { using (var db = new NtLinkLocalServiceEntities()) { ClientesPromotores cp = new ClientesPromotores { IdCliente = idCliente, IdPromotor = idPromotor }; db.ClientesPromotores.AddObject(cp); db.SaveChanges(); return(true); } } catch (Exception ee) { Logger.Error(ee.Message); if (ee.InnerException != null) { Logger.Error(ee.InnerException); } return(false); } }
public bool SavePaquete(Paquetes paquete) { try { using (var db = new NtLinkLocalServiceEntities()) { if (db.Paquetes.Any(p => p.Descripcion == paquete.Descripcion)) { throw new FaultException("DescripciĆ³n duplicada"); } if (paquete.IdPaquete == 0) { db.AddToPaquetes(paquete); db.SaveChanges(); } else { var pa = db.Paquetes.Where(p => p.IdPaquete == paquete.IdPaquete).FirstOrDefault(); db.Paquetes.ApplyCurrentValues(paquete); db.SaveChanges(); } return(true); } } catch (Exception ee) { Logger.Error(ee.Message); if (ee.InnerException != null) { Logger.Error(ee.InnerException); } return(false); } }
public static bool GetEmpresaMultipleRFC(string rfc) { try { //rgv using (var db = new NtLinkLocalServiceEntities()) { var emp = db.empresa.Where(p => p.RFC == rfc).ToList(); if (emp == null) { return(false); } if (emp.Count > 1) { return(true); } else { return(false); } } } catch (Exception eee) { Logger.Error(eee.Message); if (eee.InnerException != null) { Logger.Error(eee.InnerException); } return(false); } }
public List <producto> ProductSearch(string query, int idEmpresa) { try { using (var db = new NtLinkLocalServiceEntities()) { if (!string.IsNullOrEmpty(query)) { var x = db.producto.Where(p => p.IdEmpresa == idEmpresa && (p.Descripcion.ToLower().Contains(query) || p.Codigo.ToLower().Contains(query) || p.Observaciones.ToLower().Contains(query))).ToList(); return(x); } else { return(db.producto.Where(p => p.IdEmpresa == idEmpresa).ToList()); } } } catch (Exception ee) { Logger.Error(ee.Message); return(null); } }
public bool SaveComisionista(Comisionistas comisionista) { try { if (Validar(comisionista)) { using (var db = new NtLinkLocalServiceEntities()) { if (comisionista.IdComisionista == 0) { db.Comisionistas.AddObject(comisionista); } else { var y = db.Comisionistas.Where(p => p.IdComisionista == comisionista.IdComisionista).FirstOrDefault(); db.Comisionistas.ApplyCurrentValues(comisionista); } db.SaveChanges(); return(true); } } return(false); } catch (FaultException fe) { throw; } catch (Exception ee) { Logger.Error(ee.Message); return(false); } }
public static empresa GetEmpresaByUserId(string userId = null) { try { //rgv using (var db = new NtLinkLocalServiceEntities()) { usuarios_empresas ue = db.usuarios_empresas.Where(p => p.UserId == userId).FirstOrDefault(); if (ue != null) { empresa emp = db.empresa.Where(p => p.IdEmpresa == ue.IdEmpresa).FirstOrDefault(); return(emp); } return(null); } } catch (Exception eee) { Logger.Error(eee.Message); if (eee.InnerException != null) { Logger.Error(eee.InnerException); } return(null); } }
public bool SaveProducto(producto prod) { try { using (var db = new NtLinkLocalServiceEntities()) { if (prod.IdProducto == 0) { prod.Creacion = DateTime.Now; prod.Modificacion = DateTime.Now; //TODO: Buscar usuario de modificacion prod.IdUsuario = 1; db.producto.AddObject(prod); } else { var x = db.producto.FirstOrDefault(p => p.IdProducto == prod.IdProducto); prod.Creacion = x.Creacion; prod.Modificacion = DateTime.Now; db.producto.ApplyCurrentValues(prod); } db.SaveChanges(); return(true); } } catch (Exception ee) { Logger.Error(ee.Message); if (ee.InnerException != null) { Logger.Error(ee.InnerException.Message); } return(false); } }
public int Activar(ActivacionConvertidor A) { try { using (var db = new NtLinkLocalServiceEntities()) { if (A.Id == 0) { db.ActivacionConvertidor.AddObject(A); } else { db.ActivacionConvertidor.Where(p => p.Id == A.Id).FirstOrDefault(); db.ActivacionConvertidor.ApplyCurrentValues(A); } db.SaveChanges(); return(1); } } catch (Exception ee) { Logger.Error(ee); if (ee.InnerException != null) { Logger.Error(ee.InnerException); } return(0); } }
public static List <ElementoReporte> ObtenerReportePorEmisor(int mes, int anio, int idEmpresa) { var listaReporte = new List <ElementoReporte>(); using (var db = new NtLinkLocalServiceEntities()) { var emisor = db.empresa.First(e => e.IdEmpresa == idEmpresa); var elementoReporte = new ElementoReporte { Cancelados = db.vventas.Count( f => f.Fecha.Year == anio && f.RfcEmisor == emisor.RFC && f.Cancelado == 1), Cliente = emisor.RazonSocial, Rfc = emisor.RFC, Emitidos = db.TimbreWs33.Count( f => f.FechaFactura.Month == mes && f.FechaFactura.Year == anio && f.RfcEmisor.Equals(emisor.RFC, StringComparison. InvariantCultureIgnoreCase)) }; listaReporte.Add(elementoReporte); } return(listaReporte); }
public bool EliminarCliente(clientes cliente) { try { Logger.Info(cliente); using (var db = new NtLinkLocalServiceEntities()) { var existe = db.facturas.Any(p => p.idcliente == cliente.idCliente); if (existe) { throw new FaultException("El cliente tiene facturas capturadas, no es posible eliminar"); } var cli = db.clientes.FirstOrDefault(c => c.idCliente == cliente.idCliente); db.clientes.DeleteObject(cli); db.SaveChanges(); return(true); } } catch (FaultException fe) { throw; } catch (Exception ee) { Logger.Error(ee); if (ee.InnerException != null) { Logger.Error(ee.InnerException); } return(false); } }
public static Distribuidores GetDisByUserId(string userId = null) { try { using (var db = new NtLinkLocalServiceEntities()) { usuarios_distribuidor ue = db.usuarios_distribuidor.Where(p => p.UserId == userId).FirstOrDefault(); if (ue != null) { Distribuidores dis = db.Distribuidores.Where(p => p.IdDistribuidor == ue.IdDistribuidor).FirstOrDefault(); return(dis); } return(null); } } catch (Exception eee) { Logger.Error(eee.Message); if (eee.InnerException != null) { Logger.Error(eee.InnerException); } return(null); } }
//------------------------------------------------------------ public bool GetConfirmacionExiste(string confirmacion) { try { using (var db = new NtLinkLocalServiceEntities()) { var confirma = db.ConfirmacionTimbreWs33.Where(p => p.Confirmacion == confirmacion).FirstOrDefault(); if (confirma != null) { if (confirma.procesado != null) { return((bool)confirma.procesado); } else { return(false); } } else { return(false); } } } catch (Exception ee) { Logger.Error(ee.Message); return(false); } }
public bool Save(empresa e, byte[] logo) { try { using (var db = new NtLinkLocalServiceEntities()) { if (Validar(e)) { if (e.IdEmpresa == 0) { if (db.empresa.Any(l => l.RFC.Equals(e.RFC) && l.idSistema == e.idSistema)) { throw new FaultException("El RFC ya ha sido dato de alta"); } db.empresa.AddObject(e); } else { db.empresa.FirstOrDefault(p => p.IdEmpresa == e.IdEmpresa); db.empresa.ApplyCurrentValues(e); } db.SaveChanges(); CreaRutas(e.RFC); string path = Path.Combine(ConfigurationManager.AppSettings["Resources"], e.RFC); if (logo != null) { File.WriteAllBytes(Path.Combine(path, "Logo.png"), logo); } if (e.Baja != true) { throw new FaultException("El RFC ha sido dato de alta");//para que retorne algo si fue exitoso } else { throw new FaultException("El RFC ha sido dato de Baja");//para que retorne algo si fue exitoso } return(true); } return(false); } } catch (ApplicationException ae) { throw new FaultException(ae.Message); } catch (FaultException fe) { throw; } catch (Exception ee) { Logger.Error(ee.Message); if (ee.InnerException != null) { Logger.Error(ee.InnerException.Message); } return(false); } }
//------------------------------------------------------------------------------------- public bool GetByRfcMultiple(string rfc)///para verificar si existen mas de una empresa con el RFC { try { using (var db = new NtLinkLocalServiceEntities()) { var empr = db.empresa.Where(p => p.RFC == rfc).ToList(); if (empr != null) { if (empr.Count > 1) { return(true); } else { return(false); } } return(false); } } catch (Exception ee) { Logger.Error(ee.Message); if (ee.InnerException != null) { Logger.Error(ee.InnerException); } return(false); } }
public empresa GetByRfc(string rfc) { try { using (var db = new NtLinkLocalServiceEntities()) { var empr = db.empresa.FirstOrDefault(p => p.RFC == rfc); if (empr != null) { string path = Path.Combine(ConfigurationManager.AppSettings["Resources"], empr.RFC); string cer = Path.Combine(path, "Certs", "csd.cer"); if (File.Exists(cer)) { X509Certificate2 cert = new X509Certificate2(cer); empr.VencimientoCert = cert.GetExpirationDateString(); } } return(empr); } } catch (Exception ee) { Logger.Error(ee.Message); if (ee.InnerException != null) { Logger.Error(ee.InnerException); } return(null); } }
public bool Save(empresa e, byte[] cert, byte[] llave, string passwordLlave, byte[] logo) { try { using (var db = new NtLinkLocalServiceEntities()) { if (Validar(e)) { CreaRutas(e.RFC); string path = Path.Combine(ConfigurationManager.AppSettings["Resources"], e.RFC); if (logo != null) { File.WriteAllBytes(Path.Combine(path, "Logo.png"), logo); } if (!ValidaRfcEmisor(e.RFC, cert)) { throw new FaultException("El rfc del emisor no corresponde con el certificado"); } string pathCer = Path.Combine(path, "Certs", "csd.cer"); string pathKey = Path.Combine(path, "Certs", "csd.key"); File.WriteAllBytes(pathCer, cert); File.WriteAllBytes(pathKey, llave); //CertUtil.CreaP12(pathKey, pathCer, passwordLlave, Path.ChangeExtension(pathCer, ".p12")); if (e.IdEmpresa == 0) { if (db.empresa.Any(l => l.RFC.Equals(e.RFC) && l.idSistema == e.idSistema)) { throw new FaultException("El RFC ya ha sido dato de alta"); } db.empresa.AddObject(e); } else { db.empresa.Where(p => p.IdEmpresa == e.IdEmpresa).FirstOrDefault(); db.empresa.ApplyCurrentValues(e); } db.SaveChanges(); return(true); } Logger.Error("Fallo de validaciĆ³n"); return(false); } } catch (ApplicationException ae) { throw new FaultException(ae.Message); } catch (FaultException fe) { throw; } catch (Exception ee) { Logger.Error(ee.Message); return(false); } }
public List <empresa> GetListForLine(string Linea) { try { using (var db = new NtLinkLocalServiceEntities()) { if (Linea == null) { Linea = "A"; } if (Linea != null) { var res = db.empresa.Where(p => p.Linea == Linea).Select( p => new { p.RFC, p.idSistema, p.IdEmpresa, p.RazonSocial, p.TimbresConsumidos, Linea, p.Baja, p.Bloqueado }).OrderBy(p => p.RFC).ToList(); return (res.Select( p => new empresa() { RFC = p.RFC, idSistema = p.idSistema, IdEmpresa = p.IdEmpresa, RazonSocial = p.RazonSocial, TimbresConsumidos = p.TimbresConsumidos, Linea = p.Linea, Baja = p.Baja, Bloqueado = p.Bloqueado }).ToList()); } else { return(db.empresa.Select(p => new empresa() { RFC = p.RFC, idSistema = p.idSistema, IdEmpresa = p.IdEmpresa, RazonSocial = p.RazonSocial, TimbresConsumidos = p.TimbresConsumidos, Linea = p.Linea, Baja = p.Baja, Bloqueado = p.Bloqueado }).OrderBy(p => p.RFC).ToList()); } } } catch (Exception ee) { Logger.Error(ee.Message); return(null); } }
public static List <ElementoReporte> ObtenerReporte(int mes, int anio) { try { using (var db = new NtLinkLocalServiceEntities()) { if (mes == 0) { var timbres = db.vTimbresSistemaAnio.Where(p => p.Anio == anio).ToList(); return(timbres.Select( p => new ElementoReporte() { Cancelados = db.vventas.Count( f => f.Fecha.Year == anio && f.RfcEmisor == p.Rfc && f.Cancelado == 1), Cliente = p.RazonSocial, Emitidos = p.Timbres.Value, Rfc = p.Rfc }). ToList()); } else { var timbres = db.vTimbresSistema.Where(p => p.Mes == mes && p.Anio == anio). ToList(); return(timbres.Select( p => new ElementoReporte() { Cancelados = db.vventas.Count( f => f.Fecha.Month == mes && f.Fecha.Year == anio && f.RfcEmisor == p.Rfc && f.Cancelado == 1), Cliente = p.RazonSocial, Emitidos = p.Timbres.Value, Rfc = p.Rfc }). ToList()); } } } catch (Exception ee) { Logger.Error(ee.Message); if (ee.InnerException != null) { Logger.Error(ee.InnerException); } return(null); } }
public static bool CreateUser(string userName, string password, string eMail, int idEmpresa, string perfil, string nombreCompleto, string iniciales) { MembershipCreateStatus status = MembershipCreateStatus.ProviderError; try { using (var db = new NtLinkLocalServiceEntities()) { Membership.CreateUser(userName, password, eMail, "uno", "dos", true, out status); Logger.Debug(status.ToString()); if (status == MembershipCreateStatus.Success) { UserProfile p = UserProfile.GetUserProfile(userName); p.NombreCompleto = nombreCompleto; p.Iniciales = iniciales; p.Save(); MembershipUser mu = Membership.GetUser(userName); if (mu != null && mu.ProviderUserKey != null) { usuarios_empresas ue = new usuarios_empresas { IdEmpresa = idEmpresa, UserId = mu.ProviderUserKey.ToString() }; db.usuarios_empresas.AddObject(ue); } db.SaveChanges(); Roles.AddUserToRole(userName, perfil); return(true); } } } catch (Exception ee) { Logger.Error(ee.Message); } if (status == MembershipCreateStatus.DuplicateEmail) { throw new FaultException("Email Duplicado"); } if (status == MembershipCreateStatus.DuplicateUserName) { throw new FaultException("Usuario Duplicado"); } if (status == MembershipCreateStatus.InvalidPassword) { throw new FaultException("El password no cumple con las politicas de seguridad"); } return(false); }
public List <LogLco> GetLogLco() { try { using (var db = new NtLinkLocalServiceEntities()) { return(db.LogLco.OrderByDescending(p => p.IdLogLco).Take(5).ToList()); } } catch (Exception ee) { Logger.Error(ee.Message); return(null); } }
public List <Comisionistas> GetComisionistasLista(int idEmpresa) { try { using (var db = new NtLinkLocalServiceEntities()) { var com = db.Comisionistas.Where(c => c.IdEmpresa == idEmpresa); return(com.ToList()); } } catch (Exception ee) { Logger.Error(ee.Message); return(null); } }
public Comisionistas GetComisionista(long idComisionista) { try { using (var db = new NtLinkLocalServiceEntities()) { var com = db.Comisionistas.Where(c => c.IdComisionista == idComisionista); return(com.FirstOrDefault()); } } catch (Exception ee) { Logger.Error(ee.Message); return(null); } }
public TimbreWsHistorico ObtenerTimbreHistHash(string hash) { try { using (var db = new NtLinkLocalServiceEntities()) { var timbre = db.TimbreWsHistorico.FirstOrDefault(p => p.Hash == hash); return(timbre); } } catch (Exception ee) { Logger.Error(ee); return(null); } }