示例#1
0
        public async Task <List <UserEntity> > AllMembers(string org_uid)
        {
            return(await this._orgRepo.PrepareSessionAsync(async db =>
            {
                var map_query = db.Set <OrganizationMemberEntity>().AsNoTrackingQueryable();
                var map = map_query.Where(x => x.OrgUID == org_uid);
                var user_uids = map.Select(x => x.UserUID);
                var query = db.Set <UserEntity>().AsNoTrackingQueryable();
                query = query.Where(x => user_uids.Contains(x.UID));

                var list = await query.OrderBy(x => x.IID).Take(1000).ToListAsync();

                if (ValidateHelper.IsPlumpList(list))
                {
                    var uids = list.Select(x => x.UID);
                    var orgs = await map_query.Where(x => uids.Contains(x.UserUID)).ToListAsync();
                    var roles = MemberRoleHelper.GetRoles();
                    foreach (var m in list)
                    {
                        var org = orgs.Where(x => x.UserUID == m.UID).FirstOrDefault();
                        if (org == null)
                        {
                            continue;
                        }

                        m.OrgFlag = org.Flag;
                        m.OrgUID = org.OrgUID;
                        m.OrgFlagName = string.Join(",", MemberRoleHelper.ParseRoleNames(m.OrgFlag, roles).Take(3).ToList());
                    }
                }

                return list;
            }));
        }
示例#2
0
        public async Task <PagerData <UserEntity> > QueryMember(string org_uid, string q, int page, int pagesize)
        {
            return(await this._orgRepo.PrepareSessionAsync(async db =>
            {
                var map_query = db.Set <OrganizationMemberEntity>().AsNoTrackingQueryable();
                var map = map_query.Where(x => x.OrgUID == org_uid);
                var user_uids = map.Select(x => x.UserUID);
                var query = db.Set <UserEntity>().AsNoTrackingQueryable();
                query = query.Where(x => user_uids.Contains(x.UID));

                if (ValidateHelper.IsPlumpString(q))
                {
                    query = query.Where(x => x.UserName == q || x.NickName.StartsWith(q) || x.UserName.StartsWith(q));
                }
                var data = await query.ToPagedListAsync(page, pagesize, x => x.IID);
                if (ValidateHelper.IsPlumpList(data.DataList))
                {
                    var uids = data.DataList.Select(x => x.UID);
                    var orgs = await map_query.Where(x => uids.Contains(x.UserUID)).ToListAsync();
                    var roles = MemberRoleHelper.GetRoles();
                    foreach (var m in data.DataList)
                    {
                        var org = orgs.Where(x => x.UserUID == m.UID).FirstOrDefault();
                        if (org == null)
                        {
                            continue;
                        }

                        m.OrgFlag = org.Flag;
                        m.OrgUID = org.OrgUID;
                        m.OrgFlagName = string.Join(",", MemberRoleHelper.ParseRoleNames(m.OrgFlag, roles));
                    }
                }

                return data;
            }));
        }