You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Connected.Logistics/Connected.Logistics.Process.../Listeners/ReceiveItemListener.cs

41 lines
1.2 KiB

using Connected.Logistics.Documents.Receive;
using Connected.Middleware.Annotations;
2 years ago
using Connected.Notifications;
using Connected.Notifications.Events;
using Connected.ServiceModel;
using Microsoft.Extensions.Logging;
namespace Connected.Logistics.Documents.Listeners;
2 years ago
[Middleware<IReceiveDocumentService>(nameof(IReceiveDocumentService.ItemUpdated))]
internal sealed class ReceiveItemListener : EventListener<PrimaryKeyEventArgs<long>>
{
public ReceiveItemListener(ILogger<ReceiveItemListener> logger, IReceiveDocumentService documents)
{
Logger = logger;
Documents = documents;
}
private ILogger<ReceiveItemListener> Logger { get; }
private IReceiveDocumentService Documents { get; }
protected override async Task OnInvoke()
{
if (await Documents.SelectItem(Arguments.Id) is not IReceiveItem item)
{
Logger.LogWarning("The IReceiveItem not found ({id}}.", Arguments.Id);
return;
}
var items = await Documents.QueryItems(item.Document);
await Documents.Patch(new PatchArgs<int>
{
Id = item.Document,
Properties = new Dictionary<string, object>
{
{nameof(IReceiveDocument.OpenItemCount), items.Count(f=>f.PostedQuantity<f.Quantity)}
}
});
}
}