using Connected.Middleware; using Connected.Validation; namespace Connected.Logistics.Types.Serials; internal sealed class InsertSerialValidator : MiddlewareComponent, IValidator { public InsertSerialValidator(ISerialService serials) { Serials = serials; } public ISerialService Serials { get; } public async Task Validate(InsertSerialArgs args) { if (await Serials.Select(new SelectSerialArgs { Value = args.Value }) is not null) { throw ValidationExceptions.ValueExists(nameof(args.Value), args.Value); } } }