Example #1
0
        /// <summary>
        /// Admin启用或禁用
        /// </summary>
        /// <param name="id"></param>
        /// <param name="ised"></param>
        /// <returns></returns>
        public string AdminEnableOrDisabled(int id, string ised)
        {
            ResultInfo <string> result = new ResultInfo <string>();
            var bll   = new MultiColorPen.BLL.base_userinfo();
            var model = bll.GetModel(id);

            model.isenable = int.Parse(ised);
            if (bll.Update(model) > 0)
            {
                result.IsSucceed = true;
                result.Message   = "operation Successful!";
                PublicClass.AddLog("Operating", (model.isenable == 1 ? "Enable insiders:" : "Disable insider:") + model.username + "," + model.pname + "!");
            }
            else
            {
                result.IsSucceed = false;
                result.Message   = "operation Failed!";
            }
            return(JsonConvert.SerializeObject(result));
        }
Example #2
0
        /// <summary>
        /// 保存Admin
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public string AdminManageSave(string json)
        {
            ResultInfo result   = new ResultInfo(false);
            JObject    jo       = JObject.Parse(json);
            LoginInfo  userInfo = SessionHelper.ReadSession <LoginInfo>(SessionKeys.LoginInfoKey);
            var        bll      = new MultiColorPen.BLL.base_userinfo();

            bool   avatar     = false;
            string folderName = Server.MapPath("~/Upload/Avatar");

            if (Directory.Exists(folderName) == false)
            {
                Directory.CreateDirectory(folderName);
            }
            string fileName = Guid.NewGuid().ToString("N");
            string filePath = folderName + "/" + fileName + ".jpg";

            if (jo["avatar"].ToString() == "-1" && jo["base64"].ToString() != "-1" && StringToFile(jo["base64"].ToString(), filePath))
            {
                avatar = true;
            }
            try
            {
                //新增
                if (jo["id"].ToString() == "-1")
                {
                    var list = bll.GetModelList("username='******' and A.isenable=1");
                    if (list.Count > 0)
                    {
                        result.IsSucceed = false;
                        result.Message   = "Duplicate login name!";
                    }
                    else
                    {
                        var model = new MultiColorPen.Model.base_userinfo
                        {
                            usercode   = bll.GetMaxNo(),
                            username   = jo["username"].ToString(),
                            phone      = jo["phone"].ToString(),
                            pname      = jo["pname"].ToString(),
                            rolecode   = jo["rolecode"].ToString(),
                            wechat     = jo["wechat"].ToString(),
                            password   = "******",
                            avatar     = avatar ? fileName : jo["avatar"].ToString() == "-1" ? "" : jo["avatar"].ToString(),
                            isenable   = 1,
                            createtime = DateTime.Now,
                            createman  = userInfo.UserName
                        };
                        if (bll.Add(model) > 0)
                        {
                            result.IsSucceed = true;
                            result.Message   = "Save success, the initial password is 888888!";
                            PublicClass.AddLog("Operating", "Add insiders " + model.username + "," + model.pname + "!");
                        }
                        else
                        {
                            result.IsSucceed = false;
                            result.Message   = "Save failed!";
                        }
                    }
                }
                //修改
                else
                {
                    int id   = int.Parse(jo["id"].ToString());
                    var list = bll.GetModelList("username='******' and A.id!=" + id + " and A.isenable=1");
                    if (list.Count > 0)
                    {
                        result.IsSucceed = false;
                        result.Message   = "Duplicate login name!";
                    }
                    else
                    {
                        var    umodel = bll.GetModel(id);
                        string oldstr = JsonHelper.GetObjectToJSON(umodel);
                        umodel.phone      = jo["phone"].ToString();
                        umodel.pname      = jo["pname"].ToString();
                        umodel.wechat     = jo["wechat"].ToString();
                        umodel.rolecode   = jo["rolecode"].ToString();
                        umodel.avatar     = avatar ? fileName : jo["avatar"].ToString() == "-1" ? "" : jo["avatar"].ToString();
                        umodel.updateman  = userInfo.UserName;
                        umodel.updatetime = DateTime.Now;
                        string newstr = JsonHelper.GetObjectToJSON(umodel);

                        if (bll.Update(umodel) > 0)
                        {
                            result.IsSucceed = true;
                            result.Message   = "Saved successfully!";
                            PublicClass.AddLog("Operating", "Modify internal staff " + umodel.username + "!", "", "", "base_userinfo", umodel.id.ToString(), oldstr, newstr);
                        }
                        else
                        {
                            result.IsSucceed = false;
                            result.Message   = "Save failed!";
                        }
                    }
                }
                return(JsonConvert.SerializeObject(result));
            }
            catch (Exception ex)
            {
                result.IsSucceed = false;
                result.Message   = ex.Message;
                return(JsonConvert.SerializeObject(result));
            }
        }