Print Page | Close Window

Validation on Save

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2012
Forum Discription: For .NET 4.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3866
Printed Date: 25-Oct-2025 at 1:00pm


Topic: Validation on Save
Posted By: cefernan
Subject: Validation on Save
Date 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?



Replies:
Posted By: mgood
Date 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.

http://drc.ideablade.com/devforce-2012/bin/view/Documentation/unit-of-work-pattern-and-persistence-ignorance#HDomainService - http://drc.ideablade.com/devforce-2012/bin/view/Documentation/unit-of-work-pattern-and-persistence-ignorance#HDomainService

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.


Posted By: cefernan
Date 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.




Print Page | Close Window