Conditional Delivery of New Objects¶
Consider the following data table. The table name is Order
and it contains the orderAmount
column which will be used in the example:
The code below adds a listener for the create
event for the Order
table.
var orderEventHandler = Backendless.Data.Of( "Order" ).RT();
orderEventHandler.AddCreateListener( "orderAmount > 1000", createdOrder =>
{
Console.WriteLine( $"new Order object has been created. Object ID - {createdOrder["objectId"]}");
} );
Assume the following class represents objects from the Order table:
public class Order
{
public string ObjectId{ get; set; }
public string OrderName{ get; set; }
public double OrderAmount{ get; set; }
}
var orderEventHandler = Backendless.Data.Of<Order>().RT();
orderEventHandler.AddCreateListener( "OrderAmount > 1000", createdOrder =>
{
Console.WriteLine( $"new Order object has been created. Object ID - {createdOrder.ObjectId}");
} );
The event listener will receive only the Order
objects where the amount of order is greater than 1000. This is achieved with the first argument in the AddCreateListener
method. The argument is a where clause
condition, which references the orderAmount
column and requests that the real-time database sends only the matching objects. The second argument is a callback object which will receive any new object which matches the where clause condition. Notice the argument of the delegate function method is the actual object saved in the database.
For more information about the whereClause syntax, see the Condition Syntax section of the guide.