public ActionResult DelDevice(string id) { var username = HttpContext.Session.GetString("UserName"); var device = _context.DeviceInfo.Where(x => x.UserName.Equals(username)).Where(y => y.DeviceId.Equals(id)).Single(); _context.Remove(device); _context.SaveChanges(); return(RedirectToAction("AddDevice")); }
public JsonResult DelDevice(string deviceId) { try { var userId = HttpContext.Session.GetInt32("UserId"); var userName = _context.UserInfo.Where(x => x.Id.Equals(userId)).SingleOrDefault().UserName; var device = _context.DeviceInfo.Where(x => x.UserName.Equals(userName)).Where(y => y.DeviceId.Equals(deviceId)).Single(); _context.Remove(device); _context.SaveChanges(); return(null); } catch { return(null); } }