The Execute method provides a generic CreateCommand to create new entity objects and a generic UpdateCommand to update existing entity objects.

In general, it is recommended that clients use entity specific create commands when creating entity objects and entity specific update commands when updating entity objects.

Entity Specific create command

Example: Create a Space using the SpaceCreateCommand.

var results = corrigoService.Execute(
   new SpaceCreateCommand {CustomerId = customerId, UnitId = unitId};
);

Entity specific update command

Example: Pause a Work Order using the WoPauseCommand.

var results = corrigoService.Execute(
   new WoPauseCommand {WorkOrderId = workOrderId};
);

Create command

Example: Create a Specialty using the CreateCommand.

var results = corrigoService.Execute(
  new CreateCommand
  {
    Entity = new Specialty
    {
       DisplayAs = specialtyName, 
       Instructions = instructions,
       TaxCode = taxCode      
    }
  } 
);

📘

Concurrency Control

The EntityWithOptimisticLockSpecifier class is used to enforce Optimistic Concurrency Control (OCC) model during updates. Corrigo entities that support the EntityWithOptimisticLockSpecifier class expose the concurrency identifier (ConcurrencyId). The ConcurrencyId attribute provides an auto-increment counter representing changes to Entities. The ConcurrencyId is a read-only value. It is often used in real-time integration with Corrigo Entities wherein other data stores have copies of the same logical data, providing a mechanism to determine if concurrent edits have been performed in both copies.

Update command

Most update commands are preceded by a retrieve command to enable the entity records to be properly maintained by managing the ConcurrencyId .
Example: Update WorkZone name using the UpdateCommand.

/* Retrive the WorkZone to be updated */
var workZone = (WorkZone) corrigoService.Retrieve(
   new EntitySpecifier {Id = workZoneId, EntityType = EntityType.WorkZone}, 
   new AllProperties()
);

/* Set WorkZone name */
workZone.DisplayAs = workZoneName;

/* Update WorkZone name */
var command = new UpdateCommand
{
   Entity = workZone,
   PropertySet = new AllProperties()
 };
var operationCommandResponse = corrigoService.Execute(command) as OperationCommandResponse;
        
var responseWithOptimisticLock = operationCommandResponse.EntitySpecifier as EntityWithOptimisticLockSpecifier;

/*WorkZone's ConcurrencyId incremented after update */
workZone.ConcurrencyId = responseWithOptimisticLock.ConcurrencyId;

Routine Commands

Routine commands are identified by the word Routine in the command name. Routine commands are essentially what-if commands and do not commit data when executed but produce an intermediary result set (usually a set of calculated properties based on inputs provided) that can be used in the Execute and Execute Multiple methods.
Example: The WoScheduleRoutine command is used primarily to prepare scheduling data such as Due Date, duration etc.for new or existing Work Orders.

var routine = new WoScheduleRoutine
{
  workOrder = new WorkOrder { WorkZone = new WorkZone { Id = workOrderId } },
  options = WoScheduleOptions.SkipFinancial,
  InputPropertySet = new PropertySet { Properties = inputProperties },
  OutputPropertySet = new PropertySet { Properties = outputProperties }
};

var response  = service.Execute(routine) as WoActionResponse;

Using a Command like WoScheduleRoutine is not the only way to leverage the automation available within the Corrigo Enterprise application, but they uniquely the provide ability to discover the calculated values without committing the records to the database.

To leverage automation during actual Work Order creation, when records are committed upon execution of WoCreateCommand, this same logic is controlled by true/false Properties defined below.

PropertyDescription
ComputeScheduleWhen set to True the WoScheduleRoutine is executed. When set to False, integration client is expected to provide correct values for the properties TimeZone, DtCreated, DtDue, DtOnSiteBy, DtScheduledStart, and DtAcknowledgeBy.
ComputeAssignmentWhen set to True the WoAutoAssignRoutine routine is executed.