/// <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) { } } }
/// <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> /// 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) { } } }