Using business logic callbacks
XData allows to use business logic callbacks to interact back-end modules with front-end using synchronous Callback and asynchronous PostData models. Synchronous calls can return result value. Callbacks can be used with three-tier-architecture as well as with client-server model. Callbacks has provided business logic clear, complete view and allows debug same code in two-tier environment as code will be executed in three-tier.
public class InvoiceLogic : XDataLogic<Invoice>
{
public CustomLogic<Invoice> TestCustomLogic => (objects => {
Log.Write(MessageType.Information,
() => $"TestCustomLogic called with {objects.Length} objects");
foreach (var invoice in objects)
{
var i = invoice;
invoice.PostData("testPost", () => Encoding.UTF8.GetBytes(i.DocNumb));
var p = Encoding.UTF8.GetBytes(i.DocNumb);
var r = i.Callback("testCall", ref p);
Log.Write(MessageType.Information, () =>
@$"Call for \"{i.DocNumb}\" returned \"{r}\" with data
\"{(p == null ? null : Encoding.UTF8.GetString(p))}\"");
}
return true;
});
}