Path: redb/redb.Templates/templates/redb-worker/RedbWorker.Module/Services/OrderService.cs Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Templates/templates/redb-worker/RedbWorker.Module/Services/OrderService.cs ---- using redb.Core; using redb.Core.Models.Entities; using redb.Route.Abstractions; using RedbWorker.Module.Models; using RedbWorker.Module.Xml; namespace RedbWorker.Module.Services; /// The work done on an order. Each method is one ProcessWithRedb step of a route. public static class OrderService { /// /// Stores the order, or answers it as a duplicate when an order with the same id is already there. /// Sets the receipt as the new body. /// /// /// Runs inside .Transacted(). The order id is the object's unique key, so two files with the /// same id that arrive at the same time cannot both be stored: the second fails on the key, rolls /// back, stays in the inbox and is answered as a duplicate on the next poll. /// public static async Task RegisterAsync(IRedbService redb, IExchange exchange, CancellationToken ct) { var xml = (OrderXml)exchange.In.Body!; exchange.In.Headers[WorkerHeaders.OrderId] = xml.OrderId; var isDuplicate = await redb.Query().Where(o => o.OrderId == xml.OrderId).AnyAsync(); if (isDuplicate) { exchange.In.Headers[WorkerHeaders.Status] = ReceiptStatuses.Duplicate; exchange.In.Body = new OrderReceiptXml { OrderId = xml.OrderId, Status = ReceiptStatuses.Duplicate, Reason = "An order with this id was received before.", }; return; } await redb.SaveAsync(new RedbObject { Name = xml.OrderId, ValueUnique = xml.OrderId, Props = new Order { OrderId = xml.OrderId, Customer = xml.Customer, Amount = xml.Amount, Currency = xml.Currency, SourceFile = exchange.In.GetHeader(WorkerHeaders.FileName) ?? "", }, }, ct); exchange.In.Headers[WorkerHeaders.Status] = ReceiptStatuses.Accepted; exchange.In.Body = new OrderReceiptXml { OrderId = xml.OrderId, Status = ReceiptStatuses.Accepted }; } }