Example #1
0
        public ActionResult AdminEditProvide()
        {
            if (string.IsNullOrWhiteSpace(RQuery["AdminId"]))
            {
                if (!base.HasPermission("admin", PermissionOperate.add))
                {
                    return(JsonMessage(false, "你没有添加管理员的权限"));
                }
            }
            else
            {
                if (!base.HasPermission("admin", PermissionOperate.edit))
                {
                    return(JsonMessage(false, "你没有编辑管理员的权限"));
                }
            }

            Ocean.Entity.Admin admin       = new Entity.Admin();
            string             oldPassword = string.Empty;

            if (!string.IsNullOrWhiteSpace(RQuery["AdminId"]))
            {
                admin       = _adminService.GetById(new Guid(RQuery["AdminId"]));
                oldPassword = admin.Password;
            }

            UpdateModel <Ocean.Entity.Admin>(admin);

            if (!string.IsNullOrWhiteSpace(RQuery["Password"]))
            {
                //判断密码有效性
                if (!StringValidate.IsNumCHA20(admin.Password))
                {
                    return(JsonMessage(false, "添加管理员失败,密码必须由6-20字母、数字组成"));
                }
            }

            if (RQuery["Password"] != RQuery["PasswordConfirm"])
            {
                return(JsonMessage(false, "两次输入密码不匹配"));
            }

            if (admin.PermissionOrganizationId == Guid.Empty || admin.PermissionOrganizationId == null)
            {
                return(JsonMessage(false, "请选择所属部门"));
            }

            if (admin.PermissionRoleId == Guid.Empty || admin.PermissionRoleId == null)
            {
                return(JsonMessage(false, "请选择所属角色"));
            }

            if (string.IsNullOrWhiteSpace(RQuery["AdminId"]))
            {
                admin.Password    = Hash.MD5Encrypt(Hash.MD5Encrypt(admin.Password));
                admin.PasswordKey = Guid.NewGuid().ToString().Substring(0, 8);
                admin.State       = 1;
                _adminService.Insert(admin);
                base.AddLog(string.Format("添加管理员[{0}]成功", admin.Name), AdminLoggerModuleEnum.Admin);
                return(JsonMessage(true, "添加管理员成功"));
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(RQuery["Password"]))
                {
                    admin.Password    = Hash.MD5Encrypt(Hash.MD5Encrypt(admin.Password));
                    admin.PasswordKey = Guid.NewGuid().ToString().Substring(0, 8);
                }
                else
                {
                    admin.Password = oldPassword;
                }

                _adminService.Update(admin);
                base.AddLog(string.Format("修改管理员[{0}]成功", admin.Name), AdminLoggerModuleEnum.Admin);
                return(JsonMessage(true, "修改管理员成功"));
            }
        }