예제 #1
0
        public string AddCustomer(CustomerModel model, int type)
        {
            string errorMsg = "";

            model.Name = StringHelper.GetFirstPYLetter(model.RealName);
            if (type == 1) //添加
            {
                if (!_bll.CustomerAddValidate(model, ref errorMsg))
                {
                    return(JsonConvert.SerializeObject(AlertHelper.WarningMessage(errorMsg)));
                }
                int id = _bll.AddCustomer(model);
                return(id > 0
                           ? JsonConvert.SerializeObject(AlertHelper.SuccessMessage())
                           : JsonConvert.SerializeObject(AlertHelper.ErrorMessage()));
            }
            return(_bll.UpdateCustomer(model)
                       ? JsonConvert.SerializeObject(AlertHelper.SuccessMessage("修改成功"))
                       : JsonConvert.SerializeObject(AlertHelper.ErrorMessage("修改失败")));
        }
예제 #2
0
        public string AddUser(UserModel model, int type)
        {
            if (type == 1) //添加
            {
                if (!_bll.UserNameExists(model.LoginName))
                {
                    return(JsonConvert.SerializeObject(AlertHelper.WarningMessage("用户名已存在")));
                }
                model.Password = MD5Helper.GetMd5Hash(model.Password);
                int id = _bll.AddUser(model);
                return(id > 0
                           ? JsonConvert.SerializeObject(AlertHelper.SuccessMessage())
                           : JsonConvert.SerializeObject(AlertHelper.ErrorMessage()));
            }
            UserModel info = _bll.GetUserModel(model.ID);

            if (!info.Password.Equals(model.Password))
            {
                model.Password = MD5Helper.GetMd5Hash(model.Password);
            }
            return(_bll.UpdateUser(model)
                       ? JsonConvert.SerializeObject(AlertHelper.SuccessMessage("修改成功"))
                       : JsonConvert.SerializeObject(AlertHelper.ErrorMessage("修改失败")));
        }