コード例 #1
0
        public string UpdateSingleExitPoll(int exitpollId, CandidatoValueIncoming[] valores)
        {
            var db = new edayRoomEntities();

            ExitPollTimeline oldTimeline = (from pt in db.ExitPollTimelines
                                            where pt.id == exitpollId
                                            select pt).Single();

            db.SaveChanges();


            foreach (CandidatoValueIncoming v in valores)
            {
                int idCandidato = int.Parse(v.name.Replace("candidato-", ""));
                int valor       = v.value;
                ExitPoll
                    ep = oldTimeline.ExitPolls.Single(e => e.id_candidato == idCandidato);
                ep.valor = valor;
            }

            db.SaveChanges();


            return(new JavaScriptSerializer().Serialize(""));
        }
コード例 #2
0
        public string UpdateExitPoll(ExitPollContact contacto, CandidatoValueIncoming[] valores)
        {
            var db   = new edayRoomEntities();
            var user = db.users.Single(u => u.username == User.Identity.Name);

            ExitPollTimeline oldTimeline = (from pt in db.ExitPollTimelines
                                            where pt.id == contacto.ExitPollTimelineId
                                            select pt).Single();

            oldTimeline.activa = false;
            db.SaveChanges();

            DateTime newDate     = contacto.QuickCountActive ? DateTime.Now.AddMinutes(45) : DateTime.Now.AddMinutes(60);
            var      newTimeline = new ExitPollTimeline
            {
                id_centro          = contacto.CentroId,
                fecha              = newDate,
                id_testigoExitPoll = contacto.IdTestigo,
                activa             = true,
                id_parent          = oldTimeline.id
            };

            db.ExitPollTimelines.AddObject(newTimeline);
            db.SaveChanges();

            foreach (CandidatoValueIncoming v in valores)
            {
                var ep = new ExitPoll
                {
                    id_candidato       = int.Parse(v.name.Replace("candidato-", "")),
                    id_centro          = contacto.CentroId,
                    id_testigoExitPoll = contacto.IdTestigo,
                    id_timeline        = newTimeline.id,
                    valor   = v.value,
                    fecha   = DateTime.Now,
                    id_user = user.id
                };
                db.ExitPolls.AddObject(ep);
            }

            IQueryable <ExitPollAlerta> alertas = from a in db.ExitPollAlertas
                                                  where a.activa && !a.Alerta.blocking &&
                                                  a.id_centro == contacto.CentroId
                                                  select a;

            foreach (ExitPollAlerta a in alertas)
            {
                a.activa = false;
            }

            db.SaveChanges();
            //var newContacto = ExitPollsContact.GetExitPollsContact(contacto.IdTestigo);


            return(new JavaScriptSerializer().Serialize(contacto));
        }
コード例 #3
0
        public string AlertaExitPolls(ExitPollContact 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 ExitPollAlerta
            {
                activa             = true,
                fecha              = DateTime.Now,
                id_centro          = contacto.CentroId,
                id_testigoExitPoll = contacto.IdTestigo,
                id_alerta          = valor,
                id_usuario         = user.id
            };
            db.ExitPollAlertas.AddObject(alerta);


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

            #endregion

            #region  Retraso de Timeline

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

            if (objetoAlerta.regresivo)
            {
                ExitPollTimeline oldTimeline =
                    (from pt in db.ExitPollTimelines where pt.id == contacto.ExitPollTimelineId select pt).
                    Single();
                oldTimeline.activa = false;
                DateTime newDate     = DateTime.Now.AddMinutes(objetoAlerta.tiempo);
                var      newTimeline = new ExitPollTimeline
                {
                    id_centro          = contacto.CentroId,
                    id_testigoExitPoll = contacto.IdTestigo,
                    id_parent          = oldTimeline.id,
                    fecha  = newDate,
                    activa = true
                };
                db.ExitPollTimelines.AddObject(newTimeline);
            }

            #endregion

            db.SaveChanges();


            // VERIFICAR SI HAY QUE HACER TRIGGER DE ALGUNA ALERTA
            IQueryable <ExitPollAlerta> existingAlerts = from a in db.ExitPollAlertas
                                                         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 ExitPollAlerta
                    {
                        activa             = true,
                        fecha              = DateTime.Now,
                        id_centro          = contacto.CentroId,
                        id_testigoExitPoll = contacto.IdTestigo,
                        id_alerta          = newAlerta.id,
                        id_usuario         = user.id
                    };
                    db.ExitPollAlertas.AddObject(alertaAuto);

                    var alertMessage = new ExitPollAlertaMessage {
                        fecha = DateTime.Now, mensaje = "Alerta generada por sistema", id_usuario = user.id
                    };
                    alertaAuto.ExitPollAlertaMessages.Add(alertMessage);
                }
            }
            db.SaveChanges();
            //var newContacto = ExitPollContact.GetExitPollContact(contacto.IdTestigo);
            return(new JavaScriptSerializer().Serialize(""));
        }