/// <summary> /// Notifica a todos los usuarios con privilegio específico. /// </summary> /// <param name="PRIVS_LLAVE"></param> /// <param name="estado"></param> /// <param name="titulo"></param> /// <param name="mensaje"></param> /// <param name="mensajeParams"></param> public void NotifyUsers(string PRIVS_LLAVE, EstadosNotificacion estado, string titulo, string mensaje, params object[] mensajeParams) { try { List <usuario> usuarios = null; if (string.IsNullOrEmpty(PRIVS_LLAVE)) { Seguridad.UsuarioLogic usuariologic = new Seguridad.UsuarioLogic(); usuarios = usuariologic.GetUsuarios(); } else { Seguridad.PrivilegioLogic privilegiologic = new Seguridad.PrivilegioLogic(); usuarios = privilegiologic.GetUsuariosWithPrivilege(PRIVS_LLAVE); } StringBuilder mensajeBuilder = new StringBuilder(); string mensajeFormateado = mensajeBuilder.AppendFormat(mensaje, mensajeParams).ToString(); using (var db = new colinasEntities()) { foreach (usuario usr in usuarios) { notificacion notification = new notificacion(); notification.NOTIFICACION_ESTADO = (int)estado; notification.USR_USERNAME = usr.USR_USERNAME; notification.NOTIFICACION_TITLE = titulo; //"Notas de Peso en Catación"; notification.NOTIFICACION_MENSAJE = mensajeFormateado; //"Ya tiene disponible la nota de peso #" + note.NOTAS_ID + "."; notification.NOTIFICACION_FECHA = DateTime.Now; db.notificaciones.AddObject(notification); } db.SaveChanges(); } } catch (Exception ex) { log.Fatal("Error fatal al notificar usuarios.", ex); throw; } }
/// <summary> /// Obtiene todas las notas de peso. /// </summary> /// <param name="NOTAS_ID"></param> /// <param name="ESTADOS_NOTA_ID"></param> /// <param name="SOCIOS_ID"></param> /// <param name="SOCIOS_NOMBRE_COMPLETO"></param> /// <param name="CLASIFICACIONES_CAFE_ID"></param> /// <param name="NOTAS_FECHA"></param> /// <param name="FECHA_DESDE"></param> /// <param name="FECHA_HASTA"></param> /// <param name="LoggedUser"></param> /// <returns>Lista de notas de peso.</returns> public List<nota_de_peso> GetNotasDePeso (int NOTAS_ID, int ESTADOS_NOTA_ID, string SOCIOS_ID, string SOCIOS_NOMBRE_COMPLETO, int CLASIFICACIONES_CAFE_ID, DateTime NOTAS_FECHA, DateTime FECHA_DESDE, DateTime FECHA_HASTA, string LoggedUser) { try { using (var db = new colinasEntities()) { db.notas_de_peso.MergeOption = MergeOption.NoTracking; var queryEnPesaje = from notasPesoPesaje in db.notas_de_peso.Include("socios").Include("clasificaciones_cafe").Include("estados_nota_de_peso") where (notasPesoPesaje.estados_nota_de_peso.estados_detalles.ESTADOS_DETALLE_ENABLE_SOCIO_ID == (int)COCASJOL.LOGIC.Socios.SociosLogic.HabilitarSocios.MostrarTodos ? true : notasPesoPesaje.socios.SOCIOS_ESTATUS >= 1) && (string.IsNullOrEmpty(SOCIOS_NOMBRE_COMPLETO) ? true : (notasPesoPesaje.socios.SOCIOS_PRIMER_NOMBRE + notasPesoPesaje.socios.SOCIOS_SEGUNDO_NOMBRE + notasPesoPesaje.socios.SOCIOS_PRIMER_APELLIDO + notasPesoPesaje.socios.SOCIOS_SEGUNDO_APELLIDO).Contains(SOCIOS_NOMBRE_COMPLETO)) select notasPesoPesaje; if (LoggedUser != "DEVELOPER") { COCASJOL.LOGIC.Seguridad.UsuarioLogic usuariologic = new Seguridad.UsuarioLogic(); List<privilegio> privilegios = usuariologic.GetPrivilegiosParaNotaDePesoDeUsuario(LoggedUser); List<string> privLlaves = privilegios.Select(p => p.PRIV_LLAVE).ToList<string>(); var querySeguridad = from notasSeguridad in queryEnPesaje where privLlaves.Contains(EstadoNotaDePesoLogic.PREFIJO_PRIVILEGIO + notasSeguridad.estados_nota_de_peso.ESTADOS_NOTA_LLAVE) select notasSeguridad; var query = from notasPeso in querySeguridad where (NOTAS_ID.Equals(0) ? true : notasPeso.NOTAS_ID.Equals(NOTAS_ID)) && (ESTADOS_NOTA_ID.Equals(0) ? true : notasPeso.ESTADOS_NOTA_ID.Equals(ESTADOS_NOTA_ID)) && (string.IsNullOrEmpty(SOCIOS_ID) ? true : notasPeso.SOCIOS_ID.Contains(SOCIOS_ID)) && (CLASIFICACIONES_CAFE_ID.Equals(0) ? true : notasPeso.CLASIFICACIONES_CAFE_ID.Equals(CLASIFICACIONES_CAFE_ID)) && (default(DateTime) == FECHA_DESDE ? true : notasPeso.NOTAS_FECHA >= FECHA_DESDE) && (default(DateTime) == FECHA_HASTA ? true : notasPeso.NOTAS_FECHA <= FECHA_HASTA) select notasPeso; return query.OrderBy(n => n.SOCIOS_ID).OrderByDescending(n => n.FECHA_MODIFICACION).OrderByDescending(n => n.NOTAS_FECHA).ToList<nota_de_peso>(); } else { var query = from notasPeso in queryEnPesaje where (NOTAS_ID.Equals(0) ? true : notasPeso.NOTAS_ID.Equals(NOTAS_ID)) && (ESTADOS_NOTA_ID.Equals(0) ? true : notasPeso.ESTADOS_NOTA_ID.Equals(ESTADOS_NOTA_ID)) && (string.IsNullOrEmpty(SOCIOS_ID) ? true : notasPeso.SOCIOS_ID.Contains(SOCIOS_ID)) && (CLASIFICACIONES_CAFE_ID.Equals(0) ? true : notasPeso.CLASIFICACIONES_CAFE_ID.Equals(CLASIFICACIONES_CAFE_ID)) && (default(DateTime) == FECHA_DESDE ? true : notasPeso.NOTAS_FECHA >= FECHA_DESDE) && (default(DateTime) == FECHA_HASTA ? true : notasPeso.NOTAS_FECHA <= FECHA_HASTA) select notasPeso; return query.OrderBy(n => n.SOCIOS_ID).OrderByDescending(n => n.FECHA_MODIFICACION).OrderByDescending(n => n.NOTAS_FECHA).ToList<nota_de_peso>(); } } } catch (Exception ex) { log.Fatal("Error fatal al obtener notas de peso.", ex); throw; } }
/// <summary> /// Notifica a todos los usuarios con privilegio específico. /// </summary> /// <param name="PRIVS_LLAVE"></param> /// <param name="estado"></param> /// <param name="titulo"></param> /// <param name="mensaje"></param> /// <param name="mensajeParams"></param> public void NotifyUsers(string PRIVS_LLAVE, EstadosNotificacion estado, string titulo, string mensaje, params object[] mensajeParams) { try { List<usuario> usuarios = null; if (string.IsNullOrEmpty(PRIVS_LLAVE)) { Seguridad.UsuarioLogic usuariologic = new Seguridad.UsuarioLogic(); usuarios = usuariologic.GetUsuarios(); } else { Seguridad.PrivilegioLogic privilegiologic = new Seguridad.PrivilegioLogic(); usuarios = privilegiologic.GetUsuariosWithPrivilege(PRIVS_LLAVE); } StringBuilder mensajeBuilder = new StringBuilder(); string mensajeFormateado = mensajeBuilder.AppendFormat(mensaje, mensajeParams).ToString(); using (var db = new colinasEntities()) { foreach (usuario usr in usuarios) { notificacion notification = new notificacion(); notification.NOTIFICACION_ESTADO = (int)estado; notification.USR_USERNAME = usr.USR_USERNAME; notification.NOTIFICACION_TITLE = titulo; //"Notas de Peso en Catación"; notification.NOTIFICACION_MENSAJE = mensajeFormateado ; //"Ya tiene disponible la nota de peso #" + note.NOTAS_ID + "."; notification.NOTIFICACION_FECHA = DateTime.Now; db.notificaciones.AddObject(notification); } db.SaveChanges(); } } catch (Exception ex) { log.Fatal("Error fatal al notificar usuarios.", ex); throw; } }
/// <summary> /// Obtiene todas las notas de peso. /// </summary> /// <param name="NOTAS_ID"></param> /// <param name="ESTADOS_NOTA_ID"></param> /// <param name="SOCIOS_ID"></param> /// <param name="SOCIOS_NOMBRE_COMPLETO"></param> /// <param name="CLASIFICACIONES_CAFE_ID"></param> /// <param name="NOTAS_FECHA"></param> /// <param name="FECHA_DESDE"></param> /// <param name="FECHA_HASTA"></param> /// <param name="LoggedUser"></param> /// <returns>Lista de notas de peso.</returns> public List <nota_de_peso> GetNotasDePeso (int NOTAS_ID, int ESTADOS_NOTA_ID, string SOCIOS_ID, string SOCIOS_NOMBRE_COMPLETO, int CLASIFICACIONES_CAFE_ID, DateTime NOTAS_FECHA, DateTime FECHA_DESDE, DateTime FECHA_HASTA, string LoggedUser) { try { using (var db = new colinasEntities()) { db.notas_de_peso.MergeOption = MergeOption.NoTracking; var queryEnPesaje = from notasPesoPesaje in db.notas_de_peso.Include("socios").Include("clasificaciones_cafe").Include("estados_nota_de_peso") where (notasPesoPesaje.estados_nota_de_peso.estados_detalles.ESTADOS_DETALLE_ENABLE_SOCIO_ID == (int)COCASJOL.LOGIC.Socios.SociosLogic.HabilitarSocios.MostrarTodos ? true : notasPesoPesaje.socios.SOCIOS_ESTATUS >= 1) && (string.IsNullOrEmpty(SOCIOS_NOMBRE_COMPLETO) ? true : (notasPesoPesaje.socios.SOCIOS_PRIMER_NOMBRE + notasPesoPesaje.socios.SOCIOS_SEGUNDO_NOMBRE + notasPesoPesaje.socios.SOCIOS_PRIMER_APELLIDO + notasPesoPesaje.socios.SOCIOS_SEGUNDO_APELLIDO).Contains(SOCIOS_NOMBRE_COMPLETO)) select notasPesoPesaje; if (LoggedUser != "DEVELOPER") { COCASJOL.LOGIC.Seguridad.UsuarioLogic usuariologic = new Seguridad.UsuarioLogic(); List <privilegio> privilegios = usuariologic.GetPrivilegiosParaNotaDePesoDeUsuario(LoggedUser); List <string> privLlaves = privilegios.Select(p => p.PRIV_LLAVE).ToList <string>(); var querySeguridad = from notasSeguridad in queryEnPesaje where privLlaves.Contains(EstadoNotaDePesoLogic.PREFIJO_PRIVILEGIO + notasSeguridad.estados_nota_de_peso.ESTADOS_NOTA_LLAVE) select notasSeguridad; var query = from notasPeso in querySeguridad where (NOTAS_ID.Equals(0) ? true : notasPeso.NOTAS_ID.Equals(NOTAS_ID)) && (ESTADOS_NOTA_ID.Equals(0) ? true : notasPeso.ESTADOS_NOTA_ID.Equals(ESTADOS_NOTA_ID)) && (string.IsNullOrEmpty(SOCIOS_ID) ? true : notasPeso.SOCIOS_ID.Contains(SOCIOS_ID)) && (CLASIFICACIONES_CAFE_ID.Equals(0) ? true : notasPeso.CLASIFICACIONES_CAFE_ID.Equals(CLASIFICACIONES_CAFE_ID)) && (default(DateTime) == FECHA_DESDE ? true : notasPeso.NOTAS_FECHA >= FECHA_DESDE) && (default(DateTime) == FECHA_HASTA ? true : notasPeso.NOTAS_FECHA <= FECHA_HASTA) select notasPeso; return(query.OrderBy(n => n.SOCIOS_ID).OrderByDescending(n => n.FECHA_MODIFICACION).OrderByDescending(n => n.NOTAS_FECHA).ToList <nota_de_peso>()); } else { var query = from notasPeso in queryEnPesaje where (NOTAS_ID.Equals(0) ? true : notasPeso.NOTAS_ID.Equals(NOTAS_ID)) && (ESTADOS_NOTA_ID.Equals(0) ? true : notasPeso.ESTADOS_NOTA_ID.Equals(ESTADOS_NOTA_ID)) && (string.IsNullOrEmpty(SOCIOS_ID) ? true : notasPeso.SOCIOS_ID.Contains(SOCIOS_ID)) && (CLASIFICACIONES_CAFE_ID.Equals(0) ? true : notasPeso.CLASIFICACIONES_CAFE_ID.Equals(CLASIFICACIONES_CAFE_ID)) && (default(DateTime) == FECHA_DESDE ? true : notasPeso.NOTAS_FECHA >= FECHA_DESDE) && (default(DateTime) == FECHA_HASTA ? true : notasPeso.NOTAS_FECHA <= FECHA_HASTA) select notasPeso; return(query.OrderBy(n => n.SOCIOS_ID).OrderByDescending(n => n.FECHA_MODIFICACION).OrderByDescending(n => n.NOTAS_FECHA).ToList <nota_de_peso>()); } } } catch (Exception ex) { log.Fatal("Error fatal al obtener notas de peso.", ex); throw; } }