I have an Account model with an editable list of users which I can assign to the account.
I need to check for duplicates as I'm adding a user into the list, plus I need to check the database to make sure that the user has NOT been assigned to another account. I'm not trusting the UI to make sure it filters out available users.
BTW this is an MVC application, so any errors will be displayed when the form is posted back. I don't need immediate feedback if I try and add a user already in the list (in memory) or if they've since been allocated to another account.
So, while I can do a list.Contains(userId) call in the list.Add method for the in-memory check, I need to run an expensive rule to look at the database before the save occurs.
Is it just a case of creating a "command style" object like ExistsCommand and use that to create a custom rule in the parent Account model which loops through all the children making sure they are free to be assigned? I think that's the way to go, just need a nod I'm on the right track.
And I'll set the priority of this so it only runs if all the other rules are checked and passed first.
PS.
I don't update the children, users are either added to or removed from the account.
Thanks,
Richard.