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 { public WarehouseLocationProtection(IWarehouseLocationCache cache) { Cache = cache; } public IWarehouseLocationCache Cache { get; } public async Task Invoke(EntityProtectionArgs 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; } }