diff --git a/WEBSERVICES/ZUGFeRDRESTService/Controllers/ValidationController.cs b/WEBSERVICES/ZUGFeRDRESTService/Controllers/ValidationController.cs
index 7c03b15b..a362aa8d 100644
--- a/WEBSERVICES/ZUGFeRDRESTService/Controllers/ValidationController.cs
+++ b/WEBSERVICES/ZUGFeRDRESTService/Controllers/ValidationController.cs
@@ -9,8 +9,6 @@ using static DigitalData.Modules.Interfaces.Exceptions;
using static DigitalData.Modules.Interfaces.ZUGFeRDInterface;
using static DigitalData.Modules.Interfaces.PropertyValues;
using System.Data.SqlClient;
-using DigitalData.Modules.Database;
-using Microsoft.CodeAnalysis.Operations;
namespace ZUGFeRDRESTService.Controllers
{
@@ -55,11 +53,12 @@ namespace ZUGFeRDRESTService.Controllers
///
/// POST: /api/validation
///
- /// This parameter's name needs to correspond to the html form's file-input name
+ /// This parameter's name needs to correspond to the html form's file-input name
+ /// This is the email address which the user supplied
[HttpPost]
public ValidationResponse Post(IFormFile file, string user_id)
{
- _logger.Debug("Start processing request to ValidationController");
+ _logger.Info("Start processing request to ValidationController");
object oDocument;
PropertyValues.CheckPropertyValuesResult oResult = new PropertyValues.CheckPropertyValuesResult();
@@ -68,11 +67,11 @@ namespace ZUGFeRDRESTService.Controllers
{
using Stream oStream = file.OpenReadStream();
{
- _logger.Debug("Extracting ZUGFeRD Data from file [{0}]", file.FileName);
+ _logger.Info("Extracting ZUGFeRD Data from file [{0}]", file.FileName);
oDocument = _zugferd.ExtractZUGFeRDFileWithGDPicture(oStream);
- _logger.Debug("Checking ZUGFeRD Data against the database");
+ _logger.Info("Starting structural check against the database.");
oResult = _props.CheckPropertyValues(oDocument, _propertyMap, "MESSAGEID");
@@ -84,7 +83,7 @@ namespace ZUGFeRDRESTService.Controllers
_logger.Debug("Found [{0}] required properties", oRequiredProperties.Count);
_logger.Debug(string.Join(",", oRequiredProperties.ToArray()));
- _logger.Debug("Result of checking against the database: {0} valid properties, {1} missing properties",
+ _logger.Info("Result of checking against the database: {0} valid properties, {1} missing properties",
oResult.ValidProperties.Count, oResult.MissingProperties.Count);
if (oResult.MissingProperties.Count > 0)
@@ -95,16 +94,36 @@ namespace ZUGFeRDRESTService.Controllers
Tuple oValidateResult = ValidateBuyerOrderReference(oResult.ValidProperties);
-
- string oMessage = "Die hochgeladene Datei ist eine gültige-ZUGFeRD Rechnung";
-
- _logger.Debug($"Replying with: [{oMessage}]");
-
- return new ValidationResponse()
+ if (oValidateResult.Item1 == false)
{
- status = RESPONSE_OK,
- message = oMessage
- };
+ throw new ZUGFeRDExecption(ErrorType.UnknownError, "Die hochgeladene Datei kann nicht validiert werden, weil ein unbekannter Fehler aufgetreten ist.");
+ }
+
+ string oValidateResultString = oValidateResult.Item2;
+
+ if (oValidateResultString == "ALL REFERENCES CHECKED POSITIVE")
+ {
+ string oMessage = "Die hochgeladene Datei ist eine gültige-ZUGFeRD Rechnung";
+
+ _logger.Info($"Responding with message: [{oMessage}]");
+
+ return new ValidationResponse()
+ {
+ status = RESPONSE_OK,
+ message = oMessage
+ };
+ } else
+ {
+ string oMessage = oValidateResultString;
+
+ _logger.Info($"Responding with message: [{oMessage}]");
+
+ return new ValidationResponse()
+ {
+ status = RESPONSE_ERROR,
+ message = oMessage
+ };
+ }
};
}
catch (ZUGFeRDExecption ex)
@@ -129,7 +148,7 @@ namespace ZUGFeRDRESTService.Controllers
_ => new List()
};
- _logger.Debug($"Replying with: [{oMessage}]");
+ _logger.Info($"Responding with message: [{oMessage}]");
return new ValidationResponse()
{
@@ -144,7 +163,7 @@ namespace ZUGFeRDRESTService.Controllers
string oMessage = "Die hochgeladene Datei kann nicht validiert werden, weil ein unbekannter Fehler aufgetreten ist.";
- _logger.Debug($"Replying with: [{oMessage}]");
+ _logger.Info($"Responding with message: [{oMessage}]");
return new ValidationResponse()
{
@@ -156,9 +175,10 @@ namespace ZUGFeRDRESTService.Controllers
private Tuple ValidateBuyerOrderReference(List pProperties)
{
-
var oMessageId = GetMessageId();
+ _logger.Debug("Created new MessageId: [{0}]", oMessageId);
+ _logger.Debug("Inserting properties into database.");
foreach (var oItem in pProperties)
{
var oResult = InsertPropertyMap(oItem, oMessageId);
@@ -169,17 +189,16 @@ namespace ZUGFeRDRESTService.Controllers
}
}
+ _logger.Debug("Calling validation prodecure.");
try
{
- using SqlCommand oCommand = new SqlCommand("PRCUST_INV_CHECK_FROM_PORTAL @MESSAGE_ID, @MSG_OUTPUT");
- oCommand.CommandType = System.Data.CommandType.StoredProcedure;
- 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;
+ using SqlCommand oCommand = new SqlCommand("EXEC PRCUST_INV_CHECK_FROM_PORTAL @REF_GUID, @MSG_OUTPUT");
+ oCommand.Parameters.Add("REF_GUID", System.Data.SqlDbType.VarChar, 250).Value = oMessageId;
+ oCommand.Parameters.Add("MSG_OUTPUT", System.Data.SqlDbType.VarChar, 500).Direction = System.Data.ParameterDirection.Output;
if (_database.MSSQL.ExecuteNonQuery(oCommand))
{
string oReturnValue = (string)oCommand.Parameters["MSG_OUTPUT"].Value;
-
return new Tuple(true, oReturnValue);
}