I have the following business rule
A "visitor" role can create an event as long as the date is not in the past. An "agent" or "administrator" role can do any date.
A have an Event object which is created in a "Booking" page. The event date is passed as a query string parameter to the page so I would like to validate the rule before the user enters all the data and submits the form.
Not sure if the approach I used is correct:
I overloaded the Book CanAddObject and put a call to the Booking Page
In Booking page:
private void ApplyAuthorizationRules()
{
if (!Book.CanAddObject(_eventDate) )
{
... hide form and display message
}
}
public static bool CanAddObject(DateTime eventDate)
{
if (eventDate < DateTime.Now)
return (Csla.ApplicationContext.User.IsInRole("Agent") || Csla.ApplicationContext.User.IsInRole("Administrator"));
else
{
// otherwise do a regular validation
return CanAddObject();
}
Is that the correct approach? I wanted to implement a validation rule without instantiating the object but I'm not sure how to do it.
Thank you for your time
Rafael
Copyright (c) Marimer LLC