AfterEntityUpdate

The AfterEntityUpdateCommand handler runs after an entity has been successfully updated in the system. It gives you a chance to perform additional actions, such as logging changes, triggering notifications, updating related entities, or executing custom business logic.

When to Use

  • Logging updates for audit purposes.

  • Sending notifications after certain changes.

  • Updating related entities or aggregates.

  • Triggering downstream processes when an entity changes.

Sample API Implementation

using Bloqs.App.Engine.Commands;
using Bloqs.App.Engine.Commands.After;
using Templates.SampleApp.Models.Data;

namespace Templates.SampleApp.Api.Commands.Activities;

[EntityCommandHandler<Activity>]
public class AfterActivityUpdate
    : ICommandHandler<AfterEntityUpdateCommand, AfterEntityUpdateCommandResult>
{
    public Task<AfterEntityUpdateCommandResult> HandleAsync(
        AfterEntityUpdateCommand command,
        CancellationToken cancellationToken = default
    )
    {
        var activity = (Activity)command.DataEntities.First();

        Console.WriteLine($"{AppConstants.App.Name} [API]: Activity updated: " + activity.Name);

        // Example: trigger some post-update logic
        // NotifyUsers(activity);

        return Task.FromResult(AfterEntityUpdateCommandResult.CreateSuccess());
    }
}

Sample UI Implementation (Blazor WASM)

using Bloqs.App.Engine.Commands;
using Bloqs.App.Engine.Commands.After;
using Templates.SampleApp.Models.Data;

namespace Templates.SampleApp.UserInterface.Commands;

[EntityCommandHandler<Activity>]
public class AfterActivityUpdate
    : ICommandHandler<AfterEntityUpdateCommand, AfterEntityUpdateCommandResult>
{
    public Task<AfterEntityUpdateCommandResult> HandleAsync(
        AfterEntityUpdateCommand command,
        CancellationToken cancellationToken = default
    )
    {
        var activity = (Activity)command.DataEntities.First();

        Console.WriteLine($"{AppConstants.App.Name} [UI]: Activity updated: " + activity.Name);

        // Example: refresh UI or trigger UI notifications

        return Task.FromResult(AfterEntityUpdateCommandResult.CreateSuccess());
    }
}

Notes

  • This handler runs only after the update is successfully applied.

  • You can implement it in both API and UI projects depending on where the post-update logic needs to run.

Last updated