Ejemplo n.º 1
0
 public IEnumerable <Role> FeatchAll(Expression <Func <Role, bool> > predicate)
 {
     using (var handler = new RoleHandle(Repository))
     {
         return(handler.All(predicate).ToArray());
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取当前用户角色所属组织机构的功能
        /// </summary>
        /// <returns></returns>
        public IEnumerable <Feature> MyOrgFeatures()
        {
            if (string.IsNullOrWhiteSpace(User.Organization?.Pid))
            {
                return(FeatureTypeHelper.Items.Where(t => t.FeatureType != FeatureType.None).Select(t => new Feature
                {
                    ActId = t.Name,
                    ActRemark = t.Summary
                }).ToArray());
            }

            var noDel = (short)DeleteStatus.No;
            var orgId = User.Organization.Id;

            using (var roleHandler = new RoleHandle(Repository))
                using (var featureHandler = new FeatureHandle(Repository))
                {
                    var query =
                        from role in roleHandler.All(t => t.IsDel == noDel && t.OrgId == orgId)
                        join featureitem in featureHandler.All(t => t.IsDel == noDel) on role.Id equals featureitem.RoleId into features
                        from feature in features.DefaultIfEmpty(new Feature {
                    })
                        select feature;

                    return(query.ToArray());
                }
        }
Ejemplo n.º 3
0
        public IEnumerable <Role> FeatchAll(string orgId)
        {
            using (var orgHandler = new OrganizationHandle(Repository))
                using (var roleHandler = new RoleHandle(Repository))
                {
                    var parentOrg  = orgHandler.First(t => t.Id == orgId);
                    var parentCode = parentOrg.Code;
                    var noDel      = (short)DeleteStatus.No;
                    var query      =
                        from role in roleHandler.All(t => t.IsDel == noDel)
                        join org in orgHandler.All(t => t.IsDel == noDel) on role.OrgId equals org.Id
                        where org.Code.StartsWith(parentCode)
                        select new { role = role, org = org };

                    var items = query.ToArray();
                    var data  = items.Select(t => t.role).ToArray();
                    return(data);
                }
        }
Ejemplo n.º 4
0
        public IEnumerable <AccountModel> Page(string orgId, string roleId, int page, int size, out int count)
        {
            var noDel = (short)DeleteStatus.No;

            using (var userHandler = new UserHandle(Repository))
                using (var roleHandler = new RoleHandle(Repository))
                    using (var orgHandler = new OrganizationHandle(Repository))
                    {
                        var query =
                            from usr in userHandler.All(t => t.IsDel == noDel)
                            join ritem in roleHandler.All(t => t.IsDel == noDel) on usr.RoleId equals ritem.Id into rls
                            from role in rls.DefaultIfEmpty(new Role {
                        })
                            join orgitem in orgHandler.All(t => t.IsDel == noDel) on usr.OrgId equals orgitem.Id into orgs
                            from org in orgs.DefaultIfEmpty(new Organization {
                        })
                            select new { usr = usr, role = role, org = org };

                        var roleEmp = string.IsNullOrWhiteSpace(roleId);
                        if (!roleEmp)
                        {
                            query = query.Where(t => t.role.Id == roleId);
                        }

                        if (roleEmp && !User.IsSupperAdministrator)
                        {
                            orgId = string.IsNullOrWhiteSpace(orgId) ? User.Organization.Id : orgId;
                            query = query.Where(t => t.org.Pid == orgId);
                        }


                        count = query.Count();
                        var skipCount = (page - 1) * size;
                        return
                            (query.OrderBy(t => t.usr.SignupDate).Skip(skipCount).Take(size).ToArray().Select(t => new AccountModel
                        {
                            org = t.org,
                            role = t.role,
                            user = t.usr
                        }).ToArray());
                    }
        }
Ejemplo n.º 5
0
        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);
                        }
        }
Ejemplo n.º 6
0
        /// <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);
        }