// GET: Cliente/Inteligentes
        public ActionResult Index()
        {
            var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));
            var user        = UserManager.FindById(User.Identity.GetUserId());

            BaseRepositorio <Inteligente> repoInteligente = new BaseRepositorio <Inteligente>();

            var inteligentes = repoInteligente.Filter(i => i.Clientes.Any(c => c.NombreUsuario == user.UserName));

            return(View(inteligentes));
        }
        // GET: Cliente/Reglas
        public ActionResult Index()
        {
            ViewBag.reglas = ObtenerReglasActivas();

            var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));
            var user        = UserManager.FindById(User.Identity.GetUserId());

            BaseRepositorio <Inteligente> repoInteligente = new BaseRepositorio <Inteligente>();

            ViewBag.tieneDispositivos = repoInteligente.Filter(i => i.Clientes.Any(c => c.NombreUsuario == user.UserName)).Count > 0;

            return(View());
        }
Exemplo n.º 3
0
        private ICollection <Inteligente> ObtenerEstadosDispositivos()
        {
            var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));
            var user        = UserManager.FindById(User.Identity.GetUserId());

            BaseRepositorio <Inteligente> repoInteligente = new BaseRepositorio <Inteligente>();
            var includesInteligente = new List <Expression <Func <Inteligente, object> > >()
            {
                i => i.RegistroDeActivaciones
            };

            var inteligentes = repoInteligente.Filter(i => i.Clientes.Any(c => c.NombreUsuario == user.UserName), includesInteligente);

            return(inteligentes);
        }
        public ActionResult Agregar()
        {
            var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));
            var user        = UserManager.FindById(User.Identity.GetUserId());

            BaseRepositorio <Inteligente> repoInteligente = new BaseRepositorio <Inteligente>();

            ViewBag.inteligentes = repoInteligente.Filter(i => i.Clientes.Any(c => c.NombreUsuario == user.UserName));

            BaseRepositorio <Operador> repoOperador = new BaseRepositorio <Operador>();

            ViewBag.Operadores = new SelectList(repoOperador.GetAll(), "Id", "Descripcion");

            return(View());
        }
        private Dictionary <string, double> ejecucionSimplex()
        {
            var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));
            var user        = UserManager.FindById(User.Identity.GetUserId());

            SGEContext db = new SGEContext();

            BaseRepositorio <Inteligente> repoInteligente = new BaseRepositorio <Inteligente>(db);
            var includesCliente = new List <Expression <Func <Inteligente, object> > >()
            {
                i => i.RegistroDeActivaciones,
                i => i.Clientes
            };
            List <Inteligente> inteligentes = repoInteligente.Filter(i => i.Clientes.Any(c => c.NombreUsuario == user.UserName), includesCliente);

            Cliente cliente = new Cliente();

            cliente.Inteligentes = inteligentes;

            return(cliente.HogarEficiente());
        }
Exemplo n.º 6
0
        private ICollection <dynamic> ObtenerUltimasMediciones()
        {
            var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));
            var user        = UserManager.FindById(User.Identity.GetUserId());
            ICollection <dynamic> salida = new List <dynamic>();

            SGEContext contexto = new SGEContext();

            BaseRepositorio <Inteligente> repoInteligente = new BaseRepositorio <Inteligente>(contexto);
            var includesInteligente = new List <Expression <Func <Inteligente, object> > >()
            {
                i => i.Catalogo
            };

            var inteligentes = repoInteligente.Filter(i => i.Clientes.Any(c => c.NombreUsuario == user.UserName), includesInteligente);

            BaseRepositorio <Medicion> repoMedicion = new BaseRepositorio <Medicion>(contexto);

            foreach (Inteligente inteligente in inteligentes)
            {
                if (inteligente.Catalogo.Sensores != null && inteligente.Catalogo.Sensores.Count > 0)
                {
                    foreach (SensorFisico sensor in inteligente.Sensores)
                    {
                        dynamic customMedicion = new ExpandoObject();
                        customMedicion.dispositivo = inteligente.Nombre;
                        customMedicion.sensor      = sensor.Id;
                        customMedicion.medicion    = sensor.Mediciones.LastOrDefault();

                        salida.Add(customMedicion);
                    }
                }
            }

            return(salida);
        }
Exemplo n.º 7
0
        private ICollection <dynamic> ObtenerReglasActivas()
        {
            ICollection <dynamic> salida = new List <dynamic>();

            var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));
            var user        = UserManager.FindById(User.Identity.GetUserId());

            SGEContext contexto = new SGEContext();

            BaseRepositorio <Inteligente> repoInteligente = new BaseRepositorio <Inteligente>(contexto);
            var includesInteligente = new List <Expression <Func <Inteligente, object> > >()
            {
                i => i.Reglas
            };

            var inteligentes = repoInteligente.Filter(i => i.Clientes.Any(c => c.NombreUsuario == user.UserName), includesInteligente);

            BaseRepositorio <Accion> repoAccion = new BaseRepositorio <Accion>(contexto);
            var includesAccion = new List <Expression <Func <Accion, object> > >()
            {
                a => a.Reglas
            };

            BaseRepositorio <Condicion> repoCondicion = new BaseRepositorio <Condicion>(contexto);
            var includesCondicion = new List <Expression <Func <Condicion, object> > >()
            {
                c => c.Operador,
                c => c.Sensor
            };

            foreach (Inteligente inteligente in inteligentes)
            {
                foreach (Regla regla in inteligente.Reglas)
                {
                    var reglaId     = regla.ReglaId;
                    var condiciones = repoCondicion.Filter(c => c.ReglaId == reglaId, includesCondicion);

                    if (condiciones.Count > 0)
                    {
                        string strCondiciones = "";
                        foreach (Condicion condicion in condiciones)
                        {
                            if (strCondiciones != "")
                            {
                                strCondiciones += " | ";
                            }
                            string strTipoOperacion = condicion.Operador.Descripcion;
                            strCondiciones += condicion.Sensor.Descripcion + " " + strTipoOperacion.ToLower() + " a " + condicion.ValorReferencia.ToString() + " ";
                        }

                        string strAcciones = "";
                        foreach (Accion accion in regla.Acciones)
                        {
                            if (strAcciones != "")
                            {
                                strAcciones += " | ";
                            }
                            strAcciones += accion.Descripcion;
                        }


                        dynamic customRegla = new ExpandoObject();
                        customRegla.regla     = regla.Nombre;
                        customRegla.condicion = "{" + strCondiciones + "} => {" + strAcciones + "}";

                        salida.Add(customRegla);
                    }
                }
            }

            return(salida);
        }