Initial commit
This commit is contained in:
62
PartSource.Automation/Jobs/DeleteProducts.cs
Normal file
62
PartSource.Automation/Jobs/DeleteProducts.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using PartSource.Data.Shopify;
|
||||
using PartSource.Services;
|
||||
using PartSource.Automation.Jobs.Interfaces;
|
||||
using PartSource.Automation.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using PartSource.Data;
|
||||
using PartSource.Data.Models;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PartSource.Services.Integrations;
|
||||
using PartSource.Automation.Models;
|
||||
|
||||
namespace PartSource.Automation.Jobs
|
||||
{
|
||||
public class DeleteProducts : IAutomationJob
|
||||
{
|
||||
private readonly ShopifyClient _shopifyClient;
|
||||
|
||||
public DeleteProducts(ShopifyClient shopifyClient)
|
||||
{
|
||||
_shopifyClient = shopifyClient;
|
||||
}
|
||||
|
||||
// If this job fails, oh well. Run it again and again until it works, or use the Shopify UI (LOL)
|
||||
public async Task<AutomationJobResult> Run()
|
||||
{
|
||||
Console.WriteLine("This job will delete ALL PRODUCTS from Shopify. If you really want to delete EVERY SINGLE PRODUCT, type 'mechanical keyboard' below.");
|
||||
string input = Console.ReadLine();
|
||||
|
||||
if (input != "mechanical keyboard")
|
||||
{
|
||||
return new AutomationJobResult
|
||||
{
|
||||
IsSuccess = true
|
||||
};
|
||||
}
|
||||
|
||||
IEnumerable<Product> products = await _shopifyClient.Products.Get();
|
||||
|
||||
while (products != null)
|
||||
{
|
||||
foreach (Product product in products)
|
||||
{
|
||||
bool result = await _shopifyClient.Products.Delete(product);
|
||||
}
|
||||
|
||||
products = await _shopifyClient.Products.GetNext();
|
||||
|
||||
Console.Write('.');
|
||||
}
|
||||
|
||||
return new AutomationJobResult
|
||||
{
|
||||
Message = "All products deleted. Don't forget to truncate the ImportData table",
|
||||
IsSuccess = true
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user