Stuff and things

This commit is contained in:
2021-06-29 19:00:13 -04:00
parent 0ff42f148a
commit 962ad3383f
22 changed files with 320 additions and 226 deletions

View File

@@ -1,73 +0,0 @@
//using Newtonsoft.Json;
//using PartSource.Data.Shopify;
//using PartSource.Services.Integrations;
//using Ratermania.Shopify;
//using System;
//using System.Collections.Generic;
//using System.Diagnostics.CodeAnalysis;
//using System.Text;
//using System.Threading.Tasks;
//namespace PartSource.Services
//{
// public class MetafieldService
// {
// private readonly ShopifyClient _shopifyClient;
// public MetafieldService(ShopifyClient shopifyClient)
// {
// _shopifyClient = shopifyClient;
// }
// [SuppressMessage("Globalization", "CA1308:Normalize strings to uppercase", Justification = "Lowercase is expected by Shopify")]
// public async Task SaveMetafield<T>(T shopifyEntity, IList<int> vehicleIds, string @namespace) where T : ShopifyEntity
// {
// if (vehicleIds.Count == 0)
// {
// return;
// }
// string json = JsonConvert.SerializeObject(vehicleIds);
// if (json.Length >= 100000)
// {
// // TODO: Logging
// return;
// }
// string key = @namespace.ToLowerInvariant().Replace(" ", "_");
// if (key.Length > 20)
// {
// key = key.Substring(0, 20);
// }
// Metafield metafield = new Metafield
// {
// Namespace = "position",
// Key = key,
// Value = json,
// ValueType = "json_string",
// OwnerResource = "product",
// OwnerId = shopifyEntity.Id
// };
// await _shopifyClient.Metafields.Add(metafield);
// }
// public async Task DeleteMetafields<T>(long shopifyId) where T : ShopifyEntity
// {
// IDictionary<string, object> parameters = new Dictionary<string, object>
// {
// { "metafield[owner_id]", shopifyId},
// { "metafield[owner_resource]", "product" },
// { "namespace", "position" },
// };
// IEnumerable<Metafield> metafields = await _shopifyClient.Metafields.Get(parameters);
// foreach (Metafield metafield in metafields)
// {
// await _shopifyClient.Metafields.Delete(metafield);
// }
// }
// }
//}

View File

@@ -1,5 +1,6 @@
using Microsoft.EntityFrameworkCore;
using PartSource.Data;
using PartSource.Data.Contexts;
using PartSource.Data.Dtos;
using PartSource.Data.Models;
using System;

View File

@@ -8,6 +8,7 @@
<ItemGroup>
<PackageReference Include="AutoMapper" Version="10.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Ratermania.Shopify" Version="1.3.1" />
</ItemGroup>
<ItemGroup>

View File

@@ -1,5 +1,6 @@
using Microsoft.EntityFrameworkCore;
using PartSource.Data;
using PartSource.Data.Contexts;
using PartSource.Data.Models;
using System.Threading.Tasks;

View File

@@ -0,0 +1,34 @@
using PartSource.Data.Contexts;
using PartSource.Data.Models;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Ratermania.Shopify.Resources;
namespace PartSource.Services
{
public class ShopifyChangelogService
{
private readonly PartSourceContext _partsourceContext;
public ShopifyChangelogService(PartSourceContext partsourceContext)
{
_partsourceContext = partsourceContext;
}
public async Task AddEntry<T>(T data) where T : BaseShopifyResource
{
ShopifyChangelog shopifyChangelog = new ShopifyChangelog
{
ResourceType = typeof(T),
ShopifyId = data.Id,
Data = data,
Timestamp = DateTime.Now
};
await _partsourceContext.AddAsync(shopifyChangelog);
await _partsourceContext.SaveChangesAsync();
}
}
}