/// <summary> /// 我的菜单内容 /// </summary> /// <returns></returns> public IEnumerable <Menu> MyMenus() { var menus = User.Menus; var menuHandler = new MenuHandle(Repository); var featureHandler = new FeatureHandle(Repository); if (0 == menus.Count()) { var isDel = (short)DeleteStatus.No; var query = menuHandler.All(t => t.IsDel == isDel); // 非管理员用户,需要根据角色来进行边界数据处理 if (!User.IsSupperAdministrator) { var roleId = User.Role.Id; query = query.Join( featureHandler.All(t => t.IsDel == isDel && t.RoleId == roleId), m => m.Id, f => f.MenuId, (m, f) => m); } menus = query.OrderByDescending(t => t.Order).ToArray(); } var arr = new List <Menu>(); if (!User.IsSupperAdministrator) { var ids = menus.Select(t => t.Pid).Where(x => !string.IsNullOrWhiteSpace(x)).Distinct().ToArray(); var parents = menuHandler.All(t => ids.Any(x => t.Id == x)).ToArray(); arr.AddRange(menus); arr.AddRange(parents); menus = arr.ToArray(); arr.Clear(); } arr = null; return(menus.Distinct()); }
public IEnumerable <RoleFeatureModel> FeatchAll() { var noDel = (short)DeleteStatus.No; using (var featureHandler = new FeatureHandle(Repository)) using (var roleHandler = new RoleHandle(Repository)) using (var menuHandler = new MenuHandle(Repository)) using (var orgHandler = new OrganizationHandle(Repository)) { var query = from role in roleHandler.All(t => t.IsDel == noDel) join featureitem in featureHandler.All(t => t.IsDel == noDel) on role.Id equals featureitem.RoleId into features from feature in features.DefaultIfEmpty(new Feature { }) join menuitem in menuHandler.All(t => t.IsDel == noDel) on feature.MenuId equals menuitem.Id into menus from menu in menus.DefaultIfEmpty(new Menu { }) select new { feature = feature, role = role, menu = menu }; if (!User.IsSupperAdministrator) { var orgcode = User.Organization.Code; var orgs = orgHandler.All(t => t.IsDel == noDel && t.Code.StartsWith(orgcode)).Select(t => t.Id).ToArray(); query = query.Where(t => orgs.Any(x => t.role.OrgId == x)); } var data = query.ToArray().GroupBy(t => t.role).Select( t => new RoleFeatureModel { role = t.Key, menus = t.GroupBy(x => x.menu).Select(x => new RoleMenuFeatureModel { menu = x.Key, role = t.Key, features = Union(x.Select(f => f.feature)).ToArray() }).ToArray() }).ToArray(); return(data); } }
/// <summary> /// 使用用户名和密码获取用户内容 /// </summary> /// <param name="userId">用户名</param> /// <param name="passwd">密码</param> /// <param name="user">返回的用户信息</param> /// <returns></returns> public AccountLoginStatus Signin(string userId, string passwd, out UserInfo user) { var userHandler = new UserHandle(Repository); var roleHandler = new RoleHandle(Repository); var officerHandler = new OfficerHandle(Repository); var orgHandler = new OrganizationHandle(Repository); var featureHandler = new FeatureHandle(Repository); var menuHandler = new MenuHandle(Repository); var isDel = (short)DeleteStatus.No; var query = from usr in userHandler.All(t => t.Account == userId && t.IsDel == isDel) join orgitem in orgHandler.All(t => t.IsDel == isDel) on usr.OrgId equals orgitem.Id into orgarr from org in orgarr.DefaultIfEmpty(new data.entity.Organization()) join officeritem in officerHandler.All(t => t.IsDel == isDel) on usr.Id equals officeritem.UserId into officers from officer in officers.DefaultIfEmpty(new data.entity.Officer()) join roleitem in roleHandler.All(t => t.IsDel == isDel) on usr.RoleId equals roleitem.Id into roles from role in roles.DefaultIfEmpty(new data.entity.Role()) join fitem in featureHandler.All(t => t.IsDel == isDel) on role.Id equals fitem.RoleId into farr from feature in farr.DefaultIfEmpty(new data.entity.Feature()) join mitem in menuHandler.All(t => t.IsDel == isDel) on feature.MenuId equals mitem.Id into marr from menu in marr.DefaultIfEmpty(new data.entity.Menu()) select new { usr = usr, org = org, officer = officer, role = role, feature = feature, menu = menu }; user = query .GroupBy(t => new { usr = t.usr, org = t.org, officer = t.officer, role = t.role }) .ToArray() .Select(t => new UserInfo { User = t.Key.usr, Officer = t.Key.officer, Organization = t.Key.org, Role = t.Key.role, Features = t.Select(x => x.feature).Where(x => !string.IsNullOrWhiteSpace(x.MenuId)), Menus = t.Select(x => x.menu).Where(x => !string.IsNullOrWhiteSpace(x.Title)) }) .FirstOrDefault(); if (user == null) { return(AccountLoginStatus.UserNoExist); } if (user.User.Passwd != EscapePassword(userId, passwd)) { return(AccountLoginStatus.PasswordError); } if (user.User.Status == (int)AccountStatus.Exception) { return(AccountLoginStatus.ExceptionAccount); } if (user.User.Status == (int)AccountStatus.Locked) { return(AccountLoginStatus.LockedAccount); } user.User.SigninStatus = (short)AccountSigninStatus.Online; if (null == userHandler.Modify(user.User, true)) { return(AccountLoginStatus.Error); } return(AccountLoginStatus.Success); }