New Posts New Posts RSS Feed: Validation on Save
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Validation on Save

 Post Reply Post Reply
Author
cefernan View Drop Down
Groupie
Groupie


Joined: 13-Jul-2012
Posts: 70
Post Options Post Options   Quote cefernan Quote  Post ReplyReply Direct Link To This Post Topic: Validation on Save
    Posted: 02-Jan-2013 at 12:39pm
I have two entities in my database that are responsible to control the application access. The structure of "levels" is hierarchical and a specific level never has more rights than your parent.

AccessLevel 
----------------
AccessLevelID
Name
AccessLevelParentID 


AccessLevelRight
----------------
AccessLevelID
ActionID

When I remove a right from a parent, I need to remove this right (if exist) for all children of this level.
 
So, I need to create a kind of validation to assert this business logic. 

I thought to do this creating a validation in an entity partial class:
public override void Validate(IdeaBlade.Validation.VerifierResultCollection validationErrors)

But, in this validation, I need to execute a query and manipulate some data. I don't have an entity manager in that scope.
I can solve my problem creating a trigger in the database, but I don't want to do this.

How can I do it?
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 02-Jan-2013 at 6:18pm
This kind of logic should go into a domain service as part of your unit of work as illustrated here in the context of Cocktail.


You can then call it from a ViewModel before you do the save, or you could even override the CommitAsync method of your unit of work to make sure the logic is executed as part of every commit.
Back to Top
cefernan View Drop Down
Groupie
Groupie


Joined: 13-Jul-2012
Posts: 70
Post Options Post Options   Quote cefernan Quote  Post ReplyReply Direct Link To This Post Posted: 03-Jan-2013 at 10:17am
Ok, I got it.

I'd like to put this business logic in the DomainModel to be possible to others plataforms (through OData) consist the same logic. 

I'll do in my DomainService and if necessary I'll replicate the code.

Thanks Marcel.

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down