Operations¶
New Operation¶
You can add a new Operation to a Class in two ways.
First Way¶
- Select your Class
- Click on the Operations tab, placed at the bottom part of the designer
- Click on the button
Second Way¶
- Click on the Operations tab, placed at the bottom part of the designer
- Select the Class you want to add your Operation to, from the Class drop down
- Click on the button
Defining your Business Logic¶
As soon as you add a new Operation into your class, zAppDev will add it into a designed with a default name and a void return type
From this point on, you can define your Business Logic by changing the Operation's definition and adding your required Mamba code into the body of the function
Instance Operations¶
The signature of an Instance Operation has the following syntax:
function return_type OperationName(parameters) {}
/** EXAMPLE **/
function bool CanBeDeleted()
{
bool hasOrders = (Domain.OrderedProduct.GetAll().First(x => x.Order.Status != Domain.Status.Paid) != null);
return !hasOrders;
}
You can use an Object of the Operation's class to call it. An invocation of the CanBeDeleted()
instance Operation might look like:
Domain.Product myProduct = Domain.Product.GetByKey(1);
if(myProduct.CanBeDeleted() == false){
DebugLib.Logger.WriteWarnLine("You cannot delete this Product!");
}
Static Operations¶
To define an Operation as static, simple write the static
keyword right before the function
. Thus, the signature of a Static Operation has the following syntax:
static function return_type OperationName(parameters){}
/** EXAMPLE **/
static function Collection[Domain.Product] GetProductsWithNoPrice()
{
return Domain.Product.GetAll().Where(x => x.Price == 0);
}
You can use the Operation's class to call it. An invocation of the GetProductsWithNoPrice
static Operation might look like:
int productsWithNoPrice = Domain.Product.GetProductsWithNoPrice().Length;
if(productsWithNoPrice > 0){
DebugLib.Logger.WriteWarnLine("There are "+productsWithNoPrice+" priceless (no pun intended, lol) Products in your store!");
}
Available Operations¶
If you right-click on an Operation element, a menu like the following will appear :
Non Static¶
You can click on this item to define your Operation as non static, a.k.a. instance Operation
Attention
This operation is available only for static Operations
Static¶
You can click on this item to define your Operation as static
Attention
This operation is available only for instance Operations
Refactor¶
By refactoring an Operation, you are basically changing its name, but in such a way that it is changed in any other Model that might use it.
Find Usages¶
The Find Usages option is very helpful if you want to find all the Models that might be using your Operation. All the hits will be presented in the Console, inside the Symbols panel. From then on, you will be able to Navigate to each Model that uses your Class, by double-clicking on the record you want, presented in said Console.
Move Up¶
Displays the selected Operation one row higher, in the list of the Class' Operations
Move Down¶
Displays the selected Operation one row lower, in the list of the Class' Operations
Design Rules¶
- The name of an Operation inside a Class, must be unique. (Obviously, different Classes may have Operations with the same name) !!! attention Some Operations are pre-defined, as part of the Domain Model (e.g. GetAll(), Find(), GetByKey() etc.). You cannot define Operations with such names, as they are considered reserved. For a list of pre-defined Operations, check here
- Accessor Operations (Getters & Setters) must be Instance Operations. They cannot be
static
. - Accessor Operations (Getters & Setters) must have the same datatype as the Attribute they are created for
- A Getter Operation must have zero (0) parameters
- A Setter Operation must have exactly one (1) parameters, with the exact same datatype as its parent Attribute
- An Accessor Operation's name (Getter & Setter) cannot be the same as its parent Attribute's name