ZUGFeRDRESTService: formal validation with PRCUST_INV_CHECK_FROM_PORTAL
This commit is contained in:
parent
30e0d55600
commit
80f858bdf5
@ -10,6 +10,7 @@ using static DigitalData.Modules.Interfaces.ZUGFeRDInterface;
|
|||||||
using static DigitalData.Modules.Interfaces.PropertyValues;
|
using static DigitalData.Modules.Interfaces.PropertyValues;
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
using DigitalData.Modules.Database;
|
using DigitalData.Modules.Database;
|
||||||
|
using Microsoft.CodeAnalysis.Operations;
|
||||||
|
|
||||||
namespace ZUGFeRDRESTService.Controllers
|
namespace ZUGFeRDRESTService.Controllers
|
||||||
{
|
{
|
||||||
@ -20,6 +21,9 @@ namespace ZUGFeRDRESTService.Controllers
|
|||||||
public const string RESPONSE_OK = "OK";
|
public const string RESPONSE_OK = "OK";
|
||||||
public const string RESPONSE_ERROR = "ERROR";
|
public const string RESPONSE_ERROR = "ERROR";
|
||||||
|
|
||||||
|
public const string ADDED_WHO = "ZUGFeRD REST Service";
|
||||||
|
public const string MESSAGEID_DOMAIN = "test.wisag.de";
|
||||||
|
|
||||||
private readonly ZUGFeRDInterface _zugferd;
|
private readonly ZUGFeRDInterface _zugferd;
|
||||||
private readonly IDatabase _database;
|
private readonly IDatabase _database;
|
||||||
|
|
||||||
@ -89,6 +93,9 @@ namespace ZUGFeRDRESTService.Controllers
|
|||||||
"Die hochgeladene Datei ist eine gültige ZUGFeRD-Rechnung, allerdings fehlen benötigte Daten.");
|
"Die hochgeladene Datei ist eine gültige ZUGFeRD-Rechnung, allerdings fehlen benötigte Daten.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Tuple<bool, string> oValidateResult = ValidateBuyerOrderReference(oResult.ValidProperties);
|
||||||
|
|
||||||
|
|
||||||
string oMessage = "Die hochgeladene Datei ist eine gültige-ZUGFeRD Rechnung";
|
string oMessage = "Die hochgeladene Datei ist eine gültige-ZUGFeRD Rechnung";
|
||||||
|
|
||||||
_logger.Debug($"Replying with: [{oMessage}]");
|
_logger.Debug($"Replying with: [{oMessage}]");
|
||||||
@ -147,12 +154,14 @@ namespace ZUGFeRDRESTService.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Tuple<bool, string> ValidateBuyerOrderReference(Dictionary<string, XmlItemProperty> pPropertyMap, List<ValidProperty> pProperties)
|
private Tuple<bool, string> ValidateBuyerOrderReference(List<ValidProperty> pProperties)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
var oMessageId = GetMessageId();
|
||||||
|
|
||||||
foreach (var oItem in pProperties)
|
foreach (var oItem in pProperties)
|
||||||
{
|
{
|
||||||
var oResult = InsertPropertyMap(oItem);
|
var oResult = InsertPropertyMap(oItem, oMessageId);
|
||||||
|
|
||||||
if (oResult == false)
|
if (oResult == false)
|
||||||
{
|
{
|
||||||
@ -160,40 +169,60 @@ namespace ZUGFeRDRESTService.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Execute the Procedure.
|
|
||||||
// _database.MSSQL.ExecuteNonQuery("");
|
|
||||||
|
|
||||||
// TODO: Return a Status value which will be returned to the caller.
|
|
||||||
return new Tuple<bool, string>(true, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool InsertPropertyMap(ValidProperty pProperty)
|
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var oCreator = "ZUGFeRD REST Service";
|
using SqlCommand oCommand = new SqlCommand("PRCUST_INV_CHECK_FROM_PORTAL @MESSAGE_ID, @MSG_OUTPUT");
|
||||||
var oDomain = "test.wisag.de";
|
oCommand.CommandType = System.Data.CommandType.StoredProcedure;
|
||||||
var oMessageId = $"{Guid.NewGuid()}@{oDomain}";
|
oCommand.Parameters.Add("MESSAGE_ID", System.Data.SqlDbType.VarChar).Value = oMessageId;
|
||||||
|
oCommand.Parameters.Add("MSG_OUTPUT", System.Data.SqlDbType.VarChar).Direction = System.Data.ParameterDirection.Output;
|
||||||
|
|
||||||
|
if (_database.MSSQL.ExecuteNonQuery(oCommand))
|
||||||
|
{
|
||||||
|
string oReturnValue = (string)oCommand.Parameters["MSG_OUTPUT"].Value;
|
||||||
|
|
||||||
|
return new Tuple<bool, string>(true, oReturnValue);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new Tuple<bool, string>(false, string.Empty);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.Error(e);
|
||||||
|
return new Tuple<bool, string>(false, string.Empty);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetMessageId()
|
||||||
|
{
|
||||||
|
return $"{Guid.NewGuid()}@{MESSAGEID_DOMAIN}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool InsertPropertyMap(ValidProperty pProperty, string pMessageId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
var oSql = $"INSERT INTO {pProperty.TableName} " +
|
var oSql = $"INSERT INTO {pProperty.TableName} " +
|
||||||
"(REFERENCE_GUID, ITEM_DESCRIPTION, ITEM_VALUE, CREATEDWHO, SPEC_NAME, GROUP_COUNTER, IS_REQUIRED) VALUES " +
|
"(REFERENCE_GUID, ITEM_DESCRIPTION, ITEM_VALUE, CREATEDWHO, SPEC_NAME, GROUP_COUNTER, IS_REQUIRED) VALUES " +
|
||||||
"(@REFERENCE_GUID, @ITEM_DESCRIPTION, @ITEM_VALUE, @CREATEDWHO, @SPEC_NAME, @GROUP_COUNTER, @IS_REQUIRED)";
|
"(@REFERENCE_GUID, @ITEM_DESCRIPTION, @ITEM_VALUE, @CREATEDWHO, @SPEC_NAME, @GROUP_COUNTER, @IS_REQUIRED)";
|
||||||
|
|
||||||
var oParams = new SqlParameter[]
|
var oParams = new SqlParameter[]
|
||||||
{
|
{
|
||||||
new SqlParameter("@REFERENCE_GUID", oMessageId),
|
new SqlParameter("@REFERENCE_GUID", pMessageId),
|
||||||
new SqlParameter("@ITEM_DESCRIPTION", pProperty.Description),
|
new SqlParameter("@ITEM_DESCRIPTION", pProperty.Description),
|
||||||
new SqlParameter("@ITEM_VALUE", pProperty.Value),
|
new SqlParameter("@ITEM_VALUE", pProperty.Value),
|
||||||
new SqlParameter("@CREATEDWHO", oCreator),
|
new SqlParameter("@CREATEDWHO", ADDED_WHO),
|
||||||
new SqlParameter("@GROUP_COUNTER", pProperty.GroupCounter),
|
new SqlParameter("@GROUP_COUNTER", pProperty.GroupCounter),
|
||||||
new SqlParameter("@SPEC_NAME", pProperty.TableColumn),
|
new SqlParameter("@SPEC_NAME", pProperty.TableColumn),
|
||||||
new SqlParameter("@IS_REQUIRED", pProperty.ISRequired)
|
new SqlParameter("@IS_REQUIRED", pProperty.ISRequired)
|
||||||
};
|
};
|
||||||
|
|
||||||
var oCommand = new SqlCommand(oSql);
|
var oCommand = new SqlCommand(oSql);
|
||||||
oCommand.Parameters.AddRange(oParams);
|
oCommand.Parameters.AddRange(oParams);
|
||||||
|
|
||||||
|
|
||||||
return _database.MSSQL.ExecuteNonQuery(oCommand);
|
return _database.MSSQL.ExecuteNonQuery(oCommand);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user