Feature: Sync MWS Shipment with Database

Various restructuring and misc. features added.
Removed reliance on ABrain Amazon MWS NuGet package, added Amazon's own C# lib
This commit is contained in:
Bobbie Hodgetts
2019-06-24 16:01:50 +01:00
committed by GitHub
parent bc44546efd
commit 116aedb897
27 changed files with 2236 additions and 289 deletions

View File

@@ -0,0 +1,179 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Model.AmazonFBAInbound
{
public class ShipmentInfo
{
private string destinationFulfillmentCenterId;
private List<ShipmentItemInfo> shipmentItemInfoList;
private string shipmentStatus;
private DateTime lastUpdatedUtc;
private Dictionary<string, bool> shipmentStatusToIsClosed;
public string AmazonShipmentId { get; set; }
public string ShipmentName { get; set; }
public string DestinationFulfillmentCenterId
{
get { return destinationFulfillmentCenterId; }
set
{
if (value.Length != 4)
{
throw new Exception("incorrect Fulfillment Center Id");
}
else
{
destinationFulfillmentCenterId = value;
}
}
}
public string ShipmentStatus
{
get
{
return shipmentStatus;
}
set
{
string status = value.ToUpper();
if (!shipmentStatusToIsClosed.ContainsKey(status))
{
throw new Exception("Invalid shipment status '" + status + "' parameter set as per Amazon MWS definitions.");
}
shipmentStatus = status;
}
}
public DateTime LastUpdatedUtc
{
get
{
return lastUpdatedUtc;
}
set
{
lastUpdatedUtc = DateTime.SpecifyKind(value, DateTimeKind.Utc);
}
}
public bool ShipmentIsClosed
{
get
{
if (IsSetShipmentStatus())
{
return shipmentStatusToIsClosed[shipmentStatus];
}
else
{
return false;
}
}
}
public List<ShipmentItemInfo> ShipmentItemInfoList
{
get { return shipmentItemInfoList; }
set
{
var skuCheck = new Dictionary<string, string>();
var fnskuCheck = new Dictionary<string, string>();
foreach (var item in value)
{
if (!item.IsSetAll())
{ throw new Exception("Infomation missing from Shipment Item list"); }
if (item.AmazonShipmentId != AmazonShipmentId)
{ throw new Exception("Amazon shipment id in item list does not match header information."); }
if (skuCheck.ContainsKey(item.SKUNumber))
{ throw new Exception("Duplicated SKU number in item list."); }
skuCheck.Add(item.SKUNumber, "0000");
if (fnskuCheck.ContainsKey(item.AmazonFNSKU))
{ throw new Exception("Duplicated SKU number in item list."); }
fnskuCheck.Add(item.AmazonFNSKU, "0000");
if (item.QuantityAllocated < 0 || item.QuantityReceived < 0)
{ throw new Exception("Quantites cannot be less than zero."); }
if ((item.QuantityAllocated + item.QuantityReceived ) < 1)
{ throw new Exception("Quantites cannot be zero"); }
}
shipmentItemInfoList = value;
}
}
public bool IsSetAll()
{
if (IsSetAllHeaderInfo() && IsSetListShipmentItemInfo())
{
return true;
}
else
{
return false;
}
}
public bool IsSetAllHeaderInfo()
{
if (IsSetAmazonShipmentId()
&& IsSetShipmentName()
&& IsSetDestinationFulfillmentCenterId()
&& IsSetShipmentStatus()
&& IsSetLastUpdated()
&& IsSetShipmentIsClosed())
{
return true;
}
else
{
return false;
}
}
public bool IsSetAmazonShipmentId()
{
return AmazonShipmentId != null;
}
public bool IsSetShipmentName()
{
return ShipmentName != null;
}
public bool IsSetDestinationFulfillmentCenterId()
{
return DestinationFulfillmentCenterId != null;
}
public bool IsSetLastUpdated()
{
return LastUpdatedUtc != default(DateTime);
}
public bool IsSetListShipmentItemInfo()
{
return ShipmentItemInfoList != null;
}
public bool IsSetShipmentIsClosed()
{
return ShipmentStatus != null;
}
public bool IsSetShipmentStatus()
{
return ShipmentStatus != null;
}
public ShipmentInfo()
{
shipmentStatusToIsClosed = new Dictionary<string, bool>();
shipmentStatusToIsClosed.Add("WORKING", false);
shipmentStatusToIsClosed.Add("SHIPPED", false);
shipmentStatusToIsClosed.Add("IN_TRANSIT", false);
shipmentStatusToIsClosed.Add("DELIVERED", false);
shipmentStatusToIsClosed.Add("CHECKED_IN", false);
shipmentStatusToIsClosed.Add("RECEIVING", false);
shipmentStatusToIsClosed.Add("CLOSED", true);
shipmentStatusToIsClosed.Add("CANCELLED", true);
shipmentStatusToIsClosed.Add("DELETED", true);
shipmentStatusToIsClosed.Add("ERROR", false);
}
}
}

View File

@@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Model.AmazonFBAInbound
{
public class ShipmentItemInfo
{
private int quantityAllocated;
private int quantityReceived;
private bool isSetQuantityAllocated;
private bool isSetQuantityReceived;
/// <summary>
/// Gets and sets the AmazonShipmentId property.
/// </summary>
public string AmazonShipmentId { get; set; }
/// <summary>
/// Gets and sets the SKUNumber property.
/// </summary>
public string SKUNumber { get; set; }
/// <summary>
/// Gets and sets the FulfillmentNetworkSKU property.
/// </summary>
public string AmazonFNSKU { get; set; }
/// <summary>
/// Gets and sets the QuantityAllocated property.
/// </summary>
public int QuantityAllocated
{
get { return quantityAllocated; }
set { quantityAllocated = value; isSetQuantityAllocated = true; }
}
/// <summary>
/// Gets and sets the QuantityReceived property.
/// </summary>
public int QuantityReceived
{
get { return quantityReceived; }
set { quantityReceived = value; isSetQuantityReceived = true; }
}
public bool IsSetAll()
{
if (IsSetAmazonShipmentId()
&& IsSetSKUNumber()
&& IsSetFulfillmentNetworkSKU()
&& IsSetQuantityAllocated()
&& IsSetQuantityReceived()
)
{
return true;
}
else
{
return false;
}
}
public bool IsSetAmazonShipmentId()
{
return AmazonShipmentId != null;
}
public bool IsSetSKUNumber()
{
return SKUNumber != null;
}
public bool IsSetFulfillmentNetworkSKU()
{
return AmazonFNSKU != null;
}
public bool IsSetQuantityAllocated()
{
return isSetQuantityAllocated;
}
public bool IsSetQuantityReceived()
{
return isSetQuantityReceived;
}
}
}

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Model.SKU
{
class SKUInfo
{
public string SkuNumber { get; set; }
public string AmazonFNSKU { get; set; }
public bool IsActive { get; set; }
}
}