예제 #1
0
        public string ActualizarAlertaQuickCount(TotalizacionContact contacto, string mensaje)
        {
            var db = new edayRoomEntities();
            var user = db.users.Single(u => u.username == User.Identity.Name);
            QuickCountAlerta alerta = (from a in db.QuickCountAlertas
                                       where a.id == contacto.BlockingAlert.Id
                                       select a).Single();

            if (!string.IsNullOrWhiteSpace(mensaje))
            {
                var alertMessage = new QuickCountAlertaMessage { fecha = DateTime.Now, mensaje = mensaje, id_usuario = user.id};
                alerta.QuickCountAlertaMessages.Add(alertMessage);
            }

            db.SaveChanges();
            IQueryable<TotalizacionContactAlertMessage> mensajesAlerta = (from a in alerta.QuickCountAlertaMessages
                                                                          orderby a.fecha descending
                                                                          select new TotalizacionContactAlertMessage
                                                                                     {
                                                                                         Id = a.id,
                                                                                         Fecha = a.fecha,
                                                                                         Message = a.mensaje
                                                                                     }).AsQueryable();

            return new JavaScriptSerializer().Serialize("");
        }
예제 #2
0
 /// <summary>
 /// Create a new QuickCountAlertaMessage object.
 /// </summary>
 /// <param name="id">Initial value of the id property.</param>
 /// <param name="alerta_id">Initial value of the alerta_id property.</param>
 /// <param name="mensaje">Initial value of the mensaje property.</param>
 /// <param name="fecha">Initial value of the fecha property.</param>
 public static QuickCountAlertaMessage CreateQuickCountAlertaMessage(global::System.Int32 id, global::System.Int32 alerta_id, global::System.String mensaje, global::System.DateTime fecha)
 {
     QuickCountAlertaMessage quickCountAlertaMessage = new QuickCountAlertaMessage();
     quickCountAlertaMessage.id = id;
     quickCountAlertaMessage.alerta_id = alerta_id;
     quickCountAlertaMessage.mensaje = mensaje;
     quickCountAlertaMessage.fecha = fecha;
     return quickCountAlertaMessage;
 }
예제 #3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the QuickCountAlertaMessages EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToQuickCountAlertaMessages(QuickCountAlertaMessage quickCountAlertaMessage)
 {
     base.AddObject("QuickCountAlertaMessages", quickCountAlertaMessage);
 }
예제 #4
0
        public string AlertaQuickCount(TotalizacionContact contacto, int valor, string mensaje)
        {
            var db = new edayRoomEntities();
            var user = db.users.Single(u => u.username == User.Identity.Name);
            #region Registro la alerta

            var alerta = new QuickCountAlerta
                             {
                                 activa = true,
                                 fecha = DateTime.Now,
                                 id_centro = contacto.CentroId,
                                 id_alerta = valor,
                                 id_usuario = user.id
                             };
            db.QuickCountAlertas.AddObject(alerta);

            var messages = new List<QuickCountAlertaMessage>();
            if (!string.IsNullOrWhiteSpace(mensaje))
            {
                var alertMessage = new QuickCountAlertaMessage { fecha = DateTime.Now, mensaje = mensaje, id_usuario = user.id };
                alerta.QuickCountAlertaMessages.Add(alertMessage);
                messages.Add(alertMessage);
            }

            #endregion

            #region  Retraso de Timeline

            Alerta objetoAlerta = db.Alertas.Single(a => a.id == valor);

            if (objetoAlerta.regresivo)
            {
                var oldTimelines =
                   (from pt in db.QuickCountTimelines
                    where
                        pt.activa && pt.id_centro == contacto.CentroId
                    //pt.id == contacto.MovilizacionTimelineId
                    select pt);
                foreach (var oldTimeline in oldTimelines)
                {
                    oldTimeline.activa = false;
                }

                //QuickCountTimeline oldTimeline =
                //    (from pt in db.QuickCountTimelines where pt.id == contacto.TotalizacionTimelineId select pt).
                //        Single();
                //oldTimeline.activa = false;
                DateTime newDate = DateTime.Now.AddMinutes(objetoAlerta.tiempo);
                var newTimeline = new QuickCountTimeline
                                      {
                                          id_centro = contacto.CentroId,
                                          fecha = newDate,
                                          activa = true
                                      };
                db.QuickCountTimelines.AddObject(newTimeline);
            }

            #endregion

            db.SaveChanges();

            // VERIFICAR SI HAY QUE HACER TRIGGER DE ALGUNA ALERTA
            IQueryable<QuickCountAlerta> existingAlerts = from a in db.QuickCountAlertas
                                                          where a.id_centro == contacto.CentroId &&
                                                                a.id_alerta == valor && a.activa
                                                          select a;
            int alertCount = existingAlerts.Count();
            int maxRepeats = existingAlerts.First().Alerta.maxRepeats ?? 0;
            if (maxRepeats != 0)
            {
                if (alertCount == maxRepeats)
                {
                    //LLEGUE AL LIMITE, hago el trigger de la alerta
                    Alerta newAlerta = existingAlerts.First().Alerta.AlertaAsociada;
                    var alertaAuto = new QuickCountAlerta
                                         {
                                             activa = true,
                                             fecha = DateTime.Now,
                                             id_centro = contacto.CentroId,
                                             id_alerta = newAlerta.id,
                                             id_usuario = user.id
                                         };
                    db.QuickCountAlertas.AddObject(alertaAuto);

                    var alertMessage = new QuickCountAlertaMessage { fecha = DateTime.Now, mensaje = "Alerta generada por sistema", id_usuario = user.id };
                    alertaAuto.QuickCountAlertaMessages.Add(alertMessage);
                }
            }
            db.SaveChanges();

            //var newContacto = TotalizacionContact.GetTotalizacionContact(contacto.IdTestigo);
            return new JavaScriptSerializer().Serialize("");
        }
예제 #5
0
 public MensajeAlerta(QuickCountAlertaMessage m)
 {
     InitializarMensaje(m.mensaje, m.fecha, m.id_usuario, m.id, m.alerta_id);
 }