We have a debate about a best practice, which is a view of a .NET architecture design view:
Action: How to manage role-based visibility in UI with Enum? For example: I want to show all Team Type [A, B, C, D, E] to the Administrator but only for Team Type [A, B, C] normal user.
Pre>
I use it like this:
if (IsAdminitrator ()) comboboxTeamtypes.Items.AddRange (Enum.GetNames (typeof (TeamType));
Now I should decide how to apply the second segment. Because enums can not be inherited, I have two alternative approaches:
1) Should I apply another role to specific anum:
public anac TeamType can be found in other {a, b, c}
and then I will have:
other comboboxTeamtypes.Items.AddRange (Enum.GetNames (typeof (TeamTypeOthers ))); 2) Or I should not forget to create any role specific and other teamtip and eliminate the original TeamType Enim values in the UI-code: else {Foreach () TeamTip Team type in Enum.GetValues (typeof (TeamType)) {if (asdf == TeamType.a) comboboxTeamtypes.Items.Add (teamtype); Else if (asdf == TeamType.b) comboboxTeamtypes.Items.Add (Team Type); If (asdf == TeamType.c) ComboboxType Items.ed (team type); }}
I think the first solution is good and clean (though the repetition which is not very good). But now I also make a decision about the use of intensive architecture compared to solution 2 in depth architecture which is probably poor and helps in using the solution 2. The solution for me is 2 ugly and dirty because I'm around the code Do not like the cultivation of loop.
I will change some things and use simple bitmasking for permissions:
Public team teamtype {a = 1, // or 00001b = 2, // or 00010c = 4, // or 00100d = 8, // or 01000E = 16 // or 10000}
Then each user type sets its permission level (each available permission is added together):
int administratorLevel = 32; // 11111 int user level = 7; // 00111
And then when you populate your dropdown in the UI, bitmasking comes in:
ComboboxTem TypeEight. Choose (V => myLevel & amp; v == v). Select (v => Enum.GetName (typeof (TeamType), v)) ;
No comments:
Post a Comment