Implementing Operations in Bloqs

Operations in Bloqs are non-CRUD actions that can be executed within the system. Unlike standard Create, Read, Update, Delete actions, an operation represents a custom task or workflow you want to run.

  • Operations have an input entity that is sent to the API.

  • They can only be implemented on the API side.

  • The UI can trigger operations via a dedicated page.


Declaring an Operation in the Model

To add an operation, first declare its input class and register the operation in your app model.

.AddEntityClass<SendMailInput>()
.AddOperation(new Operation()
{
    Id = AppConstants.Operations.SendMail,
    Name = AppConstants.Operations.SendMailName,
})

Input Entity Class

using Bloqs.App.Engine.Entities;

namespace Templates.SampleApp.Models.Operations;

public class SendMailInput : Entity
{
    public required string MailAddress { get; set; }
    public required string Message { get; set; }
}

This entity defines the input required for the operation — in this case, an email address and a message body.


Implementing the Operation in the API

On the API side, you implement the operation by creating an Operation Command Handler.

This handler takes the SendMailInput object and performs the actual email sending logic.

Last updated