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.
|
|
|
|
using Connected.Middleware;
|
|
|
|
|
using Connected.Validation;
|
|
|
|
|
|
|
|
|
|
namespace Logistics.Types.Packaging;
|
|
|
|
|
internal sealed class InsertPackingValidator : MiddlewareComponent, IValidator<InsertPackingArgs>
|
|
|
|
|
{
|
|
|
|
|
public InsertPackingValidator(IPackingService packingService)
|
|
|
|
|
{
|
|
|
|
|
PackingService = packingService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IPackingService PackingService { get; }
|
|
|
|
|
|
|
|
|
|
public async Task Validate(InsertPackingArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (await PackingService.Select(new SelectPackingArgs
|
|
|
|
|
{
|
|
|
|
|
Ean = args.Ean
|
|
|
|
|
}) is not null)
|
|
|
|
|
{
|
|
|
|
|
throw ValidationExceptions.ValueExists(nameof(args.Ean), args.Ean);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal sealed class UpdatePackingValidator : MiddlewareComponent, IValidator<UpdatePackingArgs>
|
|
|
|
|
{
|
|
|
|
|
public UpdatePackingValidator(IPackingService packingService)
|
|
|
|
|
{
|
|
|
|
|
PackingService = packingService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IPackingService PackingService { get; }
|
|
|
|
|
|
|
|
|
|
public async Task Validate(UpdatePackingArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (await PackingService.Select(new SelectPackingArgs
|
|
|
|
|
{
|
|
|
|
|
Ean = args.Ean
|
|
|
|
|
}) is Packing entity && entity.Id != args.Id)
|
|
|
|
|
{
|
|
|
|
|
throw ValidationExceptions.ValueExists(nameof(args.Ean), args.Ean);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|