public ActionResult Delete(string idList) { var json = new JsonHelper() { Msg = "删除角色完毕", Status = "n" }; var id = idList.Trim(',').Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(p => int.Parse(p)).ToList(); if (id.Contains(Common.Enums.ClsDic.DicRole["超级管理员"])) { json.Msg = "删除失败,不能删除系统固有角色!"; WriteLog(Common.Enums.enumOperator.Remove, "删除用户角色:" + json.Msg, Common.Enums.enumLog4net.ERROR); return(Json(json)); } if (this.UserRoleManage.IsExist(p => id.Contains(p.FK_ROLEID))) { json.Msg = "删除失败,不能删除系统中正在使用的角色!"; WriteLog(Common.Enums.enumOperator.Remove, "删除用户角色:" + json.Msg, Common.Enums.enumLog4net.ERROR); return(Json(json)); } try { //1、删除角色权限 RolePermissionManage.Delete(p => id.Contains(p.ROLEID)); //2、删除角色 RoleManage.Delete(p => id.Contains(p.ID)); json.Status = "y"; WriteLog(Common.Enums.enumOperator.Remove, "删除用户角色:" + json.Msg, Common.Enums.enumLog4net.WARN); } catch (Exception e) { json.Msg = "删除用户角色发生内部错误!"; WriteLog(Common.Enums.enumOperator.Remove, "删除用户角色:", e); } return(Json(json)); }
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)); }