public string ActualizarAlertaTotalizacion(TotalizacionContact contacto, string mensaje) { var db = new edayRoomEntities(); var user = db.users.Single(u => u.username == User.Identity.Name); TotalizacionAlerta alerta = (from a in db.TotalizacionAlertas where a.id == contacto.BlockingAlert.Id select a).Single(); if (!string.IsNullOrWhiteSpace(mensaje)) { var alertMessage = new TotalizacionAlertaMessage { fecha = DateTime.Now, mensaje = mensaje, id_usuario=user.id }; alerta.TotalizacionAlertaMessages.Add(alertMessage); } db.SaveChanges(); IQueryable<TotalizacionContactAlertMessage> mensajesAlerta = (from a in alerta.TotalizacionAlertaMessages orderby a.fecha descending select new TotalizacionContactAlertMessage { Id = a.id, Fecha = a.fecha, Message = a.mensaje }).AsQueryable(); return new JavaScriptSerializer().Serialize(""); }
public string AlertaTotalizacion(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 TotalizacionAlerta { activa = true, fecha = DateTime.Now, id_mesa = contacto.MesaId, id_testigoTotalizacion = contacto.IdTestigo, id_alerta = valor, id_usuario = user.id }; db.TotalizacionAlertas.AddObject(alerta); var messages = new List<TotalizacionAlertaMessage>(); if (!string.IsNullOrWhiteSpace(mensaje)) { var alertMessage = new TotalizacionAlertaMessage { fecha = DateTime.Now, mensaje = mensaje , id_usuario = user.id}; alerta.TotalizacionAlertaMessages.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.TotalizacionTimelines where pt.activa && pt.id_mesa == contacto.MesaId //pt.id == contacto.MovilizacionTimelineId select pt); foreach (var oldTimeline in oldTimelines) { oldTimeline.activa = false; } //TotalizacionTimeline oldTimeline = // (from pt in db.TotalizacionTimelines where pt.id == contacto.TotalizacionTimelineId select pt). // Single(); //oldTimeline.activa = false; DateTime newDate = DateTime.Now.AddMinutes(objetoAlerta.tiempo); var newTimeline = new TotalizacionTimeline { id_mesa = contacto.MesaId, //id_parent = oldTimeline.id, fecha = newDate, activa = true }; db.TotalizacionTimelines.AddObject(newTimeline); } #endregion db.SaveChanges(); // VERIFICAR SI HAY QUE HACER TRIGGER DE ALGUNA ALERTA var existingAlerts = from a in db.TotalizacionAlertas where a.id_mesa == contacto.MesaId && 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 TotalizacionAlerta { activa = true, fecha = DateTime.Now, id_mesa = contacto.MesaId, id_testigoTotalizacion = contacto.IdTestigo, id_alerta = newAlerta.id, id_usuario = user.id }; db.TotalizacionAlertas.AddObject(alertaAuto); var alertMessage = new TotalizacionAlertaMessage { fecha = DateTime.Now, mensaje = "Alerta generada por sistema", id_usuario = user.id }; alertaAuto.TotalizacionAlertaMessages.Add(alertMessage); } } db.SaveChanges(); //var newContacto = TotalizacionContact.GetTotalizacionContact(contacto.IdTestigo); return new JavaScriptSerializer().Serialize(""); }
/// <summary> /// Deprecated Method for adding a new object to the TotalizacionAlertaMessages EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToTotalizacionAlertaMessages(TotalizacionAlertaMessage totalizacionAlertaMessage) { base.AddObject("TotalizacionAlertaMessages", totalizacionAlertaMessage); }
/// <summary> /// Create a new TotalizacionAlertaMessage 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 TotalizacionAlertaMessage CreateTotalizacionAlertaMessage(global::System.Int32 id, global::System.Int32 alerta_id, global::System.String mensaje, global::System.DateTime fecha) { TotalizacionAlertaMessage totalizacionAlertaMessage = new TotalizacionAlertaMessage(); totalizacionAlertaMessage.id = id; totalizacionAlertaMessage.alerta_id = alerta_id; totalizacionAlertaMessage.mensaje = mensaje; totalizacionAlertaMessage.fecha = fecha; return totalizacionAlertaMessage; }
public MensajeAlerta(TotalizacionAlertaMessage m) { InitializarMensaje(m.mensaje, m.fecha, m.id_usuario, m.id, m.alerta_id); }