Ejemplo n.º 1
0
        public ActionResult Edit(Device_Information model)

        {
            var db = new HefestoDevicesEntities();
            Device_Information device = new Device_Information();

            device = db.Device_Information.Find(model.Device_Id);

            if (ModelState.IsValid)
            {
                device.Device_Name           = model.Device_Name;
                device.Device_Lat            = model.Device_Lat;
                device.DEvice_Long           = model.DEvice_Long;
                device.Device_Mode           = model.Device_Mode;
                device.Device_Status         = model.Device_Status;
                device.Device_Email          = model.Device_Email;
                device.Device_Zone           = model.Device_Zone;
                device.Device_OffTime        = model.Device_OffTime;
                device.Device_OnTime         = model.Device_OnTime;
                device.Device_Port_In        = model.Device_Port_In;
                device.Device_Port_Off_Under = model.Device_Port_Off_Under;
                device.Device_Port_On_Over   = model.Device_Port_On_Over;
                device.Device_SetPoint       = model.Device_SetPoint;
                device.Device_Histerresys    = model.Device_Histerresys;

                db.SaveChanges();

                return(RedirectToAction("Details", new { id = device.Device_Id }));
            }

            // If we got this far, something failed, redisplay form
            return(View(device));
        }
Ejemplo n.º 2
0
        public ActionResult ReadAlert(int id)
        {
            var    db    = new HefestoDevicesEntities();
            Alerts alert = new Alerts();

            alert = db.Alerts.Find(id);
            alert.Alert_Isread    = 1;
            alert.Alert_Closedate = DateTime.Now;
            db.SaveChanges();
            return(RedirectToAction("Details", "Alert", new { id = id }));
        }
Ejemplo n.º 3
0
        public string Create(int id, int type)
        {
            var                db     = new HefestoDevicesEntities();
            Alerts             alert  = new Alerts();
            Device_Information device = new Device_Information();
            Alert_Types        mess   = new Alert_Types();

            //Variables used for obtain information to the mail
            mess   = db.Alert_Types.Find(type);
            device = db.Device_Information.Find(id);

            //Creation of new alert
            alert.Alert_Device   = id;
            alert.Alert_Type     = type;
            alert.Alert_Opendate = DateTime.Now;
            alert.Alert_Isread   = 0;

            db.Alerts.Add(alert);
            db.SaveChanges();

            //Creation of the message and maps location
            string message = "Report from: " + device.Device_Name + " about: " + mess.Alert_Description;

            message += "\r\n Location: \r\n";
            message += "http://maps.googleapis.com/maps/api/staticmap?center=" + device.Device_Lat.ToString() + "," + device.DEvice_Long.ToString() + "&zoom=15&size=600x300&maptype=roadmap&markers=color:blue%7Clabel:S%7C";
            message += device.Device_Lat.ToString() + "," + device.DEvice_Long.ToString() + "&sensor=false";

            //Creation of the mail's header
            string subject  = "Alert from: " + device.Device_Name;
            string address  = device.Device_Email;
            string email    = "*****@*****.**";
            string password = "******";

            //Send Email  message
            var loginInfo  = new NetworkCredential(email, password);
            var msg        = new MailMessage();
            var smtpClient = new SmtpClient("smtp.gmail.com", 587);

            msg.From = new MailAddress(email);
            msg.To.Add(new MailAddress(address));
            msg.Subject    = subject;
            msg.Body       = message;
            msg.IsBodyHtml = true;

            smtpClient.EnableSsl             = true;
            smtpClient.UseDefaultCredentials = false;
            smtpClient.Credentials           = loginInfo;
            smtpClient.Send(msg);

            //Shows the information of the device after create alert
            return("OK");
        }
Ejemplo n.º 4
0
        //GET: /DeviceLV/Control/?id=&mode=&status=
        public string Control(int id, int mode, int status)
        {
            var db = new HefestoDevicesEntities();
            Device_Information device = new Device_Information();

            device = db.Device_Information.Find(id);

            device.Device_Mode   = mode;
            device.Device_Status = status;
            db.SaveChanges();

            return("OK");
        }
Ejemplo n.º 5
0
/********************************************************************************************************************/
        public ActionResult Changemode(int id, int mode, int status)
        {
            var db = new HefestoDevicesEntities();
            Device_Information device = new Device_Information();

            device               = db.Device_Information.Find(id);
            device.Device_Mode   = mode;
            device.Device_Status = status;
            db.SaveChanges();

            return(RedirectToAction("Details", new { id = device.Device_Id }));
            //return View();
        }
Ejemplo n.º 6
0
        public ActionResult  New(Device_Information model)
        {
            if (ModelState.IsValid)
            {
                var db = new HefestoDevicesEntities();
                db.Device_Information.Add(model);
                db.SaveChanges();

                return(RedirectToAction("Details", new { id = model.Device_Id }));
            }

            // If we got this far, something failed, redisplay form
            return(View("New"));
        }
        //
        // GET: /MonitoringLV/Create

        public string Create(int id, int status, float current, float voltage)
        {
            var     db  = new HefestoDevicesEntities();
            Monitor mon = new Monitor();

            mon.Monitor_Device  = id;
            mon.Monitor_Date    = DateTime.Now;
            mon.Monitor_Status  = status;
            mon.Monitor_Current = current;
            mon.Monitor_Voltage = voltage;
            db.Monitor.Add(mon);
            db.SaveChanges();

            return("OK");
        }
Ejemplo n.º 8
0
        //
        // GET: /DeviceLV/Create?name=&lat=&lon=&mode=&status=&zone=&email=

        public string Create(string name, float lat, float lon, int mode, int status, string zone, string email)
        {
            var db = new HefestoDevicesEntities();
            Device_Information device = new Device_Information();

            device.Device_Name   = name;
            device.Device_Lat    = lat;
            device.DEvice_Long   = lon;
            device.Device_Mode   = mode;
            device.Device_Status = status;
            device.Device_Zone   = zone;
            device.Device_Email  = email;

            db.Device_Information.Add(device);
            db.SaveChanges();
            return("OK");
        }
Ejemplo n.º 9
0
        public string ReadAlert(int id)
        {
            var    db    = new HefestoDevicesEntities();
            Alerts alert = new Alerts();

            alert = db.Alerts.Find(id);
            if (alert.Alert_Isread == 0)
            {
                alert.Alert_Isread    = 1;
                alert.Alert_Closedate = DateTime.Now;
                db.SaveChanges();
                return("OK");
            }

            else
            {
                return("ERROR");
            }
        }
Ejemplo n.º 10
0
/********************************************************************************************************************/
        //
        // GET: /Device/Create
        public ActionResult Create(string name, float lat, float lon, int mode, int status, string zone, string email)

        {
            var db = new HefestoDevicesEntities();
            Device_Information device = new Device_Information();

            device.Device_Name   = name;
            device.Device_Lat    = lat;
            device.DEvice_Long   = lon;
            device.Device_Mode   = mode;
            device.Device_Status = status;
            device.Device_Zone   = zone;
            device.Device_Email  = email;

            db.Device_Information.Add(device);
            db.SaveChanges();
            return(RedirectToAction("Details", new { id = device.Device_Id }));
            //return View();
        }
Ejemplo n.º 11
0
/********************************************************************************************************************/
        //
        // GET: /Device/Delete/5
        public ActionResult Delete(int id)
        {
            var db = new HefestoDevicesEntities();
            Device_Information device = new Device_Information();

            device = db.Device_Information.Find(id);


            var alerts = (from p in db.Alerts
                          where p.Device_Information.Device_Name.Contains(device.Device_Name)
                          select p).ToList();

            if (alerts.Count() > 0)
            {
                foreach (var alert in alerts)
                {
                    db.Alerts.Remove(alert);
                }
            }

            var monitor = (from p in db.Monitor
                           where p.Device_Information.Device_Name.Contains(device.Device_Name)
                           select p).ToList();

            if (monitor.Count() > 0)
            {
                foreach (var mon in monitor)
                {
                    db.Monitor.Remove(mon);
                }
            }


            db.Device_Information.Remove(device);
            db.SaveChanges();

            return(RedirectToAction("Index"));
            //return View();
        }
        public string Create2(int id, int status, float current, float voltage, float var1, float var2)
        {
            try
            {
                var     db  = new HefestoDevicesEntities();
                Monitor mon = new Monitor();

                mon.Monitor_Device  = id;
                mon.Monitor_Date    = DateTime.Now;
                mon.Monitor_Status  = status;
                mon.Monitor_Current = Math.Round(current, 2);
                mon.Monitor_Voltage = Math.Round(voltage, 2);
                mon.Monitor_Var1    = Math.Round(var1, 2);
                mon.Monitor_Var2    = Math.Round(var2, 2);
                db.Monitor.Add(mon);
                db.SaveChanges();

                return("OK$");
            }
            catch
            {
                return("ERROR");
            }
        }