Admin only views

VictorConnerVictorConner SEMember, University ✭✭

Hi, Im wondering how you guys solve situations where you need admin only views or where the admin should see more things?

Do you login, get some User object as a response and make all the extra admin layouts in code like: if(User.IsAdmin) View.Add(adminButton); or is there a better approach?

Posts

  • rene_ruppertrene_ruppert DEXamarin Team, University, XamUProfessors Xamurai

    Difficult to answer. First of all: the logic what is possible and what not should never be in the UI layer. This is part of your business logic and fits into the ViewModel, the model or the controller - depends on the specific app and the design patterns you use. The UI can then react to the state of your logic and show or hide certain UI elements. However if the UI by accident shows an "admin" button that it is not supposed to show and the non-admin user clicks it, the app will crash or produce an error but never allow admin-functionality.

    There are different ways how to solve this. You can create different layouts and use either one, depending if user is admin or not. Or you can omit or hide certain UI elements. In XAML with bindings this would be super easy by just binding the visibility to some bool flag in your view model. If you are creating your UI code, your approach above is also perfectly valid.

Sign In or Register to comment.