예제 #1
0
        public async Task <ActionResult> DeleteRole(string ID)
        {
            try
            {
                if (!string.IsNullOrEmpty(ID))
                {
                    int  roleid   = Convert.ToInt32(ID);
                    Role findrole = await RoleRepository.FindAsync(u => u.RoleID == roleid);

                    if (RoleRepository.Delete(findrole))
                    {
                        //查询关联关系 菜单角色表
                        IEnumerable <RoleMenu> IRM = await RoleMenuRepository.FindListAsync(r => r.RoleID == roleid, string.Empty, false);

                        if (IRM != null && IRM.Count() != 0)
                        {
                            //删除已存在的菜单角色表
                            RoleMenuRepository.DeleteRange(IRM);
                        }
                        //查询关联关系 用户角色表
                        IEnumerable <UserRole> IUR = await UserRoleRepository.FindListAsync(u => u.RoleID == roleid, string.Empty, false);

                        if (IUR != null && IUR.Count() != 0)
                        {
                            //删除已存在的用户角色表
                            UserRoleRepository.DeleteRange(IUR);
                        }
                        return(Json(new
                        {
                            Success = true
                        }));
                    }
                }
                return(Json(new
                {
                    Success = false
                }));
            }
            catch (Exception ex)
            {
                LogRepository.Add(new EventLog()
                {
                    Name = Session["LoginedUser"].ToString(), Date = DateTime.Now.ToLocalTime(), Event = "删除权限失败" + ex.Message
                });
                return(Json(new
                {
                    Success = false
                }));
            }
        }
 public override void AfterDelete(DbContext DB, Roles entity, string sOperator)
 {
     _roleMenuRepository.DeleteRange(_roleMenuRepository.SelectALL(new RoleMenu()
     {
         IroleId = entity.Id
     }), sOperator);
     _userRoleRepository.DeleteRange(_userRoleRepository.SelectALL(new UserRole()
     {
         IroleId = entity.Id
     }), sOperator);
     base.AfterDelete(DB, entity, sOperator);
 }
 public override void AfterDelete(DbContext DB, Menu entity, string sOperator)
 {
     _roleMenuRepository.DeleteRange(_roleMenuRepository.SelectALL(new RoleMenu()
     {
         ImenuId = entity.Id
     }), sOperator);
     _menuActionRepository.DeleteRange(_menuActionRepository.SelectALL(new MenuAction()
     {
         ImenuId = entity.Id
     }), sOperator);
     base.AfterDelete(DB, entity, sOperator);
 }