/// <summary> /// 根据部门ID得到进出库信息 /// </summary> public dynamic Load(string username, Guid orgId, int pageindex, int pagesize) { var service = _factory.Create(username); if (service.Orgs.Count == 0) //用户没有任何可见机构 { return(new { total = 0, records = 0, page = pageindex }); } var orgIds = service.Orgs.Select(u => u.Id).ToArray(); //用户可访问的机构ID var orgs = _orgRepository.GetSubOrgs(orgId) //点击的节点与用户可访问的机构合并 .Where(u => orgIds.Contains(u.Id)) .Select(u => u.Id).ToArray(); var keys = service.Resources.Select(r => r.Key); //用户可访问的资源的KEY列表 Expression <Func <Stock, bool> > exp = u => u.OrgId != null && orgs.Contains(u.OrgId.Value) && (u.Viewable == "" || keys.Contains(u.Viewable)); var stocks = _repository.Find(pageindex, pagesize, "", exp); int total = _repository.GetCount(exp); return(new { records = total, total = (int)Math.Ceiling((double)total / pagesize), rows = stocks, page = pageindex }); }
/// <summary> /// 得到部门的所有子部门 /// <para>如果orgId为0,表示取得所有部门</para> /// </summary> public GridData LoadAllChildren(Guid orgId) { var query = _repository.GetSubOrgs(orgId); return(new GridData { page = 1, rows = query.ToList(), records = query.Count(), total = 1 }); }
/// <summary> /// 根据部门ID得到进出库信息 /// </summary> public dynamic Load(int orgId, int pageindex, int pagesize) { IEnumerable <Stock> Stocks; var user = SessionHelper.GetSessionUser <LoginUserVM>(); var loginOrgs = user.AccessedOrgs.Select(u => u.Id).ToArray(); int total; if (orgId == 0) { if (loginOrgs.Length == 0) //改用户没有任何可见机构 { Stocks = _repository.Find(pageindex, pagesize, "", u => u.User == user.User.Account); total = _repository.GetCount(u => u.User == user.User.Account); } else { Stocks = _repository.LoadInOrgs(pageindex, pagesize, loginOrgs); total = _repository.GetStockCntInOrgs(loginOrgs); } } else //加载选择的机构及用户可访问的所有子机构 { var orgs = _orgRepository.GetSubOrgs(orgId).Where(u => loginOrgs.Contains(u.Id)); List <int> orgIds = orgs.Select(u => u.Id).ToList(); orgIds.Add(orgId); Stocks = _repository.LoadInOrgs(pageindex, pagesize, orgIds.ToArray()); total = _repository.GetStockCntInOrgs(orgIds.ToArray()); } return(new { total = total, list = Stocks, pageCurrent = pageindex }); }
/// <summary> /// 得到部门的所有子部门 /// <para>如果orgId为0,表示取得所有部门</para> /// </summary> public IList <Org> LoadAllChildren(int orgId) { return(_repository.GetSubOrgs(orgId).ToList()); }
/// <summary> /// 获取当前组织的所有下级组织 /// </summary> private Guid[] GetSubOrgIds(Guid orgId) { var orgs = _orgRepository.GetSubOrgs(orgId).Select(u => u.Id).ToArray(); return(orgs); }