Exemple #1
0
        public ActionResult Detail(int?id)
        {
            var _entity = new Domain.SYS_ROLE()
            {
                ISCUSTOM = 0
            };

            if (id != null && id > 0)
            {
                _entity = RoleManage.Get(p => p.ID == id);
            }
            else
            {
                if (!string.IsNullOrEmpty(Request.QueryString["systemId"]))
                {
                    _entity.FK_BELONGSYSTEM = Request.QueryString["systemId"];
                }
            }

            ViewData["Systemlist"] = this.SystemManage.LoadSystemInfo(CurrentUser.System_Id);

            return(View(_entity));
        }
Exemple #2
0
        public ActionResult Save(Domain.SYS_ROLE entity)
        {
            bool isEdit = false;
            var  json   = new JsonHelper()
            {
                Msg = "保存成功", Status = "n"
            };

            try
            {
                if (entity != null)
                {
                    //判断角色名是否汉字
                    if (System.Text.RegularExpressions.Regex.IsMatch(entity.ROLENAME.Trim(), "^[\u4e00-\u9fa5]+$"))
                    {
                        if (entity.ROLENAME.Length > 36)
                        {
                            json.Msg = "角色名称最多只能能包含36个汉字";
                            return(Json(json));
                        }

                        //添加
                        if (entity.ID <= 0)
                        {
                            entity.CREATEDATE  = DateTime.Now;
                            entity.CREATEPERID = this.CurrentUser.Name;
                            entity.UPDATEDATE  = DateTime.Now;
                            entity.UPDATEUSER  = this.CurrentUser.Name;
                        }
                        else //修改
                        {
                            entity.UPDATEDATE = DateTime.Now;
                            entity.UPDATEUSER = this.CurrentUser.Name;
                            isEdit            = true;
                        }
                        //判断角色是否重名
                        if (!this.RoleManage.IsExist(p => p.ROLENAME == entity.ROLENAME && p.ID != entity.ID))
                        {
                            if (isEdit)
                            {
                                //系统更换 删除所有权限
                                var _entity = RoleManage.Get(p => p.ID == entity.ID);
                                if (_entity.FK_BELONGSYSTEM != entity.FK_BELONGSYSTEM)
                                {
                                    RolePermissionManage.Delete(p => p.ROLEID == _entity.ID);
                                }
                            }
                            if (RoleManage.SaveOrUpdate(entity, isEdit))
                            {
                                json.Status = "y";
                            }
                            else
                            {
                                json.Msg = "保存失败";
                            }
                        }
                        else
                        {
                            json.Msg = "角色名" + entity.ROLENAME + "已被使用,请修改角色名称再提交";
                        }
                    }
                    else
                    {
                        json.Msg = "角色名称只能包含汉字";
                    }
                }
                else
                {
                    json.Msg = "未找到需要保存的角色信息";
                }
                if (isEdit)
                {
                    WriteLog(Common.Enums.enumOperator.Edit, "修改用户角色,结果:" + json.Msg, Common.Enums.enumLog4net.INFO);
                }
                else
                {
                    WriteLog(Common.Enums.enumOperator.Add, "添加用户角色,结果:" + json.Msg, Common.Enums.enumLog4net.INFO);
                }
            }
            catch (Exception e)
            {
                json.Msg = "保存用户角色发生内部错误!";
                WriteLog(Common.Enums.enumOperator.None, "保存用户角色:", e);
            }
            return(Json(json));
        }