Hey velum,
Yeah, it may sound easy, and it is actually easy once things are clear 
Here is another example, of the class that resides in the Service Layer called VerifyCountryProcessor.cs. Its' responsibility to create a broken rule and add it to the BrokenRulesList of the process result if the rule is invalid
using System;
using System.Collections.Generic;
using System.Text;
using NetTiers.Data;
using NetTiers.Entities;
using NetTiers.Services;
namespace NetTiers.Services.Pipline
{
/// <summary>
/// Processor to verify Country Name if exists in Database
/// </summary>
public class VerifyCountryProcessor : ProcessorBase
{
private Entities.Country _country;
private GenericProcessorResult genericProcessorResult;
/// <summary>
/// Country Processor
/// </summary>
/// <param name="country"></param>
public VerifyCountryProcessor(Entities.Country country)
{
this._country = country;
}
/// <summary>
/// Process the IProcessResult
/// </summary>
/// <returns></returns>
public override IProcessorResult Process()
{
_country.AddValidationRuleHandler(ValidateIfCountryExists, "CountryExists");
//check country
_country.Validate();
if (!_country.IsValid)
ProcessResult.AddBrokenRulesList(typeof(Entities.Country), _country.BrokenRulesList);
return ProcessResult;
}
private bool ValidateIfCountryExists(object target, Entities.Validation.ValidationRuleArgs e)
{
CountryService CountryService = new CountryService();
string Where = string.Format("CountryName = '{0}'", _country.CountryName);
TList<Country> CountryList = CountryService.Find(Where);
e.Description = string.Format("The {0} already exists and cannot be added or updated.", _country.CountryName);
if (CountryList.Count > 0 && _country.CountryId == CountryList[0].CountryId)
{
return true;
}
else if (CountryList.Count > 0)
{
return false;
}
else
{
return true;
}
}
/// <summary>
/// ProcessResult
/// </summary>
public override IProcessorResult ProcessResult
{
get
{
if (genericProcessorResult == null)
{
genericProcessorResult = new GenericProcessorResult();
}
return genericProcessorResult;
}
}
}
}
velum:Thanks Mike!
This looks like exactly what I need. It looks simple, but somehow all these things about processors and validators was a bit blurry in my mind.
Cheers!
JF
Mike Shatny
--------------------------------------------------------------
Member of the .netTiers team http://www.nettiers.com
--------------------------------------------------------------