예제 #1
0
        public ActionResult Register(EnterpriseManager.Models.User user)
        {
            //MySQL
            //user.UserId = "UserId";
            //userService.Create(user);
            //return View();

            //SQL
            if (db.Users.FirstOrDefault(u => u.UserName == user.UserName) != null) //判断注册用户是否存在
            {
                ModelState.AddModelError("", "用户已经存在");                            //自定义添加错误提示消息
                return(View());
            }
            db.Users.Add(user); //将用户对象添加到数据库中
            db.SaveChanges();   //将用户提交到数据保存
            return(RedirectToAction("Login", "Account"));
        }
예제 #2
0
        public ActionResult login(EnterpriseManager.Models.User user)
        {
            var item = db.Users.FirstOrDefault(u => u.UserName == user.UserName && u.PassWord == user.PassWord);

            if (item == null)
            {
                //Session["User"] = item;
                //return RedirectToAction("Index", "Home");
                ModelState.AddModelError("", "登陆失败");//自定义添加错误提示消息
                return(View(user));
            }
            if (item.Classify <= 1)
            {
                Session["User"] = item;
                return(RedirectToAction("VIP", "Home"));
            }
            else
            {
                Session["User"] = item;
                return(RedirectToAction("Index", "Home"));
            }
        }