Relatude Help

Routes

Endpoints(e => …) maps the module's own routes, for visitors rather than editors: a feed, a form post, a webhook. MapRelatudeCMS() maps them. While the module is not active, they are left out of routing, so a request falls through to whatever else answers it.

A route reads as the visitor through RelatudeCmsContext.DB. Visitors cannot write, so a route that writes uses .Admin, the master admin, after checking what the visitor may do:

public static void Map(IEndpointRouteBuilder endpoints) {
    endpoints.MapGet("/events.ics", (RelatudeCmsContext cms, EventCalendar calendar) => …);
    endpoints.MapPost("/events/{id:guid}/register", Register).DisableAntiforgery();
}

static async Task<IResult> Register(HttpContext http, Guid id, RelatudeCmsContext cms) {
    var e = cms.DB.Query<IEventPage>().Where(id).Execute().FirstOrDefault();   // as the visitor
    if (e == null) return Results.NotFound();
    var form = await http.Request.ReadFormAsync();
    var registration = cms.Admin.CreateAndInsert<IEventRegistration>(r => {
        r.Name = form["name"].ToString();
        r.Seats = 1;
    });
    cms.Admin.SetRelation<IEventRegistration>(registration.Id, r => r.Event, e.Id);
    return Results.Redirect(cms.GetUrl(e) + "?registered=1");
}