Example #1
0
 /// <summary>
 /// 数据转换
 /// </summary>
 /// <param name="requestBody"></param>
 /// <param name="special">特殊(单选:顶级节点)</param>
 /// <returns></returns>
 public static DeptSelector ConvertTo(Department.RequestBody requestBody, bool special = false)
 {
     if (requestBody != null)
     {
         return(new DeptSelector()
         {
             Id = (requestBody.id).ToString(),
             Name = requestBody.name,
             ParentId = (requestBody.parentid).ToString(),
             Special = special
         });
     }
     return(null);
 }
Example #2
0
 /// <summary>
 /// 转换
 /// </summary>
 /// <param name="body"></param>
 /// <param name="members"></param>
 /// <returns></returns>
 public static DepartmentBody ConvertTo(Department.RequestBody body, List <Member.Result> members)
 {
     if (body == null)
     {
         throw new ArgumentNullException("body paramter is null value");
     }
     return(new DepartmentBody()
     {
         id = body.id,
         Members = members,
         name = body.name,
         order = body.order,
         parentid = body.parentid
     });
 }
        /// <summary>
        /// 获取部门
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="partyid">部门编号集合</param>
        /// <returns></returns>
        static List <DeptSelector> GetDepartments(string accessToken, List <int> partyid, int deptid = -1)
        {
            if (partyid == null || partyid.Count == 0)
            {
                return(null);
            }

            List <DeptSelector> depts      = new List <DeptSelector>();
            Department          department = new Department();

            foreach (int _partyid in partyid)
            {
                var dept = department.List(accessToken, _partyid);// 部门信息
                if (dept != null && dept.errcode == 0)
                {
                    if (deptid == -1)
                    {
                        Department.RequestBody body = dept.department.FirstOrDefault(e => e.id == _partyid);
                        var item = DeptSelector.ConvertTo(body, true);
                        if (item != null)
                        {
                            depts.Add(item);
                        }
                    }
                    else
                    {
                        var bodys = dept.department.Where(e => e.parentid == deptid).ToList();
                        var items = DeptSelector.ConvertTo(bodys).ToList();
                        if (items != null && items.Count > 0)
                        {
                            depts.AddRange(items);
                        }
                    }
                }
            }
            return(depts);
        }