/// <summary> /// Obtener Periodo Facturación /// </summary> /// <returns>Lista de Periodo Facturación</returns> public MethodResponseDTO <List <C_PeriodosDTO> > ObtenerPeriodo() { using (var context = new DB_9F97CF_CatarsysSGCEntities()) { try { var response = new MethodResponseDTO <List <C_PeriodosDTO> >() { Code = 0 }; var obj = context.C_Periodos.ToList(); response.Result = Mapper.Map <List <C_PeriodosDTO> >(obj); return(response); } catch (Exception ex) { return(new MethodResponseDTO <List <C_PeriodosDTO> > { Code = -100, Message = "ObtenerPeriodo: " + ex.Message }); } } }
public MethodResponseDTO <List <ContactosDTO> > GetContactosCliente(int IdCliente) { using (var context = new DB_9F97CF_CatarsysSGCEntities()) { try { var response = new MethodResponseDTO <List <ContactosDTO> >() { Code = 0 }; var clientes = context.Contactos.Where(x => x.Id_Cliente == IdCliente && x.Estado == true).ToList(); response.Result = Mapper.Map <List <ContactosDTO> >(clientes); return(response); } catch (Exception ex) { return(new MethodResponseDTO <List <ContactosDTO> > { Code = -100, Message = "ObtenerContactos: " + ex.Message }); } } }
public MethodResponseDTO <PaginacionDTO <List <CarteraVencidaPaginadorDTO> > > ObtenerCarteraVencidaPaginacion(int page, int size, int sort, string sortDireccion, string filter, int filterCliente, int filterEstado, DateTime filterPeriodo, int Id_Empresa) { using (var context = new DB_9F97CF_CatarsysSGCEntities()) { try { var response = new MethodResponseDTO <PaginacionDTO <List <CarteraVencidaPaginadorDTO> > >() { Code = 0 }; var responsePag = new PaginacionDTO <List <CarteraVencidaPaginadorDTO> >(); ObjectParameter totalrow = new ObjectParameter("totalrow", typeof(int)); var asignacion = context.sp_GetCarteraVencidaPaginacion(page, size, sort, Id_Empresa, sortDireccion, filter, filterEstado, filterPeriodo, totalrow).ToList(); //var asignacion = context.sp_GetCarteraVencidaPaginacion(0, 10, 1, 1, "asc", "",1, filterPeriodo, totalrow).ToList(); responsePag.data = Mapper.Map <List <CarteraVencidaPaginadorDTO> >(asignacion); responsePag.recordsTotal = Convert.ToInt32(totalrow.Value); responsePag.draw = page; response.Result = responsePag; return(response); } catch (Exception ex) { return(new MethodResponseDTO <PaginacionDTO <List <CarteraVencidaPaginadorDTO> > > { Code = -100, Message = "Obtner Facturas Paginador: " + ex.Message }); } } }
/// <summary> /// Obtener Asignaciones /// Con idAsignacion = 0 regresara todas las asignaciones /// Con estatusAsignacion = 0 regresara las asignaciones de cualquier estado /// </summary> /// <param name="idFactura"></param> /// <param name="estatusAsignacion"></param> /// <returns></returns> public MethodResponseDTO <List <FacturasDTO> > ObtenerFacturas(int idFactura) { using (var context = new DB_9F97CF_CatarsysSGCEntities()) { try { var response = new MethodResponseDTO <List <FacturasDTO> >() { Code = 0 }; var asignaciones = context.Facturas.Where(x => (x.IdFactura == idFactura || idFactura == 0)).ToList(); response.Result = Mapper.Map <List <FacturasDTO> >(asignaciones); return(response); } catch (Exception ex) { return(new MethodResponseDTO <List <FacturasDTO> > { Code = -100, Message = "ObtenerAsignaciones: " + ex.Message }); } } }
/// <summary> /// Obtener Permisos /// </summary> /// <returns>Lista de tipo asignacion</returns> public MethodResponseDTO <List <PermisosDTO> > ObtenerPermisos() { using (var context = new DB_9F97CF_CatarsysSGCEntities()) { try { var response = new MethodResponseDTO <List <PermisosDTO> >() { Code = 0 }; var tipoAsignacion = context.ctPermisos.Where(x => x.Estado_Permiso == true).ToList(); response.Result = Mapper.Map <List <PermisosDTO> >(tipoAsignacion); return(response); } catch (Exception ex) { return(new MethodResponseDTO <List <PermisosDTO> > { Code = -100, Message = "Obtener Permisos DTO: " + ex.Message }); } } }
/// <summary> /// Obtener Proyectos /// Con IdProyecto = 0 regresara todos los proyectos /// Con IdEmpresa = 0 regresara todos los proyectos de todas las empresas /// Con estado = 0 regresara los proyectos de cualquier estado /// </summary> /// <param name="idProyecto"></param> /// <param name="idEmpresa"></param> /// <param name="estado"></param> /// <returns>Lista de proyectos</returns> public MethodResponseDTO <List <ProyectosDTO> > ObtenerProyecto(int idProyecto, int idEmpresa, int estado) { using (var context = new DB_9F97CF_CatarsysSGCEntities()) { try { var response = new MethodResponseDTO <List <ProyectosDTO> >() { Code = 0 }; var asignaciones = context.Proyectos.Where(x => (x.Id_Proyectos == idProyecto || idProyecto == 0) && (x.Estado == (estado == 1) || estado == 2) && (x.Id_Empresa == idEmpresa || idEmpresa == 0)).ToList(); response.Result = Mapper.Map <List <ProyectosDTO> >(asignaciones); return(response); } catch (Exception ex) { return(new MethodResponseDTO <List <ProyectosDTO> > { Code = -100, Message = "ObtenerProyecto: " + ex.Message }); } } }
/// <summary> /// Obtener Asignaciones /// Con idAsignacion = 0 regresara todas las asignaciones /// Con estatusAsignacion = 0 regresara las asignaciones de cualquier estado /// </summary> /// <param name="idAsignacion"></param> /// <param name="estatusAsignacion"></param> /// <returns></returns> public MethodResponseDTO <List <AsignacionDTO> > ObtenerAsignaciones(int idAsignacion, int estatusAsignacion) { using (var context = new DB_9F97CF_CatarsysSGCEntities()) { try { var response = new MethodResponseDTO <List <AsignacionDTO> >() { Code = 0 }; var asignaciones = context.Asignacion.Where(x => (x.Id_Asignacion == idAsignacion || idAsignacion == 0) && (x.Id_Estatus_Asignacion == estatusAsignacion || estatusAsignacion == 0)).ToList(); response.Result = Mapper.Map <List <AsignacionDTO> >(asignaciones); return(response); } catch (Exception ex) { return(new MethodResponseDTO <List <AsignacionDTO> > { Code = -100, Message = "ObtenerAsignaciones: " + ex.Message }); } } }
/// <summary> /// Obtener Tipo Asignación /// </summary> /// <returns>Lista de tipo asignacion</returns> public MethodResponseDTO <List <C_Tipo_AsignacionDTO> > ObtenerTipoAsignacion() { using (var context = new DB_9F97CF_CatarsysSGCEntities()) { try { var response = new MethodResponseDTO <List <C_Tipo_AsignacionDTO> >() { Code = 0 }; var tipoAsignacion = context.C_Tipo_Asignacion.ToList(); response.Result = Mapper.Map <List <C_Tipo_AsignacionDTO> >(tipoAsignacion); return(response); } catch (Exception ex) { return(new MethodResponseDTO <List <C_Tipo_AsignacionDTO> > { Code = -100, Message = "ObtenerTipoAsignacion: " + ex.Message }); } } }
public MethodResponseDTO <PaginacionDTO <List <AsignacionPaginadorDTO> > > ObtenerAsignacionesPaginacion(int page, int size, int sort, string sortDireccion, string filter, int Id_Empresa) { using (var context = new DB_9F97CF_CatarsysSGCEntities()) { try { var response = new MethodResponseDTO <PaginacionDTO <List <AsignacionPaginadorDTO> > >() { Code = 0 }; var responsePag = new PaginacionDTO <List <AsignacionPaginadorDTO> >(); ObjectParameter totalrow = new ObjectParameter("totalrow", typeof(int)); var asignacion = context.sp_GetAsigPaginacion(page, size, sort, Id_Empresa, sortDireccion, filter, totalrow).ToList(); responsePag.data = Mapper.Map <List <AsignacionPaginadorDTO> >(asignacion); responsePag.recordsTotal = Convert.ToInt32(totalrow.Value); responsePag.draw = page; response.Result = responsePag; return(response); } catch (Exception ex) { return(new MethodResponseDTO <PaginacionDTO <List <AsignacionPaginadorDTO> > > { Code = -100, Message = "ObtenerAsignaciones: " + ex.Message }); } } }
/// <summary> /// Obtener Empresas -> /// Con IdEmpresa = 0 regresara todas las Empresas /// Con Estado = 2 regresara todas las Empresas de todos los estados /// </summary> /// <param name="IdEmpresa"></param> /// <param name="Estado"></param> /// <returns></returns> public MethodResponseDTO <List <EmpresaDTO> > ObtenerEmpresas(int Id_Empresa, int Estado) { using (var context = new DB_9F97CF_CatarsysSGCEntities()) { try { var response = new MethodResponseDTO <List <EmpresaDTO> >() { Code = 0 }; var obj = context.Empresa.Where(x => (x.Id_Empresa == Id_Empresa || Id_Empresa == 0) && (x.Estado_Empresa == (Estado == 1) || Estado == 2)).ToList(); response.Result = Mapper.Map <List <EmpresaDTO> >(obj); return(response); } catch (Exception ex) { return(new MethodResponseDTO <List <EmpresaDTO> > { Code = -100, Message = "ObtenerEmpleados: " + ex.Message }); } } }
/// <summary> /// Obtener Empleados por username /// </summary> /// <param name="Username"></param> /// <returns>EmpleadosDTO</returns> public MethodResponseDTO <EmpleadosDTO> ObtenerEmpleados(string Username) { using (var context = new DB_9F97CF_CatarsysSGCEntities()) { try { var response = new MethodResponseDTO <EmpleadosDTO>() { Code = 0 }; var clientes = context.Empleados.Where(x => x.Usuario_Empleado == Username).FirstOrDefault(); response.Result = Mapper.Map <EmpleadosDTO>(clientes); return(response); } catch (Exception ex) { return(new MethodResponseDTO <EmpleadosDTO> { Code = -100, Message = "ObtenerEmpleados: " + ex.Message }); } } }
/// <summary> /// Obtener Metodo de Pago /// </summary> /// <returns>Lista de tipo asignacion</returns> public MethodResponseDTO <List <C_Metodo_PagoDTO> > ObtenerMetodoPago() { using (var context = new DB_9F97CF_CatarsysSGCEntities()) { try { var response = new MethodResponseDTO <List <C_Metodo_PagoDTO> >() { Code = 0 }; var metodoPago = context.C_Metodo_Pago.ToList(); response.Result = Mapper.Map <List <C_Metodo_PagoDTO> >(metodoPago); return(response); } catch (Exception ex) { return(new MethodResponseDTO <List <C_Metodo_PagoDTO> > { Code = -100, Message = "Obtener Metodo Pago DTO: " + ex.Message }); } } }
public MethodResponseDTO <int> GuardarContactos(ContactosDTO contactos) { using (var context = new DB_9F97CF_CatarsysSGCEntities()) { try { var response = new MethodResponseDTO <int>() { Code = 0, Result = 1 }; if (contactos.Id_Contacto == 0) { var objDB = Mapper.Map <Contactos>(contactos); context.Contactos.Add(objDB); } else { var objDB = context.Contactos.SingleOrDefault(x => x.Id_Contacto == contactos.Id_Contacto); objDB.Nombre_Contacto = contactos.Nombre_Contacto; objDB.Puesto_Contacto = contactos.Puesto_Contacto; objDB.Email_Contacto = contactos.Email_Contacto; objDB.Telefono_Contacto = contactos.Telefono_Contacto; objDB.Movil__Contacto = contactos.Movil__Contacto; objDB.Skype_Contacto = contactos.Skype_Contacto; objDB.Comentario_Contacto = contactos.Comentario_Contacto; objDB.EnviaFactura_Contacto = contactos.EnviaFactura_Contacto; objDB.Estado = contactos.Estado; } context.SaveChanges(); return(response); } catch (DbEntityValidationException e) { string Result = string.Empty; foreach (var eve in e.EntityValidationErrors) { Result += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Result += string.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } Result += ("Code: -100, Mensaje: " + e.Message + ", InnerException: " + (e.InnerException != null ? e.InnerException.Message : "")); return(new MethodResponseDTO <int> { Code = -100, Result = 0, Message = e.Message }); } catch (Exception ex) { return(new MethodResponseDTO <int> { Code = -100, Result = 0, Message = "GuardarAsignacion: " + ex.Message }); } } }
/// <summary> /// Guardar Asignacion /// </summary> /// <returns>Lista de tipo asignacion</returns> public MethodResponseDTO <int> GuardarPermisos(List <EmpleadoPermisoDTO> permisos) { using (var context = new DB_9F97CF_CatarsysSGCEntities()) { try { var response = new MethodResponseDTO <int>() { Code = 0, Result = 1 }; foreach (var perm in permisos) { var objDB = context.EmpleadoPermiso.Where(x => x.Id_Empleado == perm.Id_Empleado && perm.Id_Permiso == x.Id_Permiso).FirstOrDefault(); if (objDB == null) { objDB = Mapper.Map <EmpleadoPermiso>(perm); context.EmpleadoPermiso.Add(objDB); } else { objDB.Id_Empleado = perm.Id_Empleado; objDB.Id_Permiso = perm.Id_Permiso; objDB.Tipo_Permiso = perm.Tipo_Permiso; } context.SaveChanges(); } return(response); } catch (DbEntityValidationException e) { string Result = string.Empty; foreach (var eve in e.EntityValidationErrors) { Result += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Result += string.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } Result += ("Code: -100, Mensaje: " + e.Message + ", InnerException: " + (e.InnerException != null ? e.InnerException.Message : "")); return(new MethodResponseDTO <int> { Code = -100, Result = 0, Message = e.Message }); } catch (Exception ex) { return(new MethodResponseDTO <int> { Code = -100, Result = 0, Message = "GuardarAsignacion: " + ex.Message }); } } }
/// <summary> /// Borrar Facturas /// </summary> /// <returns>Lista de tipo asignacion</returns> public MethodResponseDTO <int> BorrarFacturas(int Id, int tipo) { using (var context = new DB_9F97CF_CatarsysSGCEntities()) { try { var response = new MethodResponseDTO <int>() { Code = 0, Result = 1 }; List <Facturas> ltsFacturas; if (tipo == 1) { ltsFacturas = context.Facturas.Where(x => x.IdProyecto == Id && x.Id_Estado_Factura == 1).ToList(); } else { ltsFacturas = context.Facturas.Where(x => x.IdAsignacion == Id && x.Id_Estado_Factura == 1).ToList(); } foreach (var factura in ltsFacturas) { context.Facturas.Remove(factura); context.SaveChanges(); } return(response); } catch (DbEntityValidationException e) { string Result = string.Empty; foreach (var eve in e.EntityValidationErrors) { Result += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Result += string.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } Result += ("Code: -100, Mensaje: " + e.Message + ", InnerException: " + (e.InnerException != null ? e.InnerException.Message : "")); return(new MethodResponseDTO <int> { Code = -100, Result = 0, Message = e.Message }); } catch (Exception ex) { return(new MethodResponseDTO <int> { Code = -100, Result = 0, Message = "GuardarAsignacion: " + ex.Message }); } } }
public MethodResponseDTO <EmpleadoPermisoDTO> ObtenRolActivo(int IdPermiso) { using (var context = new DB_9F97CF_CatarsysSGCEntities()) { try { var response = new MethodResponseDTO <EmpleadoPermisoDTO> { Code = 0 }; var objDB = context.ctPermisos.SingleOrDefault(r => r.Id_Permisos == IdPermiso && r.Estado_Permiso == true); if (objDB != null) { response.Result = Mapper.Map <EmpleadoPermisoDTO>(objDB); } return(response); } catch (DbEntityValidationException e) { string Result = string.Empty; foreach (var eve in e.EntityValidationErrors) { Result += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Result += string.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } Result += ("Code: -100, Mensaje: " + e.Message + ", InnerException: " + (e.InnerException != null ? e.InnerException.Message : "")); return(new MethodResponseDTO <EmpleadoPermisoDTO> { Code = -100, Message = Result }); } catch (Exception ex) { return(new MethodResponseDTO <EmpleadoPermisoDTO> { Code = -100, Message = "GuardarAsignacion: " + ex.Message }); } } }
public MethodResponseDTO <List <EmpleadoPermisoDTO> > ObtenerPermisos(int IdEmpleado) { using (var context = new DB_9F97CF_CatarsysSGCEntities()) { try { var response = new MethodResponseDTO <List <EmpleadoPermisoDTO> > { Code = 0 }; var objDB = context.EmpleadoPermiso .Join(context.ctPermisos, c => c.Id_Permiso, cm => cm.Id_Permisos, (c, cm) => new { EmpPer = c, Per = cm }) .Where(a => a.EmpPer.Id_Empleado == IdEmpleado && a.Per.Estado_Permiso == true && a.EmpPer.Tipo_Permiso > 0).Select(x => x.EmpPer); response.Result = Mapper.Map <List <EmpleadoPermisoDTO> >(objDB); return(response); } catch (DbEntityValidationException e) { string Result = string.Empty; foreach (var eve in e.EntityValidationErrors) { Result += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Result += string.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } Result += ("Code: -100, Mensaje: " + e.Message + ", InnerException: " + (e.InnerException != null ? e.InnerException.Message : "")); return(new MethodResponseDTO <List <EmpleadoPermisoDTO> > { Code = -100, Message = Result }); } catch (Exception ex) { return(new MethodResponseDTO <List <EmpleadoPermisoDTO> > { Code = -100, Message = "GuardarAsignacion: " + ex.Message }); } } }
public MethodResponseDTO <bool> ObtenerPermisosTipo(int IdEmpleado, int Idpermiso) { using (var context = new DB_9F97CF_CatarsysSGCEntities()) { try { var response = new MethodResponseDTO <bool> { Code = 0 }; var objDB = context.EmpleadoPermiso.Where(a => a.Id_Empleado == IdEmpleado && a.Id_Permiso == Idpermiso).FirstOrDefault(); response.Result = (objDB.Tipo_Permiso == 2 || objDB.Tipo_Permiso == 3); return(response); } catch (DbEntityValidationException e) { string Result = string.Empty; foreach (var eve in e.EntityValidationErrors) { Result += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Result += string.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } Result += ("Code: -100, Mensaje: " + e.Message + ", InnerException: " + (e.InnerException != null ? e.InnerException.Message : "")); return(new MethodResponseDTO <bool> { Code = -100, Message = Result }); } catch (Exception ex) { return(new MethodResponseDTO <bool> { Code = -100, Message = "Obtener permiso Tipo: " + ex.Message }); } } }
/// <summary> /// Guardar Asignacion /// </summary> /// <returns>Lista de tipo asignacion</returns> public MethodResponseDTO <int> GuardarAsignacion(AsignacionDTO asignacion) { using (var context = new DB_9F97CF_CatarsysSGCEntities()) { try { var response = new MethodResponseDTO <int>() { Code = 0, Result = 1 }; if (asignacion.Id_Asignacion == 0) { Asignacion asignacionDB = Mapper.Map <Asignacion>(asignacion); context.Asignacion.Add(asignacionDB); } else { var asig = context.Asignacion.SingleOrDefault(x => x.Id_Asignacion == asignacion.Id_Asignacion); asig.Id_Asignacion = asignacion.Id_Asignacion; asig.Id_Empleado_Asignacion = asignacion.Id_Empleado_Asignacion; asig.Id_Cliente_Asignacion = asignacion.Id_Cliente_Asignacion; asig.Id_Tipo_Asignacion = asignacion.Id_Tipo_Asignacion; asig.Id_Estatus_Asignacion = asignacion.Id_Estatus_Asignacion; asig.Id_Corte_Asignacion = asignacion.Id_Corte_Asignacion; asig.Id_Moneda_Asignacion = asignacion.Id_Moneda_Asignacion; asig.Id_Periodo_Asignacion = asignacion.Id_Periodo_Asignacion; asig.Id_Empresa = asignacion.Id_Empresa; asig.Id_IVA_Asignacion = asignacion.Id_IVA_Asignacion; asig.Fecha_Ini_Asignacion = asignacion.Fecha_Ini_Asignacion; asig.Fecha_Fin_Asignacion = asignacion.Fecha_Fin_Asignacion; asig.Costo_Pactado_Asignacion = asignacion.Costo_Pactado_Asignacion; } context.SaveChanges(); return(response); } catch (DbEntityValidationException e) { string Result = string.Empty; foreach (var eve in e.EntityValidationErrors) { Result += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Result += string.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } Result += ("Code: -100, Mensaje: " + e.Message + ", InnerException: " + (e.InnerException != null ? e.InnerException.Message : "")); return(new MethodResponseDTO <int> { Code = -100, Result = 0, Message = e.Message }); } catch (Exception ex) { return(new MethodResponseDTO <int> { Code = -100, Result = 0, Message = "GuardarAsignacion: " + ex.Message }); } } }
/// <summary> /// Guardar Empresas /// </summary> /// <returns>Lista de tipo asignacion</returns> public MethodResponseDTO <int> GuardarEmpresas(EmpresaDTO empresa) { using (var context = new DB_9F97CF_CatarsysSGCEntities()) { try { var response = new MethodResponseDTO <int>() { Code = 0, Result = 1 }; if (empresa.Id_Empresa == 0) { var objDB = Mapper.Map <Empresa>(empresa); context.Empresa.Add(objDB); } else { var objDB = context.Empresa.SingleOrDefault(x => x.Id_Empresa == empresa.Id_Empresa); objDB.Id_Empresa = empresa.Id_Empresa; objDB.Nombre_Empresa = empresa.Nombre_Empresa; objDB.Razon_Social_Empresa = empresa.Razon_Social_Empresa; objDB.RFC_Empresa = empresa.RFC_Empresa; objDB.Calle_Empresa = empresa.Calle_Empresa; objDB.No_Ext_Empresa = empresa.No_Ext_Empresa; objDB.No_Int_Empresa = empresa.No_Int_Empresa; objDB.Colonia_Empresa = empresa.Colonia_Empresa; objDB.CP_Empresa = empresa.CP_Empresa; objDB.Del_Mun_Empresa = empresa.Del_Mun_Empresa; objDB.Estado_Dom_Empresa = empresa.Estado_Dom_Empresa; objDB.Email_Empresa = empresa.Email_Empresa; objDB.Fecha_Creacion_Empresa = empresa.Fecha_Creacion_Empresa; objDB.Estado_Empresa = empresa.Estado_Empresa; } context.SaveChanges(); return(response); } catch (DbEntityValidationException e) { string Result = string.Empty; foreach (var eve in e.EntityValidationErrors) { Result += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Result += string.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } Result += ("Code: -100, Mensaje: " + e.Message + ", InnerException: " + (e.InnerException != null ? e.InnerException.Message : "")); return(new MethodResponseDTO <int> { Code = -100, Result = 0, Message = Result }); } catch (Exception ex) { return(new MethodResponseDTO <int> { Code = -100, Result = 0, Message = "GuardarAsignacion: " + ex.Message }); } } }
/// <summary> /// Guardar Proyecto /// </summary> /// <returns>Lista de tipo asignacion</returns> public MethodResponseDTO <int> GuardarProyecto(ProyectosDTO proyecto) { using (var context = new DB_9F97CF_CatarsysSGCEntities()) { try { var response = new MethodResponseDTO <int>() { Code = 0, Result = 1 }; if (proyecto.Id_Proyectos == 0) { var proyectoDB = Mapper.Map <Proyectos>(proyecto); context.Proyectos.Add(proyectoDB); } else { var asig = context.Proyectos.SingleOrDefault(x => x.Id_Proyectos == proyecto.Id_Proyectos); asig.Id_Proyectos = proyecto.Id_Proyectos; asig.Id_Clientes_Proyectos = proyecto.Id_Clientes_Proyectos; asig.Id_Empresa = proyecto.Id_Empresa; asig.Nombre_Proyectos = proyecto.Nombre_Proyectos; asig.Fecha_Ini_Proyectos = proyecto.Fecha_Ini_Proyectos; asig.Fecha_Fin_Proyectos = proyecto.Fecha_Fin_Proyectos; asig.Costo_Proyectos = proyecto.Costo_Proyectos; asig.Id_Moneda_Proyectos = proyecto.Id_Moneda_Proyectos; asig.Numero_Facturas_Proyectos = proyecto.Numero_Facturas_Proyectos; asig.Id_Tipo_Cambio_Proyectos = proyecto.Id_Tipo_Cambio_Proyectos; asig.Id_IVA_Proyectos = proyecto.Id_IVA_Proyectos; asig.Estado = proyecto.Estado; } context.SaveChanges(); var _FacturasData = new FacturasData(); var BrFacturas = _FacturasData.BorrarFacturas(proyecto.Id_Proyectos, 1); if (BrFacturas.Code != 0) { return(new MethodResponseDTO <int> { Code = -100, Result = 0, Message = "Borrar Facturas: " + BrFacturas.Message }); } var Facturas = _FacturasData.GuardarFacturas(proyecto.facturas); if (Facturas.Code != 0) { return(new MethodResponseDTO <int> { Code = -100, Result = 0, Message = "Guardar Facturas: " + Facturas.Message }); } return(response); } catch (DbEntityValidationException e) { string Result = string.Empty; foreach (var eve in e.EntityValidationErrors) { Result += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Result += string.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } Result += ("Code: -100, Mensaje: " + e.Message + ", InnerException: " + (e.InnerException != null ? e.InnerException.Message : "")); return(new MethodResponseDTO <int> { Code = -100, Result = 0, Message = e.Message }); } catch (Exception ex) { return(new MethodResponseDTO <int> { Code = -100, Result = 0, Message = "Guardar Proyecto: " + ex.Message }); } } }
/// <summary> /// Guardar Facturas /// </summary> /// <returns>Lista de tipo asignacion</returns> public MethodResponseDTO <int> GuardarFacturas(List <FacturasDTO> ltsFacturas) { using (var context = new DB_9F97CF_CatarsysSGCEntities()) { try { var response = new MethodResponseDTO <int>() { Code = 0, Result = 1 }; foreach (var factura in ltsFacturas) { if (factura.Id_Estado_Factura == 1) { if (factura.IdFactura == 0) { Facturas facturasDB = Mapper.Map <Facturas>(factura); context.Facturas.Add(facturasDB); } else { var fact = context.Facturas.SingleOrDefault(x => x.IdFactura == factura.IdFactura); fact.IdFactura = factura.IdFactura; fact.IdCliente = factura.IdCliente; fact.IdEmpresa = factura.IdEmpresa; fact.IdAsignacion = factura.IdAsignacion; fact.IdProyecto = factura.IdProyecto; fact.C_Id_IVA = factura.C_Id_IVA; fact.C_Id_Moneda = factura.C_Id_Moneda; fact.C_Id_Tipo_Cambio = factura.C_Id_Tipo_Cambio; fact.C_Id_Metodo_Pago = factura.C_Id_Metodo_Pago; fact.Tipo_Factura = factura.Tipo_Factura; fact.Fecha_Inicio_Factura = factura.Fecha_Inicio_Factura; fact.Fecha_fin_Factura = factura.Fecha_fin_Factura; fact.No_Factura = factura.No_Factura; fact.Descuento_Factura = factura.Descuento_Factura; fact.Monto_Factura = factura.Monto_Factura; fact.Ultimos_4_digitos_Factura = factura.Ultimos_4_digitos_Factura; } } context.SaveChanges(); } return(response); } catch (DbEntityValidationException e) { string Result = string.Empty; foreach (var eve in e.EntityValidationErrors) { Result += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Result += string.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } Result += ("Code: -100, Mensaje: " + e.Message + ", InnerException: " + (e.InnerException != null ? e.InnerException.Message : "")); return(new MethodResponseDTO <int> { Code = -100, Result = 0, Message = e.Message }); } catch (Exception ex) { return(new MethodResponseDTO <int> { Code = -100, Result = 0, Message = "GuardarAsignacion: " + ex.Message }); } } }
/// <summary> /// Guardar Empleado /// </summary> /// <returns>Lista de tipo asignacion</returns> public MethodResponseDTO <int> GuardarEmpleado(EmpleadosDTO empleado) { using (var context = new DB_9F97CF_CatarsysSGCEntities()) { try { var response = new MethodResponseDTO <int>() { Code = 0, Result = 1 }; if (empleado.Id_Empleado == 0) { var objDB = Mapper.Map <Empleados>(empleado); context.Empleados.Add(objDB); } else { var objDB = context.Empleados.SingleOrDefault(x => x.Id_Empleado == empleado.Id_Empleado); objDB.Id_Empleado = empleado.Id_Empleado; objDB.Id_Empresa = empleado.Id_Empresa; objDB.Nombre_Empleado = empleado.Nombre_Empleado; objDB.Email_Empleado = empleado.Email_Empleado; objDB.Puesto_Empleado = empleado.Puesto_Empleado; objDB.Fecha_Nacimiento_Empleado = empleado.Fecha_Nacimiento_Empleado; objDB.Antiguedad_Empleado = empleado.Antiguedad_Empleado; objDB.Skype_Empleado = empleado.Skype_Empleado; objDB.Domicilio_Empleado = empleado.Domicilio_Empleado; objDB.Telefono_L_Empleado = empleado.Telefono_L_Empleado; objDB.Telefono_M_Empleado = empleado.Telefono_M_Empleado; objDB.Id_JefeInmediato_Empleado = empleado.Id_JefeInmediato_Empleado; objDB.IsLogIn = empleado.IsLogIn; objDB.Usuario_Empleado = empleado.Usuario_Empleado; if (empleado.Password_Empleado != string.Empty) { objDB.Password_Empleado = empleado.Password_Empleado; objDB.Salt = empleado.Salt; } objDB.Estado = empleado.Estado; //objDB.Id_Perfil = empleado.Id_Perfil; } context.SaveChanges(); var permisos = GuardarPermisos(empleado.EmpleadoPermiso); if (permisos.Code != 0) { return(new MethodResponseDTO <int> { Code = -100, Result = 0, Message = permisos.Message }); } return(response); } catch (DbEntityValidationException e) { string Result = string.Empty; foreach (var eve in e.EntityValidationErrors) { Result += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Result += string.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } Result += ("Code: -100, Mensaje: " + e.Message + ", InnerException: " + (e.InnerException != null ? e.InnerException.Message : "")); return(new MethodResponseDTO <int> { Code = -100, Result = 0, Message = Result }); } catch (Exception ex) { return(new MethodResponseDTO <int> { Code = -100, Result = 0, Message = "GuardarAsignacion: " + ex.Message }); } } }
/// <summary> /// Guardar Clientes /// </summary> /// <returns>Lista de tipo asignacion</returns> public MethodResponseDTO <int> GuardarCliente(ClientesDTO clientes) { using (var context = new DB_9F97CF_CatarsysSGCEntities()) { try { var response = new MethodResponseDTO <int>() { Code = 0, Result = 1 }; if (clientes.Id_Empresa == 0) { var objDB = Mapper.Map <Clientes>(clientes); context.Clientes.Add(objDB); } else { var objDB = context.Clientes.SingleOrDefault(x => x.Id_Cliente == clientes.Id_Cliente); objDB.Id_Cliente = clientes.Id_Cliente; objDB.Id_Empresa = clientes.Id_Empresa; objDB.Nombre_Cliente = clientes.Nombre_Cliente; objDB.Razon_Social_Cliente = clientes.Razon_Social_Cliente; objDB.RFC_Cliente = clientes.RFC_Cliente; objDB.Calle_Cliente = clientes.Calle_Cliente; objDB.Exterior_Cliente = clientes.Exterior_Cliente; objDB.Interior_Cliente = clientes.Interior_Cliente; objDB.Colonia_Cliente = clientes.Colonia_Cliente; objDB.DelMun_Cliente = clientes.DelMun_Cliente; objDB.CP_Cliente = clientes.CP_Cliente; objDB.Estado_Dom_Cliente = clientes.Estado_Dom_Cliente; objDB.Dias_de_Pago_Cliente = clientes.Dias_de_Pago_Cliente; objDB.Estado = clientes.Estado; objDB.Contactos = Mapper.Map <List <Contactos> >(clientes.Contactos); }; context.SaveChanges(); return(response); } catch (DbEntityValidationException e) { string Result = string.Empty; foreach (var eve in e.EntityValidationErrors) { Result += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Result += string.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } Result += ("Code: -100, Mensaje: " + e.Message + ", InnerException: " + (e.InnerException != null ? e.InnerException.Message : "")); return(new MethodResponseDTO <int> { Code = -100, Result = 0, Message = e.Message }); } catch (Exception ex) { return(new MethodResponseDTO <int> { Code = -100, Result = 0, Message = "GuardarAsignacion: " + ex.Message }); } } }