This article highlights a pattern which is used to return an appropriate validation outcome based on the output of the stored procedure doing the business rule validations.
Scenario
In an ASP.NET Web Application Project, we often have requirements to do some validations in the stored procedures and return an appropriate message to the front-end. Further actions will be made based on the validation result.
Validation Response
To address the above scenario, I prefer to have an Interface based validation response being returned from the DAL layer to the consuming code.
The code for the desired Interface is as follows,
In an ASP.NET Web Application Project, we often have requirements to do some validations in the stored procedures and return an appropriate message to the front-end. Further actions will be made based on the validation result.
Validation Response
To address the above scenario, I prefer to have an Interface based validation response being returned from the DAL layer to the consuming code.
The code for the desired Interface is as follows,
- public interface IResponse
- {
- bool Success { get; set; }
- string Message { get; set; }
- }
Next is we can have our own custom class as shown below which will inherit this interface for doing a specific validation.
However, if the validation fails as per our logic or any exception is thrown, then Success is set to false and Message will have the desired validation message which will be displayed to the user.
- public class ValidationResponse : IResponse
- {
- bool Success { get; set; }
- string Message { get; set; }
- }
When the validation results in the expected outcome, Success boolean property is set to true and the Message will have a standard message for eg., "SUCCESS".
However, if the validation fails as per our logic or any exception is thrown, then Success is set to false and Message will have the desired validation message which will be displayed to the user.
The API in the DAL layer would have the return type as IResponse which gives us the flexibility to return any type of class implementing the interface.
- public IResponse DoSomeValidation()
- {
- // validation logic goes here..
- }
Requirement is to validate the password update activity by passing the current password and new password hash as inputs to the stored procedure and return the validation response.

Naveen BishtPosted Jul 24, 2017, 4:15 AM
It is nice, can we do some more validation like based on user roles, for eg. if user a has rights of admin have to view some textbox on page, and another user subamdin have to use same page but the validation of admin will not apply for subadmin for this there is some diffrent validation based on roles.