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/Logistics.Types/Warehouses/WarehouseValidation.cs

37 lines
1.1 KiB

using Connected.Entities;
using Connected.Middleware;
using Connected.Validation;
namespace Logistics.Types.Warehouses;
internal sealed class InsertWarehouseValidator : MiddlewareComponent, IValidator<InsertWarehouseArgs>
{
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<UpdateWarehouseArgs>
{
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);
}
}