Beispiel #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
                }));
            }
        }