protected virtual void InterceptChange(TenantEntity entity, UpdateOperations operations) { if (TenantFilter.AppTenantID == 0) { throw new HttpRequestValidationException(); } if (operations == UpdateOperations.Add) { entity.AppTenantID = TenantFilter.AppTenantID; } if (operations == UpdateOperations.Change) { int originalTenant = CurrentDataSource.Entry(entity).OriginalValues.GetValue <int>("AppTenantID"); if (originalTenant != TenantFilter.AppTenantID) { throw new HttpRequestValidationException(); } if (originalTenant != entity.AppTenantID) { throw new Exception("Entity cannot move across tenants"); } } if (operations == UpdateOperations.Delete) { int originalTenant = CurrentDataSource.Entry(entity).OriginalValues.GetValue <int>("AppTenantID"); if (originalTenant != TenantFilter.AppTenantID) { throw new HttpRequestValidationException(); } } }