Ejemplo n.º 1
0
        public ActionResult Editsens(tbl_sensors t)
        {
            if (Session["UserName"] != null)
            {
                var q = (from a in db.tbl_sensors
                         where a.ID.Equals(t.ID)
                         select a).SingleOrDefault();

                tbl_sensorinformation info = new tbl_sensorinformation();

                string username = Session["username"].ToString();

                var quser = (from a in db.tbl_users
                             where a.Username.Equals(username)
                             select a).SingleOrDefault();

                info.BaseID_ago = q.BaseID;
                info.BaseID_new = t.BaseID;
                info.Date       = DateTime.Now;
                info.SensorID   = t.ID;
                info.State_ago  = q.State;
                info.State_new  = t.State;
                info.TypeID_ago = q.TypeID;
                info.TypeID_new = t.TypeID;
                info.UserID     = quser.ID;
                info.x_ago      = q.x;
                info.x_new      = t.x;
                info.y_ago      = q.y;
                info.y_new      = t.y;

                db.tbl_sensorinformation.Add(info);

                q.State  = t.State;
                q.BaseID = t.BaseID;
                q.TypeID = t.TypeID;
                q.x      = t.x;
                q.y      = t.y;

                db.tbl_sensors.Attach(q);
                db.Entry(q).State = System.Data.Entity.EntityState.Modified;

                if (Convert.ToBoolean(db.SaveChanges()))
                {
                    ViewBag.Message = "Seccessfully saved.";
                    ViewBag.style   = "color:green;";
                    return(View(q));
                }
                else
                {
                    ViewBag.Message = "Unfortunately not saved.";
                    ViewBag.style   = "color:red;";
                    return(View(q));
                }
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Ejemplo n.º 2
0
        public ActionResult CreateSensor(tbl_sensors t)
        {
            if (Session["UserName"] == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (Session["Access"].ToString() != "admin")
            {
                return(RedirectToAction("Index", "Home"));
            }

            string username = Session["username"].ToString();
            var    q        = (from a in db.tbl_users
                               where a.Username.Equals(username)
                               select a).SingleOrDefault();

            t.UserID = q.ID;



            db.tbl_sensors.Add(t);

            if (Convert.ToBoolean(db.SaveChanges()))
            {
                ViewBag.Message = "Seccessfully saved.";
                ViewBag.style   = "color:green;";
                return(View(t));
            }
            else
            {
                ViewBag.Message = "Unfortunately not saved.";
                ViewBag.style   = "color:red;";
                return(View(t));
            }
        }