Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        public JsonResult CheckDevice(string deviceid)
        {
            var        username = HttpContext.Session.GetString("UserName");
            int        isExistance;
            DeviceInfo temp = new DeviceInfo();
            string     Warning;

            if (deviceid == null)
            {
                return(Json("设备号不能为空"));
            }
            if (_context.DeviceInfo.Where(x => x.UserName.Equals(username)).Count() != 0)
            {
                isExistance = _context.DeviceInfo.Where(x => x.UserName.Equals(username)).Where(y => y.DeviceId.Equals(deviceid)).Count();
                if (isExistance != 0)
                {
                    Warning = "设备已注册";
                    return(Json(Warning));
                }
            }
            temp.Id       = _context.DeviceInfo.Max(x => x.Id) + 1;
            temp.UserName = username;
            temp.DeviceId = deviceid;
            _context.Add(temp);
            _context.SaveChanges();
            return(Json("设备添加成功"));
        }
Esempio n. 3
0
        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"));
            }
        }
Esempio n. 4
0
        public async Task <IActionResult> Create([Bind("Id,UserName,PassWord,Address,Tel,Coporation,Department,Sex")] UserInfo userInfo)
        {
            if (ModelState.IsValid)
            {
                var test = userInfo.UserName;
                if (_context.UserInfo.Where(x => x.UserName.Equals(userInfo.UserName)).Count() != 0)
                {
                    ViewBag.warning = "该用户已存在";
                    return(View());
                }

                _context.Add(userInfo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(userInfo));
        }