public async Task <ActionResult> Delete(string id, string serialCode, string port) { string name, error, loginName; if (CookieHelper.HasCookie(out name, out error) == false) { return(RedirectToAction("", "LoginUI")); } else { new RoleHelper().GetRoles(name, out role, out department1Code, out loginName); ViewData["VisitorRole"] = role; ViewData["username"] = loginName; } if (string.IsNullOrEmpty(id)) { return(RedirectToAction("Index", "Device")); } int slaveID = int.Parse(id); int servicePort = int.Parse(port); using (mlrmsEntities db = new mlrmsEntities()) { device matchOne = db.device.Where(m => m.slaveid == slaveID && m.servicecode == serialCode && m.port == servicePort).ToList().First(); db.device.Attach(matchOne); db.Entry(matchOne).State = System.Data.Entity.EntityState.Deleted; await db.SaveChangesAsync(); //通知客户端已经移除; MvcApplication.Client.Refresh(slaveID, false); } return(RedirectToAction("Index", "Device")); }
public async Task <ActionResult> Delete(string id) { string name, error, loginName; if (CookieHelper.HasCookie(out name, out error) == false) { return(RedirectToAction("", "LoginUI")); } else { new RoleHelper().GetRoles(name, out role, out department1Code, out loginName); ViewData["VisitorRole"] = role; ViewData["username"] = loginName; } if (string.IsNullOrEmpty(id)) { return(RedirectToAction("Index", "LoginUI")); } long pwdID = 0; if (long.TryParse(id, out pwdID) == false) { return(Content("入参错误", "text/html")); } using (mlrmsEntities db = new mlrmsEntities()) { sysadmin matchOne = db.sysadmin.Where(m => m.AdminID == pwdID).ToList().First(); db.sysadmin.Attach(matchOne); db.Entry(matchOne).State = System.Data.Entity.EntityState.Deleted; await db.SaveChangesAsync(); return(RedirectToAction("", "administrator")); } }
public ActionResult Reset(string id) { try { using (mlrmsEntities db = new mlrmsEntities()) { int ID = int.Parse(id); var usr = db.sysadmin.Where(m => m.AdminID == ID).First(); usr.AdminPwd = EncryptHelper.GetEncrypt("123456"); db.sysadmin.Attach(usr); db.Entry(usr).State = System.Data.Entity.EntityState.Modified; int result = db.SaveChanges(); if (result > 0) { return(Content("True", "text/html")); } else { return(Content("False", "text/html")); } } } catch (Exception ex) { LogHelper.Error("密码重置出错:" + ex.Message); return(Content("False", "text/html")); } }
public async Task <ActionResult> Index(Manager info) { string name, error, loginName; if (CookieHelper.HasCookie(out name, out error) == false) { return(RedirectToAction("", "LoginUI")); } else { new RoleHelper().GetRoles(name, out role, out department1Code, out loginName); ViewData["VisitorRole"] = role; ViewData["username"] = loginName; } try { if (ModelState.IsValid) { using (mlrmsEntities db = new mlrmsEntities()) { var userList = db.sysadmin.Where(m => m.AdminID == info.AdminId); if (userList == null || userList.Count() <= 0) { return(Content("Not Found", "text/html")); } sysadmin item = userList.First(); string pwd = EncryptHelper.GetEncrypt(info.Passwd); if (pwd != item.AdminPwd) //如果密码验证不通过 { ModelState.AddModelError("Passwd", "密码错误"); return(View()); } item.AdminPwd = EncryptHelper.GetEncrypt(info.NewPwd); db.sysadmin.Attach(item); db.Entry(item).State = System.Data.Entity.EntityState.Modified; await db.SaveChangesAsync(); ViewData["status"] = "true"; return(RedirectToAction("Logout", "LoginUI")); } } } catch { ViewData["status"] = "false"; } Manager manager = new Manager(); manager.UserName = info.UserName; //系统登出 return(View(manager)); }
public async Task <ActionResult> Delete(string id) { string name, error, loginName; if (CookieHelper.HasCookie(out name, out error) == false) { return(RedirectToAction("", "LoginUI")); } else { new RoleHelper().GetRoles(name, out role, out department1Code, out loginName); ViewData["VisitorRole"] = role; ViewData["username"] = loginName; } if (string.IsNullOrEmpty(id)) { return(RedirectToAction("Index", "serialport")); } try { using (mlrmsEntities db = new mlrmsEntities()) { if (db.device.Where(m => m.servicecode == id).Count() > 0) { return(Content("1", "text/html")); } else { serialservice matchOne = db.serialservice.Where(m => m.code == id).ToList().First(); db.serialservice.Attach(matchOne); db.Entry(matchOne).State = System.Data.Entity.EntityState.Deleted; await db.SaveChangesAsync(); return(Content("0", "text/html")); } } } catch (Exception ex) { LogHelper.Error("串口服务器删除异常", ex); return(Content("2", "text/html")); } }