Business Rules

After generating the code, the application is in state to add / edit / delete records in the database. But this is not enough in most of the cases. The application may require more business rules to be implemented to make the application suitable for the customer.

It is as simple as overriding a method in the data objects and providing the requuired logic.


protected override void SetupValidationRules()
{
base.SetupValidationRules();
AddValidationRule(EntityProperties.InvoiceDetails, a => a.InvoiceDetails.Count != 0, "No invoice details provided.");
AddValidationRule(EntityProperties.DeliveryAddress, a =>
{
var res = a.invoiceTypeHelper.SaleInvoice.Equals(a.InvoiceType) && a.DeliveryAddress != null;
return res;
}, "Delivery address must be provided for Sale Invoice");
}

In the above code we have two rules

  • Invoice Details must be provided. An invoice cannot be saved unless there is atleast one invoice detail added to it.
  • If Invoice is a Sale Invoice, Delivery Address must be provided.

If user clicks on "Save" button, following message box is shown.

Invoice Header Business Rule Violation Message Box

The message about "Account not selected" was because underlying column (account_id in tbl_invoice_header) was marked as "not null".