Ok i have a MVC.net front end using EF and SQL server for the database connectivity. I’ve created a large object with around 100 fields and a web ui to select and edit objects. I use EF to save changes back to the database. All good so far.
What i need to do now is implement some logic to stop edits for some objects and allow for others. For example:
object “01”
is ok for everyone to make changes no changes needed the interface already covers this.
object “02”
is “locked” against all changes when any user opens that object in the web app all fields should be disabled and the whole thing is read only.
object “03”
is locked for some users but unlocked for others so depending on the users roles they will either get the R/O all disabled view or the enabled edit anything view.
I could just right into this and start hacking something together but i just wondered if there is any “prefered” way or simpler way to achieve this? tnx.
Well the preferred way to do this is do it in your View. So you’d have something like
Peronally I wouldn’t have the @User.IsInRole(xxx) in the View I would have that precalculated in an IsAdmin boolean parameter that is passed through in the ViewModel but I put it there for conciseness in this example.