예제 #1
0
        public ActionResult Register(LoginViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { code = -1, url = "", msg = "数据不合法" }));
            }

            //根据用户登录名查询指定用户实体
            var user = UserBll.LoadEntities(t => t.UserCode == model.UserCode).FirstOrDefault();

            //如果用户不存在,则携带错误消息并返回登录页面
            if (user != null)
            {
                return(Json(new { code = "-2", url = "", msg = "用户名已存在" }));
            }


            var ret = UserBll.AddEntity(new T_Sys_User()
            {
                Password = Encryptor.Md5Hash(model.Password), UserCode = model.UserCode
            });

            return(Json(new { code = "0", url = "/Account/Login", msg = "注册成功,请登录" }));
        }