Initial commit

This commit is contained in:
2020-04-12 20:52:03 -04:00
parent e750d2848a
commit 01e7627293
249 changed files with 9733 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
using PartSource.Data.Shopify;
using Ratermania.Shopify;
using System;
using System.Collections.Generic;
using System.Text;
namespace PartSource.Services.Integrations
{
public class ShopifyClient : BaseShopifyClient
{
public ShopifyClient(ShopifyOptionsBuilder optionsBuilder) : base(optionsBuilder) { }
public ShopifyResource<Product> Products { get; set; }
public ShopifyResource<Metafield> Metafields { get; set; }
//public ShopifyResource<SmartCollection> SmartCollections { get; set; }
public ShopifyResource<ProductImage> ProductImages { get; set; }
}
}

View File

@@ -0,0 +1,43 @@
using PartSource.Data.Nexpart;
using System;
using System.Configuration;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace PartSource.Services
{
public class NexpartService
{
public async Task<U> SendRequest<T, U>(T requestContent)
{
Envelope envelope = new Envelope();
envelope.Body.Content = (object)(T)requestContent;
XmlSerializer serializer = new XmlSerializer(typeof(Envelope));
StringBuilder sb = new StringBuilder();
using (TextWriter textWriter = (TextWriter)new StringWriter(sb))
serializer.Serialize(textWriter, (object)envelope);
U content;
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", "QUZBNUNDMTQzMUNENDNEQ0E2NjNDMTdCREFEODUwQkItQzhGNUJERjlBMDlDNDQ2NEE2NjczMUNBNDQyN0NCQjk6N0FCMzU3NjYtMDM3OS00REYwLTk2NjUtREFFRTEzODIyRjQz");
try
{
//HttpResponseMessage response = await client.PostAsync(ConfigurationManager.AppSettings["NexpartUrl"], (HttpContent)new StringContent(sb.ToString(), Encoding.UTF8, "text/xml"));
HttpResponseMessage response = await client.PostAsync("http://acespssint.nexpart.com:4001/partselect/1.0/services/PartSelectService.PartSelectHttpSoap11Endpoint/", (HttpContent)new StringContent(sb.ToString(), Encoding.UTF8, "text/xml"));
Stream result = await response.Content.ReadAsStreamAsync();
string str = await response.Content.ReadAsStringAsync();
content = (U)((Envelope)serializer.Deserialize(result)).Body.Content;
}
catch (Exception ex)
{
throw;
}
}
return content;
}
}
}

View File

@@ -0,0 +1,45 @@
using PartSource.Data;
using PartSource.Data.Dtos;
using PartSource.Data.Models;
using System.Collections.Generic;
using System.Linq;
namespace PartSource.Services
{
public class PartService
{
private readonly PartSourceContext _context;
public PartService(PartSourceContext context)
{
_context = context;
}
public Part GetPart(string partNumber, string lineCode)
{
return _context.Parts.FirstOrDefault(p => p.PartNumber == partNumber && p.Manufacturer.LineCode == lineCode);
}
public Part GetPart(int sku)
{
return _context.Parts.FirstOrDefault(p => p.Sku == sku);
}
public PartsAvailability GetInventory(int sku, int storeNumber)
{
return _context.PartAvailabilities.FirstOrDefault(s => s.Store == storeNumber && s.SKU == sku);
}
public IList<Fitment> GetFitments(FitmentSearchDto fitmentSearchDto)
{
return null;
//return _context.Fitments.Where(f =>
// f.ManufacturerCode == fitmentSearchDto.ManufacturerCode &&
// f.PartNumber == fitmentSearchDto.PartNumber &&
// f.BaseVehicleId == fitmentSearchDto.BaseVehicleId &&
// f.EngineConfigId == fitmentSearchDto.EngineConfigId
//).ToList();
}
}
}

View File

@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Configurations>Debug;Release;Also Debug</Configurations>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\ratermania\shopify\Shopify\Shopify.csproj" />
<ProjectReference Include="..\PartSource.Data\PartSource.Data.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore;
using PartSource.Data;
using PartSource.Data.Models;
using System.Threading.Tasks;
namespace PartSource.Services
{
public class SecurityService
{
private readonly PartSourceContext _context;
public SecurityService(PartSourceContext context)
{
_context = context;
}
public async Task<ApiClient> GetApiClientByKeyAsync(string key)
{
return await _context.ApiClients.FirstOrDefaultAsync(c => c.Key == key);
}
}
}

View File

@@ -0,0 +1,137 @@
using Microsoft.EntityFrameworkCore;
using PartSource.Data;
using PartSource.Data.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace PartSource.Services
{
public class VehicleService
{
private readonly PartSourceContext _partSourceContext;
public VehicleService(PartSourceContext partSourceContext)
{
_partSourceContext = partSourceContext;
}
public async Task<IList<VehicleMake>> GetAllMakes()
{
return await _partSourceContext.VehicleMakes.ToListAsync();
}
public async Task<IList<VehicleData>> GetModels(int makeId, int year)
{
return await _partSourceContext.VehicleData.Where(d =>
d.MakeId == makeId
&& d.Year == year
)
.ToListAsync();
}
public async Task<IList<BaseVehicle>> GetBaseVehicles(int makeId, int modelId, int year)
{
return await _partSourceContext.BaseVehicles.Where(d =>
d.MakeId == makeId
&& d.ModelId == modelId
&& d.Year == year
)
.ToListAsync();
}
public async Task<IList<Engine>> GetEngines(int baseVehicleId)
{
return await _partSourceContext.Engines.Where(e => e.BaseVehicleId == baseVehicleId).ToListAsync();
}
public async Task<IList<Engine>> GetEngines(int baseVehicleId, int submodelId)
{
return await _partSourceContext.Engines.Where(e =>
e.BaseVehicleId == baseVehicleId
&& e.SubmodelId == submodelId
)
.ToListAsync();
}
public async Task<IList<Submodel>> GetSubmodels(int makeId, int modelId, int year)
{
return await _partSourceContext.Submodels.Where(s =>
s.MakeId == makeId
&& s.ModelId == modelId
&& s.Year == modelId
)
.ToListAsync();
}
public async Task<VehicleData> GetVehicle(int baseVehicleId, int engineConfigId, int submodelId)
{
return await _partSourceContext.VehicleData.FirstOrDefaultAsync(d =>
d.BaseVehicleId == baseVehicleId
&& d.EngineConfigId == engineConfigId
&& d.SubmodelId == submodelId
);
}
public IList<string> GetYmmFitment(IList<VehicleData> vehicles)
{
if (vehicles.Count == 0)
{
return null;
}
IList<string> fitmentTags = new List<string>();
IList<string> makeModels = vehicles.Select(v => $"{v.MakeName},{v.ModelName}").Distinct().ToList();
foreach (string makeModel in makeModels)
{
string make = makeModel.Split(',')[0];
string model = makeModel.Split(',')[1];
List<string> years = vehicles
.Where(v => v.MakeName == make && v.ModelName == model)
.OrderBy(v => v.Year)
.Select(v => v.Year.HasValue ? v.Year.Value.ToString().Trim() : string.Empty)
.Distinct()
.ToList();
string tag = $"{string.Join('-', years)} {make.Trim()} {model.Trim()}";
Console.WriteLine(tag);
fitmentTags.Add(tag);
}
return fitmentTags;
}
public IList<int> GetVehicleIdFitment(IList<VehicleData> vehicles)
{
return vehicles.Select(v => v.VehicleToEngineConfigId).ToArray();
}
public IList<VehicleData> GetVehiclesForPart(string partNumber, string lineCode)
{
partNumber = Regex.Replace(partNumber, "[^a-zA-Z0-9]", string.Empty);
IQueryable<string> whiCodes = _partSourceContext.DcfMappings
.Where(d => d.LineCode == lineCode)
.Select(d => d.WhiCode);
IQueryable<VehicleData> vehicles = _partSourceContext.Fitments
.Where(f => f.PartNumber == partNumber && whiCodes.Contains(f.LineCode))
.Join(_partSourceContext.VehicleData,
f => new { f.BaseVehicleId, f.EngineConfigId },
v => new { v.BaseVehicleId, v.EngineConfigId },
(f, v) => v);
return vehicles.ToList();
}
}
}

View File

@@ -0,0 +1,22 @@
{
"ConnectionStrings": {
//"PartSourceDatabase": "Server=(localdb)\\mssqllocaldb;Database=PartSource;Trusted_Connection=True;"
"PartSourceDatabase": "Server=tcp:ps-whi.database.windows.net,1433;Initial Catalog=ps-whi-stage;Persist Security Info=False;User ID=ps-whi;Password=9-^*N5dw!6:|.5Q;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
},
"emailConfiguration": {
"From": "alerts@ps-shopify.canadaeast.cloudapp.azure.com",
// "To": "tom@soundpress.com,Anas.Bajwa@Partsource.ca",
"To": "tommy@localhost",
"SmtpHost": "localhost"
},
"ftpConfiguration": {
"Username": "ps-ftp\\$ps-ftp",
"Password": "ycvXptffBxqkBXW4vuRYqn4Zi1soCvnvMMolTe5HNSeAlcl3bAyJYtNhG579",
"Url": "ftp://waws-prod-yq1-007.ftp.azurewebsites.windows.net/site/wwwroot",
"Destination": "C:\\Users\\soundpress\\Desktop"
},
"ssisConfiguration": {
"Directory": "c:\\users\\soundpress\\desktop"
}
}