Beispiel #1
0
 /// <summary>
 /// 初始化数据
 /// </summary>
 public void Install()
 {
     if (this.GetResult != null && this.GetResult.errcode == 0)
     {
         if (this.GetResult.allow_partys != null && this.GetResult.allow_partys.partyid != null && this.GetResult.allow_partys.partyid.Count > 0)
         {
             // 所有部门
             var allDepartment = this.GetAllDepartment();
             var allMember     = this.GetAllMember();
             this.Departments = new List <DepartmentBody>();
             foreach (int partyid in this.GetResult.allow_partys.partyid)
             {
                 DepartmentBody body = this.CreateDepartemnt(partyid, allDepartment, allMember);
                 this.Departments.Add(body);
             }
         }
         if (this.GetResult.allow_tags != null && this.GetResult.allow_tags.tagid != null && this.GetResult.allow_tags.tagid.Count > 0)
         {
             Tags tags    = new Tags();
             var  allTags = tags.FindTagsCollection(this.AccessToken);
             this.Tags = new List <Contacts.Tags.Result.Tag>();
             foreach (int tagid in this.GetResult.allow_tags.tagid)
             {
                 var tag = allTags.taglist.FirstOrDefault(e => e.tagid == tagid);
                 this.Tags.Add(tag);
             }
         }
         if (this.GetResult.allow_userinfos != null && this.GetResult.allow_userinfos.user != null && this.GetResult.allow_userinfos.user.Count > 0)
         {
             this.Members = new List <Member.Result>();
             Member member = new Member();
             foreach (var user in this.GetResult.allow_userinfos.user)
             {
                 var _member = member.Get(this.AccessToken, user.userid);
                 this.Members.Add(_member);
             }
         }
     }
 }
Beispiel #2
0
            DepartmentBody CreateDepartemnt(int deptid, List <Department.RequestBody> departments, List <Member.Result> members)
            {
                DepartmentBody body = null;
                var            dept = departments.FirstOrDefault(e => e.id == deptid);

                if (dept != null)
                {
                    var member = members.Where(e => e.department.Contains(deptid)).ToList();
                    body = DepartmentBody.ConvertTo(dept, member);

                    List <int> deptids = departments.Where(e => e.parentid == deptid).Select(e => e.id).ToList();
                    if (deptids != null && deptids.Count > 0)
                    {
                        body.Kids = new List <DepartmentBody>();
                        foreach (int id in deptids)
                        {
                            var department = this.CreateDepartemnt(id, departments, members);
                            body.Kids.Add(department);
                        }
                    }
                }
                return(body);
            }