// GET: MachineSensor public ActionResult IndexMachineSensor() { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"].ToString().ToUpper(); ViewBag.roleid = Session["RoleID"]; String Username = Session["Username"].ToString(); //using (i_facility_unimechEntities db = new i_facility_unimechEntities()) //{ sensormachinemodel pa = new sensormachinemodel(); configurationtblmachinesensor mp = new configurationtblmachinesensor(); pa.machinesensor = mp; pa.machinesensorList = db.configurationtblmachinesensors.Where(m => m.IsDeleted == 0).ToList(); return(View(pa)); //} }
public ActionResult EditMachineSensor(sensormachinemodel tblmc) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"].ToString().ToUpper(); ViewBag.roleid = Session["RoleID"]; String Username = Session["Username"].ToString(); int UserID = Convert.ToInt32(Session["UserID"]); string sensorName = db.configuration_tblsensorgroup.Where(m => m.SID == tblmc.machinesensor.Sid).Select(m => m.SensorGroupName).FirstOrDefault(); string macname = db.tblmachinedetails.Where(m => m.MachineID == tblmc.machinesensor.MachineId).Select(m => m.MachineName).FirstOrDefault(); int msid = tblmc.machinesensor.MSID; using (i_facility_unimechEntities db = new i_facility_unimechEntities()) { var doesThisExist = db.configurationtblmachinesensors.Where(m => m.IsDeleted == 0 && m.MSID != msid && m.Sid == tblmc.machinesensor.Sid && m.MachineId == tblmc.machinesensor.MachineId && m.Sid == tblmc.machinesensor.Sid).ToList(); if (doesThisExist.Count == 0) { var sensor = db.configurationtblmachinesensors.Find(tblmc.machinesensor.MSID); sensor.MachineId = tblmc.machinesensor.MachineId; sensor.Sid = tblmc.machinesensor.Sid; sensor.IPAddress = tblmc.machinesensor.IPAddress; if (sensor.IPAddress == null) { sensor.IPAddress = "0"; } sensor.PortNo = tblmc.machinesensor.PortNo; sensor.MachineId = tblmc.machinesensor.MachineId; sensor.ModifiedBy = ViewBag.roleid; sensor.ModifiedOn = DateTime.Now; db.Entry(sensor).State = EntityState.Modified; db.SaveChanges(); TempData["toaster_success"] = "Data Updated successfully"; return(RedirectToAction("IndexMachineSensor")); } else { TempData["toaster_error"] = "Sensor Group Name already exists"; return(View(tblmc)); } } }
public ActionResult EditMachineSensor(int id) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"].ToString().ToUpper(); ViewBag.roleid = Session["RoleID"]; String Username = Session["Username"].ToString(); using (i_facility_unimechEntities db = new i_facility_unimechEntities()) { configurationtblmachinesensor tblmc = db.configurationtblmachinesensors.Find(id); if (tblmc == null) { return(HttpNotFound()); } ViewBag.MachineName = new SelectList(db.tblmachinedetails.ToList().Where(m => m.IsDeleted == 0), "MachineId", "MachineName", tblmc.MachineId).ToList(); ViewBag.SensorGroupName = new SelectList(db.configuration_tblsensorgroup.ToList().Where(m => m.IsDeleted == 0), "SID", "SensorGroupName", tblmc.Sid).ToList(); sensormachinemodel sd = new sensormachinemodel(); sd.machinesensor = tblmc; return(View(sd)); } }