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/WarehouseLocations/WarehouseLocationProtection.cs

30 lines
828 B

using Connected.Data.DataProtection;
using Connected.Data.EntityProtection;
using Connected.Entities;
using Connected.Middleware;
using Connected.Validation;
namespace 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;
}
}