shoc-backend/SeaHaven.Services/Helpers/WorkOrderUpliftEvidenceAssociation.cs

48 lines
1.4 KiB
C#
Raw Normal View History

using SeaHaven.DataServices.Interfaces;
namespace SeaHaven.Services.Helpers
{
public static class WorkOrderUpliftEvidenceAssociation
{
public static IReadOnlyList<int> Normalize(int? single, IEnumerable<int>? many)
{
var ids = new List<int>();
if (single is int one && one > 0)
ids.Add(one);
if (many == null)
return ids;
foreach (var id in many)
{
if (id > 0 && !ids.Contains(id))
ids.Add(id);
}
return ids;
}
public static async Task RequirePassedAsync(
IVendorDocumentDataService documents,
IReadOnlyList<int> documentIds,
int dispatchId,
int vendorId,
CancellationToken cancellationToken)
{
foreach (var documentId in documentIds)
{
var evidence = await documents.GetUpliftEvidenceAsync(
documentId,
dispatchId,
vendorId,
cancellationToken);
if (evidence == null)
{
throw new InvalidOperationException(
"The selected evidence document is not available or has not passed scanning");
}
}
}
}
}