Beispiel #1
0
        public async Task RollbackProduct(long id)
        {
            // MongoDB Settings
            var    database       = context.MongoDbSettings.Value.Databases.FirstOrDefault(x => x.Name == "DeathStar");
            string collectionName = database.Collections.FirstOrDefault(x => x.Name == "PC_Product").Name;

            // Get MongoDB
            var db = context.Database;
            var productCollection = db.GetCollection <Deathstar.Data.Models.PC_Product>(collectionName);

            // Filter
            var filter = Builders <Deathstar.Data.Models.PC_Product> .Filter.Eq(x => x.Id, id);

            // Delete
            await productCollection.DeleteOneAsync(filter);

            // Inventory
            await _inventoryModel.RollbackInventory(id, "PC_Product");

            // Variant
            await _variantModel.RollbackVariant(id);

            // External Ids
            await _externalIdModel.RollbackExternalId(id, "PC_Product");
        }
Beispiel #2
0
        public async Task RollbackInventory(long id, string tableName)
        {
            // MongoDB Settings
            var    database       = context.MongoDbSettings.Value.Databases.FirstOrDefault(x => x.Name == "DeathStar");
            string collectionName = database.Collections.FirstOrDefault(x => x.Name == "PC_Inventory").Name;

            // Get MongoDB
            var db = context.Database;
            var inventoryCollection = db.GetCollection <Deathstar.Data.Models.PC_Inventory>(collectionName);

            // Filter
            var filters = Builders <Deathstar.Data.Models.PC_Inventory> .Filter.Eq(x => x.InternalId, id.ToString());

            filters = filters & Builders <Deathstar.Data.Models.PC_Inventory> .Filter.Eq(x => x.ST_TableName, tableName);

            var dbInventories = await inventoryCollection.Find(filters).ToListAsync();

            // Delete
            await inventoryCollection.DeleteManyAsync(filters);

            // Inventory Table
            string inventoryTable = string.Empty;

            // Set inventory table
            if (tableName == "PC_Product")
            {
                inventoryTable = "PC_ProductInventory";
            }
            else
            {
                inventoryTable = "PC_ProductVariantInventory";
            }

            foreach (var dbInventory in dbInventories)
            {
                // External Ids
                await _externalIdModel.RollbackExternalId(dbInventory.Id, inventoryTable);
            }
        }