private void CreateSecurityEntity(int entityId, int parentEntityId, int ownerId, bool safe) { if (entityId == default) { throw new ArgumentException("entityId cannot be default(int)"); } if (parentEntityId != default) { // load or create parent var parent = safe ? EntityManager.GetEntitySafe(parentEntityId, false) : EntityManager.GetEntity(parentEntityId, false); if (parent == null) { throw new EntityNotFoundException( $"Cannot create entity {entityId} because its parent {parentEntityId} does not exist."); } } var entity = new StoredSecurityEntity { Id = entityId, ParentId = parentEntityId, IsInherited = true, OwnerId = ownerId }; _dataProvider.InsertSecurityEntity(entity); }