public JsonResult AddDevice(string deviceId) { try { var userId = HttpContext.Session.GetInt32("UserId"); var userName = _context.UserInfo.Where(x => x.Id.Equals(userId)).SingleOrDefault().UserName; if (_context.DeviceInfo.Where(x => x.DeviceId.Equals(deviceId)).Count() != 0) { return(Json("-1")); } else { DeviceInfo newDevice = new DeviceInfo(); newDevice.UserName = userName; newDevice.DeviceId = deviceId; if (_context.DeviceInfo.Count() != 0) { newDevice.Id = _context.DeviceInfo.Max(x => x.Id) + 1; } else { newDevice.Id = 1; } _context.Add(newDevice); _context.SaveChanges(); } return(Json("1")); } catch { return(null); } }
public ActionResult SaveChanges(IFormCollection form) { var a = form["mark0"]; var b = form["mark1"]; var c = form["mark2"]; string temp = ""; var username = HttpContext.Session.GetString("UserName"); var model = _context.UserInfo.Where(x => x.UserName.Equals(username)).First(); if (a == "1") { temp += "1"; } if (b == "1") { temp += "2"; } if (c == "1") { temp += "3"; } model.DeviceModel = temp; _context.SaveChanges(); return(RedirectToAction("../Device/DeviceManage")); }
public ActionResult AddUser(IFormCollection form) { var username = form["username"]; var password = form["password"]; var ta = _context.UserInfo.Where(m => m.UserName.Equals(username)).Select(m => m.Id); if (ta.Count() != 0) { ViewData["warning"] = "该用户已被注册"; return(View("Register")); } else { var _user = new UserInfo { UserName = username, PassWord = password, }; _context.Add(_user); _context.SaveChanges(); return(RedirectToAction("RegisterResult")); } }