Example #1
0
        public ActionResult Create(StoreInfo info)
        {
            info.CreateDate = DateTime.Now;
            info.IP         = string.Empty;
            StoreInfo infoExist = StoreBLL.GetList(p => p.Name == info.Name).FirstOrDefault();

            if (null != infoExist)
            {
                return(Json(new APIJson(-1, "名称已存在")));
            }
            if (string.IsNullOrEmpty(info.Name))
            {
                return(Json(new APIJson(-1, "名称未填写")));
            }
            if (string.IsNullOrEmpty(info.Name.Trim()))
            {
                return(Json(new APIJson(-1, "名称不能是空格,请正确填写")));
            }
            if (string.IsNullOrEmpty(info.Code))
            {
                info.Code = info.Name;
            }
            if (!string.IsNullOrEmpty(info.Password))
            {
                bool IsPassWordValidate = ValidatePassWord(info);
                if (!IsPassWordValidate || info.Password.Length < 8 || info.Password.Length > 16)
                {
                    return(Json(new APIJson("密码必需包含数字、字母,并且长度在8到16位")));
                }
            }
            else
            {
                info.Password = "******";
            }
            info.Password = Tool.Md5Helper.Md5(info.Password);
            StoreBLL.Create(info);
            if (info.ID > 0)
            {
                return(Json(new APIJson(0, "添加成功", new { info.ID, info.Name })));
            }
            return(Json(new APIJson(-1, "添加失败")));
        }