Exemple #1
0
        // 添加用户
        public ActionResult Add(user usr)
        {
            AUser user = new AUser();
            var   rs   = user.select(usr.User_name);

            // 本来没有该用户
            if (rs == null)
            {
                user.insert(usr);
                if (user.select(usr.User_name) != null)
                {
                    return(Content(JsonConvert.SerializeObject(new
                    {
                        code = 1,
                        des = "添加成功",
                    })));
                }
                else
                {
                    return(Content(JsonConvert.SerializeObject(new
                    {
                        code = 0,
                        des = "添加失败,未添加到数据库",
                    })));
                }
            }
            else
            {
                return(Content(JsonConvert.SerializeObject(new
                {
                    code = -1,
                    des = "添加失败,系统已有该用户"
                })));
            }
        }
        // 用户注册
        public ActionResult Register(user usr)
        {
            AUser user = new AUser();
            var   rs   = user.select(usr.User_name);

            if (rs == null)
            {
                user.insert(usr);
                if (user.select(usr.User_name) != null)
                {
                    return(Content(JsonConvert.SerializeObject(new
                    {
                        code = 1,
                        des = "注册成功",
                    })));
                }
                else
                {
                    return(Content(JsonConvert.SerializeObject(new
                    {
                        code = 0,
                        des = "注册失败,未能写入数据库",
                    })));
                }
            }
            else
            {
                return(Content(JsonConvert.SerializeObject(new
                {
                    code = -1,
                    des = "注册失败,已有该用户",
                })));
            }
        }