using Connected.Entities; using Connected.Middleware; using Connected.Validation; namespace Logistics.Types.Warehouses; internal sealed class InsertWarehouseValidator : MiddlewareComponent, IValidator { public InsertWarehouseValidator(IWarehouseCache cache) { Cache = cache; } private IWarehouseCache Cache { get; } public async Task Validate(InsertWarehouseArgs args) { if (await (from e in Cache where string.Equals(e.Code, args.Code, StringComparison.OrdinalIgnoreCase) select e).AsEntity() is not null) throw ValidationExceptions.ValueExists(nameof(args.Code), args.Code); } } internal sealed class UpdateWarehouseValidator : MiddlewareComponent, IValidator { public UpdateWarehouseValidator(IWarehouseCache cache) { Cache = cache; } private IWarehouseCache Cache { get; } public async Task Validate(UpdateWarehouseArgs args) { if (await (from e in Cache where string.Equals(e.Code, args.Code, StringComparison.OrdinalIgnoreCase) && e.Id == args.Id select e).AsEntity() is not null) throw ValidationExceptions.ValueExists(nameof(args.Code), args.Code); } }