/// <summary> /// Delete all objects from database that match a specified resource category. /// </summary> /// <param name="resourceCategory">The resource category to remove all objects from.</param> /// <param name="resourceType">The type of resource to look for.</param> /// <param name="connectionString">If you need to connect to a specific database, use this to pass the connection string. Otherwise, the default connection string will be used (WinterConnectionInformation.ActiveConnectionString)</param> public void DeleteFromDatabaseByCategory(Category resourceCategory, GameObjectTypeEnum resourceType, string connectionString = "") { if (resourceType == GameObjectTypeEnum.Area) { using (AreaRepository repo = new AreaRepository(connectionString)) { repo.DeleteAllByCategory(resourceCategory); } } else if (resourceType == GameObjectTypeEnum.Conversation) { using (ConversationRepository repo = new ConversationRepository(connectionString)) { repo.DeleteAllByCategory(resourceCategory); } } else if (resourceType == GameObjectTypeEnum.Creature) { using (CreatureRepository repo = new CreatureRepository(connectionString)) { repo.DeleteAllByCategory(resourceCategory); } } else if (resourceType == GameObjectTypeEnum.Item) { using (ItemRepository repo = new ItemRepository(connectionString)) { repo.DeleteAllByCategory(resourceCategory); } } else if (resourceType == GameObjectTypeEnum.Placeable) { using (PlaceableRepository repo = new PlaceableRepository(connectionString)) { repo.DeleteAllByCategory(resourceCategory); } } else if (resourceType == GameObjectTypeEnum.Script) { using (ScriptRepository repo = new ScriptRepository(connectionString)) { repo.DeleteAllByCategory(resourceCategory); } } else if (resourceType == GameObjectTypeEnum.Tileset) { using (TilesetRepository repo = new TilesetRepository(connectionString)) { repo.DeleteAllByCategory(resourceCategory); } } else { throw new NotSupportedException(); } // Now remove the category itself. using (CategoryRepository repo = new CategoryRepository()) { Category dbCategory = repo.GetByID(resourceCategory.ResourceID); repo.Delete(dbCategory); } }