asp.net - Creating list of users when developing an organisational hierarchy in C# -
so have build hierarchy whereby admin can create teams , sub-teams. there can infinite sub-teams , each team has have manager member of it's parent team (but not manager of it's parent team).
my issue this: how create list of users admin choose (when creating sub-team) whereby user neither manager nor member of of sub-teams parent teams?
i using linq sql in asp.net, , database schema contains follows: team
- teamuser
- user
team
contains fields such teamid, teamname, parentteamid , managerid. teamuser
made of teamid , userid , user
made of userid , name , contact info etc.
at moment code looks list selectlist
viewbag.userid = new selectlist(db.users.where(u => db.teamusers.where(t => t.teamid == id && t.userid == u.userid).count() == 0), "userid", "firstname");
the following method receives subteam and:
- marks manager ineligible,
- traverses parents of subteam, marking users in parent teams ineligible
- then returns list of ids of users have not been marked ineligible.
here's code:
public static list<int> geteligibleusersforteam(team subteam) { list<int> ineligibleusers = new list<int>(); ineligibleusers.add(subteam.managerid); team parent = db.teams.find(subteam.parentteamid); while (parent != null) { ineligibleusers.addrange(parent.users.select(x = x.id).tolist()); team parent = db.teams.find(parent.parentteamid); } return db.users.asenumerable().where(x => ineligibleusers.contains(x.id) == false).tolist(); }
Comments
Post a Comment