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.
30 lines
838 B
30 lines
838 B
using Connected.Data.DataProtection;
|
|
using Connected.Data.EntityProtection;
|
|
using Connected.Entities;
|
|
using Connected.Middleware;
|
|
using Connected.Validation;
|
|
|
|
namespace Connected.Logistics.Types.WarehouseLocations;
|
|
internal class WarehouseLocationProtection : MiddlewareComponent, IEntityProtector<IWarehouseLocation>
|
|
{
|
|
public WarehouseLocationProtection(IWarehouseLocationCache cache)
|
|
{
|
|
Cache = cache;
|
|
}
|
|
|
|
public IWarehouseLocationCache Cache { get; }
|
|
|
|
public async Task Invoke(EntityProtectionArgs<IWarehouseLocation> args)
|
|
{
|
|
if (args.State != State.Deleted)
|
|
return;
|
|
/*
|
|
* We are protecting the children because warehouse locations support nesting entities.
|
|
*/
|
|
if (args.Entity.ItemCount > 0)
|
|
throw ValidationExceptions.ReferenceExists(args.Entity.GetType(), args.Entity.Id);
|
|
|
|
await Task.CompletedTask;
|
|
}
|
|
}
|