/// <summary> /// Obtiene la sesion. Si no se ha guardado sesion retorna null /// </summary> /// <returns></returns> public SesionModel GetSesion() { SesionModel sesion = null; using (var entity = new Nosc.DAL.NoscDBEntities()) { try { var s = (from o in entity.CAT_SESION.Include("APP_USUARIO") select o).First<CAT_SESION>(); sesion = new SesionModel(); sesion.User = new UsuarioModel() { IdUsuario = s.IdUsuario, NombreUsuario = s.APP_USUARIO.Nombre, UsuarioCorreo = s.APP_USUARIO.UsuarioCorreo, Puesto = s.APP_USUARIO.Puesto, Apellido = s.APP_USUARIO.Apellido, Area=s.APP_USUARIO.Area, UsuarioPwd=s.APP_USUARIO.UsuarioCorreo, IsActive = s.APP_USUARIO.IsActive }; sesion.NoCerrarSesion = s.IsSaveSesion; } catch (Exception ex) { } } return sesion; }
/// <summary> /// Guarda la ultima sesión exitosa /// </summary> /// <param name="sesion"></param> public void SetSesion(SesionModel sesion) { using (var entity = new Nosc.DAL.NoscDBEntities()) { try { var s = (from o in entity.CAT_SESION.Include("APP_USUARIO") select o).FirstOrDefault(); if (s != null) { s.IdUsuario = sesion.User.IdUsuario; s.IsSaveSesion = sesion.NoCerrarSesion; } else { entity.CAT_SESION.AddObject(new CAT_SESION() { IdSesion=1, IdUsuario=sesion.User.IdUsuario, IsSaveSesion = sesion.NoCerrarSesion }); } entity.SaveChanges(); } catch (Exception ex) { } } }
public List<string> GetIsModified() { List<string> lst = null; using (var entity = new NoscDBEntities()) { lst = new List<string>(); (from md in entity.MODIFIEDDATA join s in entity.SYNCTABLE on md.IdSyncTable equals s.IdSyncTable where md.IsModified == true orderby s.OrderTable ascending select new { s.SyncTableName }).ToList().ForEach(row => lst.Add(row.SyncTableName) ); if (lst.Count > 0) { return lst; } else { return null; } } }
/// <summary> /// Inserta una nueva notificacion en la tabla /// </summary> /// <param name="notif"></param> public void InsertNotification(NotificacionModel notif) { using (var entity = new Nosc.DAL.NoscDBEntities()) { var res = (from o in entity.Notificacions where o.IdNotificacion == notif.IdNotificacion select o).FirstOrDefault(); //insertar elemento ya que no existe if (res == null) { entity.Notificacions.AddObject(new Notificacion() { Titulo=notif.Titulo, Mensaje=notif.Mensaje, Parametro=notif.Parametro, IdApp=notif.App.IdApp, IdUsuario=notif.Usuario.IdUsuario, FechaCreacion=notif.FechaCreacion, FechaNotificacion=notif.FechaNotificacion }); } entity.SaveChanges(); } }
/// <summary> /// En base al nombre del usuario obtener su informacion /// </summary> /// <param name="userMail"></param> /// <returns></returns> public UsuarioModel GetUsuario(string userMail) { UsuarioModel um = null; using (var entity = new Nosc.DAL.NoscDBEntities()) { try { var res = (from o in entity.APP_USUARIO where o.UsuarioCorreo == userMail select o).First<APP_USUARIO>(); um = new UsuarioModel() { IdUsuario = res.IdUsuario, NombreUsuario = res.Nombre, Area = res.Area, Apellido =res.Apellido, Puesto = res.Puesto, UsuarioCorreo =res.UsuarioCorreo, UsuarioPwd =res.UsuarioPwd, IsActive = res.IsActive }; } catch (Exception ex) { ; } } return um; }
public string GetJsonTable(string tableName) { using (var entity = new NoscDBEntities()) { string json = entity.SP_TABLE_JSON(tableName).First<string>(); return json; } }
/// <summary> /// Metodo que manda a llamar el procedimiento almacenado "SP_UpdateModifiedDataLocal". /// </summary> /// <param name="nomTbl">Nombre de una tabla.</param> /// <param name="jsonTable">Registros de una tabla en formato JSON.</param> /// <returns>Retorna un mensaje de "OK"</returns> public string SP_UpdateModifiedDataLocal(string nomTbl, string jsonTable) { string res = ""; using (var entity = new NoscDBEntities()) { res = entity.SP_UpdateModifiedDataLocal(nomTbl, jsonTable).First<string>(); } return res; }
public bool _SpConfirmSincRows(string json, string tableName) { bool x = false; using (var entity = new NoscDBEntities()) { entity.SpConfirmSincRows(json, tableName); return x = true; } }
/// <summary> /// Metodo que manda a llamar el procedimiento almacenado "SP_GetTableNameModifiedData". /// </summary> /// <param name="jsonModifiedServer"></param> /// <returns>Retorna una lista de Strings con los nombres de las tablas que se van a sincronizar</returns> public List<string> GetTableNameModifiedData(string jsonModifiedServer) { List<string> lst = null; using (var entity = new NoscDBEntities()) { lst = entity.SP_GetTableNameModifiedData(jsonModifiedServer).ToList<string>(); } return lst; }
/// <summary> /// Metodo que manda a llamar el procedimiento almacenado "SP_GetMax". /// </summary> /// <param name="tableName">Nombre de una tabla</param> /// <returns>Retorna una cadena de string en formato JSON con el registro maximo de una tabla.</returns> public string GetMaxTableLocal(string tableName) { string res = ""; using (var entity = new NoscDBEntities()) { res = entity.SP_GetMax(tableName).First<string>(); } return res; }
/// <summary> /// Metodo que manda a llamar el procedimiento almacenado "SpUpsertServerRows". /// </summary> /// <param name="jsonTable">Registros de la tabla en formato JSON que se van a insertar o actualizar.</param> /// <param name="tableName">Nombre de una tabla.</param> /// <returns>Retorna el Id de los registros que se insertaron o actualizaron </returns> public string SpUpsertServerRows(string jsonTable, string tableName) { string res = ""; using (var entity = new NoscDBEntities()) { res = entity.SP_Upsert_Server_Rows(jsonTable, tableName).First<string>(); } return res; }
public ObservableCollection<NotificacionModel> LoadNotifications(UsuarioModel user) { ObservableCollection<NotificacionModel> notifications = new ObservableCollection<NotificacionModel>(); long fechaActual = new UNID().getNewUNID(); using (var entity = new Nosc.DAL.NoscDBEntities()) { try { //obtine las notificaciones con validaciones (from o in entity.Notificacions.Include("CAT_APP") where o.APP_USUARIO.IdUsuario == user.IdUsuario && o.IsNotificacionActiva && o.FechaNotificacion <= fechaActual select new { o, NotificacionActive = o.NOTIFICACION_ACTIVA.Select (s => new Model.NotificacionActivaModel() { IdNotificacion = s.IdNotificacion , IdNotificacionActiva = s.IdNotificacionActiva , IsActive = s.IsActive } ) }).ToList().ForEach(p => { notifications.Add(new NotificacionModel() { App = new AppModel() { AppName = p.o.CAT_APP.AppName, AppIconPath = p.o.CAT_APP.AppIcon, IdApp = p.o.CAT_APP.IdApp }, FechaCreacion = p.o.FechaCreacion, IdNotificacion = p.o.IdNotificacion, Mensaje = p.o.Mensaje, Parametro = p.o.Parametro, Titulo = p.o.Titulo, FechaNotificacion = p.o.FechaNotificacion, Recurrencia = p.o.Recurrencia, FechaUltimaMuestra = p.o.FechaUltimaMuestra, NotificacionActiva = p.NotificacionActive, IdUsuario = p.o.APP_USUARIO.IdUsuario, Usuario = new UsuarioModel() { IdUsuario = p.o.APP_USUARIO.IdUsuario } }); }); } catch (Exception ex) { } } return notifications; }
/// <summary> /// Actualiza la fecha Fecha Ultima Muestra en la tabla NOTIFICACION_ACTIVA /// </summary> /// <param name="notif"></param> public void UpdateNotificationRecurrencia(NotificacionModel notif) { using (var entity = new Nosc.DAL.NoscDBEntities()) { if (notif != null) { Notificacion result = null; try { result = (from o in entity.Notificacions where o.IdNotificacion == notif.IdNotificacion && o.Recurrencia > 0 select o).FirstOrDefault(); } catch (Exception) { } //actualiza if (result != null) { result.FechaUltimaMuestra = notif.FechaUltimaMuestra; } entity.SaveChanges(); } } }
/// <summary> /// Actualiza la fecha Fecha Ultima Muestra en la tabla NOTIFICACION_ACTIVA /// </summary> /// <param name="notif"></param> public void UpdateNotificationRecurrencia(ObservableCollection<NotificacionModel> notifs) { using (var entity = new Nosc.DAL.NoscDBEntities()) { if (notifs.Count != 0) { notifs.ToList().ForEach(p => { Notificacion result = null; try { result = (from o in entity.Notificacions where o.IdNotificacion == p.IdNotificacion && o.Recurrencia > 0 select o).FirstOrDefault(); } catch (Exception) { } //actualiza if (result != null) { result.FechaUltimaMuestra = p.FechaUltimaMuestra; } }); entity.SaveChanges(); } } }
/// <summary> /// Actualiza o inserta cuando una notifcacion esta activa /// </summary> /// <param name="notif"></param> public void UpdateNotificationActiva( ObservableCollection<NotificacionModel> notifs) { using (var entity = new Nosc.DAL.NoscDBEntities()) { if (notifs.Count !=0) { notifs.ToList().ForEach(p => { NOTIFICACION_ACTIVA result = null; try { result = (from o in entity.NOTIFICACION_ACTIVA where o.IdNotificacion == p.IdNotificacion select o).FirstOrDefault(); } catch (Exception) { } //actualiza if (result != null && !result.IsActive) { result.IsActive = true; } //inserta if (result == null) { entity.NOTIFICACION_ACTIVA.AddObject( new NOTIFICACION_ACTIVA() { IdNotificacion = p.IdNotificacion , IdNotificacionActiva = new UNID().getNewUNID() , IsActive = true }); } }); entity.SaveChanges(); } } }
/// <summary> /// Actualiza un registro /// </summary> /// <param name="notif"></param> public void UpdateNotification(NotificacionModel notif) { using (var entity = new Nosc.DAL.NoscDBEntities()) { var res = (from o in entity.Notificacions where o.IdNotificacion == notif.IdNotificacion select o).FirstOrDefault(); //actualiza el elemento ya que no existe if (res != null) { res.Titulo = notif.Titulo; res.Mensaje = notif.Mensaje; res.Parametro = notif.Parametro; res.IdApp = notif.App.IdApp; res.IdUsuario = notif.Usuario.IdUsuario; res.FechaCreacion = notif.FechaCreacion; res.FechaNotificacion = notif.FechaNotificacion; res.IsDescartarOnClick = notif.IsDescartarOnClick; res.IsNotificacionActiva = notif.IsNotificacionActiva; } entity.SaveChanges(); } }
/// <summary> /// Actualiza todas las banderas en IsActive en false /// </summary> public void ResetNotificationActiva() { using (var entity = new Nosc.DAL.NoscDBEntities()) { IEnumerable<NOTIFICACION_ACTIVA> result = new ObservableCollection<NOTIFICACION_ACTIVA>(); try { result = (from o in entity.NOTIFICACION_ACTIVA select o).ToList(); (from o in result select o).ToList().ForEach(p=> p.IsActive=false); entity.SaveChanges(); } catch (Exception) { } } }
public void LoadUsuario(List<Model.SynClases.APP_USUARIO> element) { try { if (element != null) { using (NoscDBEntities entity = new NoscDBEntities()) { element.ToList().ForEach(p => { var query = (from cust in entity.APP_USUARIO where p.IdUsuario == cust.IdUsuario select cust).ToList(); //Actualización if (query.Count > 0) { var aux = query.First(); if (aux.LastModifiedDate < p.LastModifiedDate) this.UpdateUsuario(p, entity); } //Inserción else this.InsertUsuario(p, entity); }); } } } catch (Exception) { throw; } }