mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-21 15:27:15 +00:00
Feature repricing min max (#10)
amazon settlement import/export improvements
This commit is contained in:
77
src/bnhtrade.Core/Logic/Validate/AccountCode.cs
Normal file
77
src/bnhtrade.Core/Logic/Validate/AccountCode.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bnhtrade.Core.Logic.Validate
|
||||
{
|
||||
public class AccountCode : Validate
|
||||
{
|
||||
private Logic.Utilities.StringCheck stringCheck = new Logic.Utilities.StringCheck();
|
||||
|
||||
public new void Innit()
|
||||
{
|
||||
base.Innit();
|
||||
stringCheck = new Logic.Utilities.StringCheck();
|
||||
}
|
||||
public bool IsValidAccountCodeId(int accountCode)
|
||||
{
|
||||
if (accountCode >=0)
|
||||
{ return true; }
|
||||
else
|
||||
{
|
||||
ValidationResultAdd("Invalid account code.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public bool IsValidTitle(string title)
|
||||
{
|
||||
if (stringCheck.MaxLength(title, 150))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ValidationResultAdd(stringCheck.ValidationResult);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public bool IsValidDescription(string description)
|
||||
{
|
||||
if (stringCheck.MaxLength(description, 500))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ValidationResultAdd(stringCheck.ValidationResult);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public bool IsValidType(string type)
|
||||
{
|
||||
if (stringCheck.MaxLength(type, 50))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ValidationResultAdd(stringCheck.ValidationResult);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public bool IsValidBasicType(string basicType)
|
||||
{
|
||||
if (stringCheck.MaxLength(basicType, 50))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ValidationResultAdd(stringCheck.ValidationResult);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
21
src/bnhtrade.Core/Logic/Validate/AmazonIventoryLoaderFile.cs
Normal file
21
src/bnhtrade.Core/Logic/Validate/AmazonIventoryLoaderFile.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bnhtrade.Core.Logic.Validate
|
||||
{
|
||||
public class AmazonIventoryLoaderFile : Validate
|
||||
{
|
||||
public bool IsValidFbaPricing(IEnumerable<Model.Export.AmazonIventoryLoaderFile> exportList)
|
||||
{
|
||||
if (!IsValid(exportList))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return IsValidResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
497
src/bnhtrade.Core/Logic/Validate/AmazonSettlement.cs
Normal file
497
src/bnhtrade.Core/Logic/Validate/AmazonSettlement.cs
Normal file
@@ -0,0 +1,497 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bnhtrade.Core.Logic.Validate
|
||||
{
|
||||
public class AmazonSettlement : Validate
|
||||
{
|
||||
protected Utilities.StringCheck stringCheck = new Utilities.StringCheck();
|
||||
protected Utilities.DateTimeCheck timeCheck = new Utilities.DateTimeCheck();
|
||||
protected Logic.Validate.CurrencyCode currencyCheck = new Logic.Validate.CurrencyCode();
|
||||
protected Utilities.DecimalCheck decimalCheck = new Utilities.DecimalCheck();
|
||||
|
||||
public AmazonSettlement() : base()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public bool ValidateMarketPlaceName { get; set; } = true;
|
||||
|
||||
public new void Innit()
|
||||
{
|
||||
base.Innit();
|
||||
timeCheck.Innit();
|
||||
stringCheck.Innit();
|
||||
currencyCheck.Innit();
|
||||
decimalCheck.Innit();
|
||||
}
|
||||
|
||||
public bool IsValid(Model.Import.AmazonSettlement settlement)
|
||||
{
|
||||
return IsValid(new List<Model.Import.AmazonSettlement> { settlement });
|
||||
}
|
||||
|
||||
public bool IsValid(List<Model.Import.AmazonSettlement> settlementList)
|
||||
{
|
||||
Innit();
|
||||
|
||||
for (int i = 0; i < settlementList.Count; i++)
|
||||
{
|
||||
if (!settlementList[i].CurrencyCodeIsSet) { ValidationResultAdd("CurrencyCode is a required value."); }
|
||||
else { IsValidCurrencyCode(settlementList[i].CurrencyCode); }
|
||||
|
||||
if (!settlementList[i].DepositDateIsSet) { ValidationResultAdd("DepositDate is a required value."); }
|
||||
else { IsValidDepositDate(settlementList[i].DepositDate); }
|
||||
|
||||
if (!settlementList[i].EndDateIsSet) { ValidationResultAdd("EndDate is a required value."); }
|
||||
else { IsValidEndDate(settlementList[i].EndDate); }
|
||||
|
||||
if (!settlementList[i].IsProcessedIsSet) { ValidationResultAdd("IsProcessed is a required value."); }
|
||||
else { IsValidIsProcessed(settlementList[i].IsProcessed); }
|
||||
|
||||
if (!settlementList[i].MarketPlaceNameIsSet)
|
||||
{
|
||||
if (ValidateMarketPlaceName) { ValidationResultAdd("MarketPlaceName is a required value."); }
|
||||
}
|
||||
else { IsValidMarketPlaceName(settlementList[i].MarketPlaceName); }
|
||||
|
||||
if (!settlementList[i].SettlementIdIsSet) { ValidationResultAdd("SettlementId is a required value."); }
|
||||
else { IsValidSettlementId(settlementList[i].SettlementId); }
|
||||
|
||||
if (!settlementList[i].StartDateIsSet) { ValidationResultAdd("StartDate is a required value."); }
|
||||
else { IsValidStartDate(settlementList[i].StartDate); }
|
||||
|
||||
if (!settlementList[i].TotalAmountIsSet) { ValidationResultAdd("TotalAmount is a required value."); }
|
||||
else { IsValidTotalAmount(settlementList[i].TotalAmount); }
|
||||
|
||||
|
||||
// check line list
|
||||
if (!settlementList[i].SettlementLineListIsSet)
|
||||
{
|
||||
ValidationResultAdd("Settlement line list is null or empty");
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// loop though lines and check
|
||||
decimal lineSum = 0;
|
||||
for (int j = 0; j < settlementList[i].SettlementLineList.Count(); j++)
|
||||
{
|
||||
IsValid(settlementList[i].SettlementLineList[j]);
|
||||
if (settlementList[i].SettlementLineList[j].AmountIsSet)
|
||||
{ lineSum += settlementList[i].SettlementLineList[j].Amount; }
|
||||
}
|
||||
|
||||
// check totals
|
||||
if (lineSum != settlementList[i].TotalAmount)
|
||||
{
|
||||
ValidationResultAdd("Settlement header total (" + settlementList[i].TotalAmount +
|
||||
") does not match line total (" + lineSum + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return IsValidResult;
|
||||
}
|
||||
|
||||
public bool IsValid(Model.Import.AmazonSettlement.SettlementLine settlementLine)
|
||||
{
|
||||
if (settlementLine.AdjustmentIdIsSet)
|
||||
{
|
||||
if (!IsValidAdjustmentId(settlementLine.AdjustmentId)) { }
|
||||
}
|
||||
|
||||
if (settlementLine.AmountIsSet)
|
||||
{
|
||||
if (!IsValidAmount(settlementLine.Amount)) { }
|
||||
}
|
||||
else
|
||||
{
|
||||
ValidationResultAdd("Amount is a required value.");
|
||||
}
|
||||
|
||||
|
||||
if (settlementLine.AmountDescriptionIsSet)
|
||||
{
|
||||
if (!IsValidAmountDescription(settlementLine.AmountDescription)) { }
|
||||
}
|
||||
else
|
||||
{
|
||||
ValidationResultAdd("Amount Description is a required value.");
|
||||
}
|
||||
|
||||
|
||||
if (settlementLine.AmountTypeIsSet)
|
||||
{
|
||||
if (!IsValidAmountType(settlementLine.AmountType)) { }
|
||||
}
|
||||
else
|
||||
{
|
||||
ValidationResultAdd("Amount Type is a required value.");
|
||||
}
|
||||
|
||||
|
||||
if (settlementLine.CurrenyCodeIsSet)
|
||||
{
|
||||
if (!IsValidCurrenyCode(settlementLine.CurrenyCode)) { }
|
||||
}
|
||||
else
|
||||
{
|
||||
ValidationResultAdd("Currency Code is a required value.");
|
||||
}
|
||||
|
||||
|
||||
if (settlementLine.ExportAccountInvoiceLineIdIsSet)
|
||||
{
|
||||
if (!IsValidExportAccountInvoiceLineId(settlementLine.ExportAccountInvoiceLineId)) { }
|
||||
}
|
||||
|
||||
if (settlementLine.FulfillmentIdIsSet)
|
||||
{
|
||||
if (!IsValidFulfillmentId(settlementLine.FulfillmentId)) { }
|
||||
}
|
||||
|
||||
if (settlementLine.IsProcessedIsSet)
|
||||
{
|
||||
if (!IsValidIsProcessed(settlementLine.IsProcessed)) { }
|
||||
}
|
||||
else
|
||||
{
|
||||
ValidationResultAdd("Is Processed is a required value.");
|
||||
}
|
||||
|
||||
|
||||
if (settlementLine.MarketPlaceNameIsSet)
|
||||
{
|
||||
if (!IsValidMarketPlaceName(settlementLine.MarketPlaceName)) { }
|
||||
}
|
||||
|
||||
if (settlementLine.MerchantAdjustmentItemIdIsSet)
|
||||
{
|
||||
if (!IsValidMerchantAdjustmentItemId(settlementLine.MerchantAdjustmentItemId)) { }
|
||||
}
|
||||
|
||||
if (settlementLine.MerchantOrderIdIsSet)
|
||||
{
|
||||
if (!IsValidMerchantOrderId(settlementLine.MerchantOrderId)) { }
|
||||
}
|
||||
|
||||
if (settlementLine.MerchantOrderItemIdIsSet)
|
||||
{
|
||||
if (!IsValidMerchantOrderItemId(settlementLine.MerchantOrderItemId)) { }
|
||||
}
|
||||
|
||||
if (settlementLine.OrderIdIsSet)
|
||||
{
|
||||
if (!IsValidOrderId(settlementLine.OrderId)) { }
|
||||
}
|
||||
|
||||
if (settlementLine.OrderItemCodeIsSet)
|
||||
{
|
||||
if (!IsValidOrderItemCode(settlementLine.OrderItemCode)) { }
|
||||
}
|
||||
|
||||
if (settlementLine.PostDateTimeIsSet)
|
||||
{
|
||||
if (!IsValidPostDateTime(settlementLine.PostDateTime)) { }
|
||||
}
|
||||
else
|
||||
{
|
||||
ValidationResultAdd("Posted DateTime is a required value.");
|
||||
}
|
||||
|
||||
if (settlementLine.PromotionIdIsSet)
|
||||
{
|
||||
if (!IsValidPromotionId(settlementLine.PromotionId)) { }
|
||||
}
|
||||
|
||||
if (settlementLine.QuantityPurchasedIsSet)
|
||||
{
|
||||
if (!IsValidQuantityPurchased(settlementLine.QuantityPurchased)) { }
|
||||
}
|
||||
|
||||
if (settlementLine.ShipmentIdIsSet)
|
||||
{
|
||||
if (!IsValidShipmentId(settlementLine.ShipmentId)) { }
|
||||
}
|
||||
|
||||
if (settlementLine.SkuIsSet)
|
||||
{
|
||||
if (!IsValidSku(settlementLine.Sku)) { }
|
||||
}
|
||||
|
||||
if (settlementLine.TransactionTypeIsSet)
|
||||
{
|
||||
if (!IsValidTransactionType(settlementLine.TransactionType)) { }
|
||||
}
|
||||
else
|
||||
{
|
||||
ValidationResultAdd("Transaction Type is a required value.");
|
||||
}
|
||||
|
||||
return IsValidResult;
|
||||
}
|
||||
|
||||
public bool IsValidSettlementId(string settlementId)
|
||||
{
|
||||
if (!stringCheck.IsNumeric(settlementId))
|
||||
{
|
||||
ValidationResultAdd(stringCheck.ValidationResult.Select(x => "Invalid settlement Id: " + x).ToList());
|
||||
return false;
|
||||
}
|
||||
if (!stringCheck.MaxLength(settlementId, 50))
|
||||
{
|
||||
ValidationResultAdd(stringCheck.ValidationResult.Select(x => "Invalid settlement Id: " + x).ToList());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool IsValidIsProcessed(bool isProcessed)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool IsValidMarketPlaceName(string marketPlaceName)
|
||||
{
|
||||
if (!stringCheck.MaxLength(marketPlaceName, 50, true))
|
||||
{
|
||||
ValidationResultAdd("Invalid market place name.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool IsValidStartDate(DateTime startDate)
|
||||
{
|
||||
if (!timeCheck.IsUtc(startDate))
|
||||
{
|
||||
ValidationResultAdd(timeCheck.ValidationResult.Select(x => "Invalid StartDate: " + x).ToList());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool IsValidEndDate(DateTime endDate)
|
||||
{
|
||||
if (!timeCheck.IsUtc(endDate))
|
||||
{
|
||||
ValidationResultAdd(timeCheck.ValidationResult.Select(x => "Invalid EndDate: " + x).ToList());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool IsValidDepositDate(DateTime depositDate)
|
||||
{
|
||||
if (!timeCheck.IsUtc(depositDate))
|
||||
{
|
||||
ValidationResultAdd(timeCheck.ValidationResult.Select(x => "Invalid DepositDate: " + x).ToList());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool IsValidTotalAmount(decimal totalAmount)
|
||||
{
|
||||
if (!decimalCheck.SqlLength92(totalAmount))
|
||||
{
|
||||
ValidationResultAdd(decimalCheck.ValidationResult.Select(x => "Total Amount Invalid: " + x).ToList());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool IsValidCurrencyCode(string currencyCode)
|
||||
{
|
||||
if (!currencyCheck.IsValidCurrencyCode(currencyCode))
|
||||
{
|
||||
ValidationResultAdd(currencyCheck.ValidationResult.Select(x => "Total Amount CurrencyCode: " + x).ToList());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public bool IsValidTransactionType(string transactionType)
|
||||
{
|
||||
if (!stringCheck.MaxLength(transactionType, 50))
|
||||
{
|
||||
ValidationResultAdd(stringCheck.ValidationResult.Select(x => "Invalid transaction type: " + x).ToList());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool IsValidOrderId(string orderId)
|
||||
{
|
||||
if (!stringCheck.MaxLength(orderId, 50, true))
|
||||
{
|
||||
ValidationResultAdd(stringCheck.ValidationResult.Select(x => "Invalid order id: " + x).ToList());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool IsValidMerchantOrderId(string merchantOrderId)
|
||||
{
|
||||
if (!stringCheck.MaxLength(merchantOrderId, 50, true))
|
||||
{
|
||||
ValidationResultAdd(stringCheck.ValidationResult.Select(x => "Invalid merchant order id: " + x).ToList());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool IsValidAdjustmentId(string adjustmentId)
|
||||
{
|
||||
if (!stringCheck.MaxLength(adjustmentId, 50, true))
|
||||
{
|
||||
ValidationResultAdd(stringCheck.ValidationResult.Select(x => "Invalid adjustment id: " + x).ToList());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool IsValidShipmentId(string shipmentId)
|
||||
{
|
||||
if (!stringCheck.MaxLength(shipmentId, 50, true))
|
||||
{
|
||||
ValidationResultAdd(stringCheck.ValidationResult.Select(x => "Invalid shipment id: " + x).ToList());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool IsValidAmountType(string amountType)
|
||||
{
|
||||
if (!stringCheck.MaxLength(amountType, 50))
|
||||
{
|
||||
ValidationResultAdd(stringCheck.ValidationResult.Select(x => "Invalid amount type: " + x).ToList());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool IsValidAmountDescription(string amountDescription)
|
||||
{
|
||||
if (!stringCheck.MaxLength(amountDescription, 100))
|
||||
{
|
||||
ValidationResultAdd(stringCheck.ValidationResult.Select(x => "Invalid amount description: " + x).ToList());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool IsValidAmount(decimal amount)
|
||||
{
|
||||
if (!decimalCheck.SqlLength92(amount))
|
||||
{
|
||||
ValidationResultAdd(decimalCheck.ValidationResult.Select(x => "Invalid amount: " + x).ToList());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool IsValidCurrenyCode(string currenyCode)
|
||||
{
|
||||
if (!currencyCheck.IsValidCurrencyCode(currenyCode))
|
||||
{
|
||||
ValidationResultAdd(currencyCheck.ValidationResult.Select(x => "Invalid curreny code: " + x).ToList());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool IsValidFulfillmentId(string fulfillmentId)
|
||||
{
|
||||
if (!stringCheck.MaxLength(fulfillmentId, 50, true))
|
||||
{
|
||||
ValidationResultAdd(stringCheck.ValidationResult.Select(x => "Invalid fulfillment Id: " + x).ToList());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool IsValidPostDateTime(DateTime postDateTime)
|
||||
{
|
||||
var timeCheck = new Logic.Utilities.DateTimeCheck();
|
||||
if (!timeCheck.IsUtc(postDateTime))
|
||||
{
|
||||
ValidationResultAdd(@"Invalid post date/time, not set to UTC kind.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool IsValidOrderItemCode(string orderItemCode)
|
||||
{
|
||||
if (!stringCheck.MaxLength(orderItemCode, 50, true))
|
||||
{
|
||||
ValidationResultAdd(stringCheck.ValidationResult.Select(x => "Invalid order item code: " + x).ToList());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool IsValidMerchantOrderItemId(string merchantOrderItemId)
|
||||
{
|
||||
if (!stringCheck.MaxLength(merchantOrderItemId, 50, true))
|
||||
{
|
||||
ValidationResultAdd(stringCheck.ValidationResult.Select(x => "Invalid merchant order item id: " + x).ToList());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool IsValidMerchantAdjustmentItemId(string merchantAdjustmentItemId)
|
||||
{
|
||||
if (!stringCheck.MaxLength(merchantAdjustmentItemId, 50, true))
|
||||
{
|
||||
ValidationResultAdd(stringCheck.ValidationResult.Select(x => "Invalid merchant adjustment item id: " + x).ToList());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool IsValidSku(string skuNumber)
|
||||
{
|
||||
if (!stringCheck.MaxLength(skuNumber, 50, true))
|
||||
{
|
||||
ValidationResultAdd(stringCheck.ValidationResult.Select(x => "Invalid sku number: " + x).ToList());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool IsValidQuantityPurchased(int quantityPurchased)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public bool IsValidPromotionId(string promotionId)
|
||||
{
|
||||
if (!stringCheck.MaxLength(promotionId, 50, true))
|
||||
{
|
||||
ValidationResultAdd(stringCheck.ValidationResult.Select(x => "Invalid promotion id: " + x).ToList());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool IsValidExportAccountInvoiceLineId(int exportAccountInvoiceLineId)
|
||||
{
|
||||
if (exportAccountInvoiceLineId > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ValidationResultAdd("Export account invoice line id cannot be less than 1");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
31
src/bnhtrade.Core/Logic/Validate/CurrencyCode.cs
Normal file
31
src/bnhtrade.Core/Logic/Validate/CurrencyCode.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bnhtrade.Core.Logic.Validate
|
||||
{
|
||||
public class CurrencyCode : Validate
|
||||
{
|
||||
private Logic.Utilities.StringCheck stringCheck = new Logic.Utilities.StringCheck();
|
||||
public new void Innit()
|
||||
{
|
||||
base.Innit();
|
||||
stringCheck = new Logic.Utilities.StringCheck();
|
||||
}
|
||||
public bool IsValidCurrencyCode(string currencyCode)
|
||||
{
|
||||
if (stringCheck.Length(currencyCode, 3) && stringCheck.IsAlpha(currencyCode, true))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ValidationResultAdd(stringCheck.ValidationResult);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
43
src/bnhtrade.Core/Logic/Validate/SalesInvoice.cs
Normal file
43
src/bnhtrade.Core/Logic/Validate/SalesInvoice.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bnhtrade.Core.Logic.Validate
|
||||
{
|
||||
public class SalesInvoice : Logic.Validate.Validate
|
||||
{
|
||||
public SalesInvoice()
|
||||
{
|
||||
}
|
||||
|
||||
public bool IsValidExportInvoice(IEnumerable<Model.Account.Invoice> invoiceList)
|
||||
{
|
||||
if (!IsValid(invoiceList))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var invoice in invoiceList)
|
||||
{
|
||||
if (invoice.UnitAmountIsTaxExclusive == false)
|
||||
{
|
||||
ValidationResultAdd("Tax inclusive line unit amounts are not supported");
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var invoiceLine in invoice.InvoiceLineList)
|
||||
{
|
||||
if (invoiceLine.Quantity != 1)
|
||||
{
|
||||
ValidationResultAdd("Quantities greater than 1 are not supported");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return IsValidResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
29
src/bnhtrade.Core/Logic/Validate/SkuPriceInfo.cs
Normal file
29
src/bnhtrade.Core/Logic/Validate/SkuPriceInfo.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bnhtrade.Core.Logic.Validate
|
||||
{
|
||||
public class SkuPriceInfo : Validate
|
||||
{
|
||||
public SkuPriceInfo()
|
||||
{
|
||||
Innit();
|
||||
}
|
||||
|
||||
public bool IsValidDatabaseCreate(List<Model.Sku.Price.PriceInfo> priceInfoList)
|
||||
{
|
||||
Innit();
|
||||
|
||||
if (!IsValid(priceInfoList))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return IsValidResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
44
src/bnhtrade.Core/Logic/Validate/SkuTransaction.cs
Normal file
44
src/bnhtrade.Core/Logic/Validate/SkuTransaction.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bnhtrade.Core.Logic.Validate
|
||||
{
|
||||
public class SkuTransaction : Validate
|
||||
{
|
||||
public bool DatabaseUpdate(Model.Stock.SkuTransaction skuTransaction)
|
||||
{
|
||||
return IsValid(new List<Model.Stock.SkuTransaction> { skuTransaction });
|
||||
}
|
||||
|
||||
public bool DatabaseUpdate(List<Model.Stock.SkuTransaction> skuTransactionList)
|
||||
{
|
||||
if (!IsValid(skuTransactionList))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < skuTransactionList.Count; i++)
|
||||
{
|
||||
if (!skuTransactionList[i].IsSetSkuTransactionId)
|
||||
{
|
||||
ValidationResultAdd("StockTransactionId is required");
|
||||
}
|
||||
}
|
||||
|
||||
return IsValidResult;
|
||||
}
|
||||
|
||||
public bool DatabaseInsert(Model.Stock.SkuTransaction skuTransaction)
|
||||
{
|
||||
return IsValid(new List<Model.Stock.SkuTransaction> { skuTransaction });
|
||||
}
|
||||
|
||||
public bool DatabaseInsert(List<Model.Stock.SkuTransaction> skuTransactionList)
|
||||
{
|
||||
return IsValid(skuTransactionList);
|
||||
}
|
||||
}
|
||||
}
|
||||
17
src/bnhtrade.Core/Logic/Validate/TaxCodeInfo.cs
Normal file
17
src/bnhtrade.Core/Logic/Validate/TaxCodeInfo.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bnhtrade.Core.Logic.Validate
|
||||
{
|
||||
public class TaxCodeInfo : Validate
|
||||
{
|
||||
public bool IsValidPresistanceGet(Model.Account.TaxCodeInfo taxCodeInfo)
|
||||
{
|
||||
return IsValid(taxCodeInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
94
src/bnhtrade.Core/Logic/Validate/Validate.cs
Normal file
94
src/bnhtrade.Core/Logic/Validate/Validate.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace bnhtrade.Core.Logic.Validate
|
||||
{
|
||||
public abstract class Validate
|
||||
{
|
||||
public List<ValidationResult> ValidationResult { get; set; } = new List<ValidationResult>();
|
||||
|
||||
public bool IsValidResult
|
||||
{
|
||||
get
|
||||
{
|
||||
if (ValidationResult.Any()) { return false; }
|
||||
else { return true; }
|
||||
}
|
||||
}
|
||||
|
||||
public void Innit()
|
||||
{
|
||||
ValidationResult = new List<ValidationResult>();
|
||||
}
|
||||
|
||||
protected bool IsValid(IValidatableObject validatableObject)
|
||||
{
|
||||
if (validatableObject == null)
|
||||
{
|
||||
ValidationResult.Add(new ValidationResult("Validatable object is null"));
|
||||
return false;
|
||||
}
|
||||
|
||||
var validationContext = new ValidationContext(validatableObject);
|
||||
ValidationResult.AddRange(validatableObject.Validate(validationContext));
|
||||
return IsValidResult;
|
||||
}
|
||||
|
||||
protected bool IsValid(IEnumerable<IValidatableObject> validatableObjectList)
|
||||
{
|
||||
if (validatableObjectList == null || !validatableObjectList.Any())
|
||||
{
|
||||
ValidationResult.Add(new ValidationResult("Validatable object list is empty or null"));
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var validatableObject in validatableObjectList)
|
||||
{
|
||||
if (!IsValid(validatableObject)) { return false; }
|
||||
}
|
||||
|
||||
return IsValidResult;
|
||||
}
|
||||
|
||||
protected void ValidationResultAdd(string result)
|
||||
{
|
||||
ValidationResult.Add(new ValidationResult(result));
|
||||
}
|
||||
|
||||
protected void ValidationResultAdd(List<string> result)
|
||||
{
|
||||
foreach (var item in result)
|
||||
{
|
||||
ValidationResultAdd(item);
|
||||
}
|
||||
}
|
||||
|
||||
protected void ValidationResultAdd(ValidationResult result)
|
||||
{
|
||||
ValidationResult.Add(result);
|
||||
}
|
||||
|
||||
protected void ValidationResultAdd(List<ValidationResult> result)
|
||||
{
|
||||
ValidationResult.AddRange(result);
|
||||
}
|
||||
|
||||
public string ValidationResultListToString()
|
||||
{
|
||||
if (IsValidResult == false)
|
||||
{
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (int i = 0; i < ValidationResult.Count; i++)
|
||||
{
|
||||
result.AppendLine(ValidationResult[i].ErrorMessage);
|
||||
}
|
||||
return result.ToString();
|
||||
}
|
||||
else { return null; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user