How To Start Business Operation in Code
The default behavior of BO is that the operation is represented in the UI via the appropriate control, it may be an Action or ARM item, see Business Operations. End-User Capabilities for more details. By activating these controls, the user initiates the start of Business Operations. Xafari provides the feature to run BO from a console application, this is described in Business Operation in Console topic. In addition, it is possible for the developer to start BO from custom code at any desired moment. It will be enough to create an instance, set properties and call the Execute() method.
As an example, let's take a look at a ChangeFreightContext Business Operation of the Northwind DC demo app. This is a context-dependent Business Operation, its context is the Order objects, the operation is available in the Actions|Context Business Operations menu.
Before performing this operation takes the collection of the selected Order objects and Percent value, they are the parameters of the operation.
This operation increases the cost of freight on a specified percentage. After specifying all the parameters and clicking OK, the user will get the following result.
ChangeFreightContext Business Operation is implemented in the Xafari.Northwind.DC.BusinessOperations|ChangeFreightContext.cs file of the Northwind DC demo installed with Xafari.
The development of the context-dependent BO is described in the Business Operation Class topic.
To start this operation from arbitrary code, it is possible to use the following DirectExecuteChangeFreightContext method in custom logic:
// Creating, initializing, and running the ChangeFreightContext BO.
void DirectExecuteChangeFreightContext(ICollection<Order> OrderList)
var businessOperation = new ChangeFreightContext();
businessOperation.Orders = OrderList;
businessOperation.Percent = 10;
' Creating, initializing, and running the ChangeFreightContext BO.
Private Sub DirectExecuteChangeFreightContext(ByVal OrderList As ICollection(Of Order))
Dim businessOperation = New ChangeFreightContext()
businessOperation.Orders = OrderList
businessOperation.Percent = 10
The code snippet above creates ChangeFreightContext instance, sets Orders and Percent properties and call Execute() method.
This approach extends the use of BO for nontrivial business scenarios.
Another use case is presented in the following code, which starts the arbitrary BO with default parameters:
// Creating and running an arbitrary BO.
void DirectCreateAndExecuteBusinessOperationById(string businessOperationId)
var businessOperation = BusinessOperationBase.CreateInstance(businessOperationId);
' Creating and running an arbitrary BO.
Private Sub DirectCreateAndExecuteBusinessOperationById(ByVal businessOperationId As String)
Dim businessOperation = BusinessOperationBase.CreateInstance(businessOperationId)