Compare commits
2 Commits
80f858bdf5
...
f04e1b4c85
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f04e1b4c85 | ||
|
|
873b024f13 |
@@ -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
|
||||
/// <summary>
|
||||
/// POST: /api/validation
|
||||
/// </summary>
|
||||
/// <param name="files">This parameter's name needs to correspond to the html form's file-input name</param>
|
||||
/// <param name="file">This parameter's name needs to correspond to the html form's file-input name</param>
|
||||
/// <param name="user_id">This is the email address which the user supplied</param>
|
||||
[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<bool, string> 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<string>()
|
||||
};
|
||||
|
||||
_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<bool, string> ValidateBuyerOrderReference(List<ValidProperty> 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<bool, string>(true, oReturnValue);
|
||||
|
||||
}
|
||||
|
||||
@@ -23,31 +23,25 @@ namespace ZUGFeRDRESTService
|
||||
public MSSQLServer MSSQL { get; set; }
|
||||
public Firebird Firebird { get; set; }
|
||||
|
||||
public Database(ILogging Logging, IConfiguration Config, IOptions<Config> Options)
|
||||
public Database(ILogging Logging, IConfiguration Config)
|
||||
{
|
||||
var LogConfig = Logging.LogConfig;
|
||||
var Logger = Logging.LogConfig.GetLogger();
|
||||
var FirebirdConfig = Options.Value.Firebird;
|
||||
var oLogConfig = Logging.LogConfig;
|
||||
var oLogger = Logging.LogConfig.GetLogger();
|
||||
var oAppConfig = Config.GetSection("Config");
|
||||
var oFirebirdConfig = oAppConfig.GetSection("Firebird");
|
||||
|
||||
// var AppConfig = Config.GetSection("Config");
|
||||
// var FBConfig = AppConfig.GetSection("Firebird");
|
||||
oLogger.Debug("Establishing MSSQL Database connection..");
|
||||
MSSQL = new MSSQLServer(oLogConfig, oAppConfig["MSSQLConnectionString"]);
|
||||
|
||||
oLogger.Debug("Establishing Firebird Database connection..");
|
||||
Firebird = new Firebird(oLogConfig,
|
||||
oFirebirdConfig["Datasource"],
|
||||
oFirebirdConfig["Database"],
|
||||
oFirebirdConfig["Username"],
|
||||
oFirebirdConfig["Password"]);
|
||||
|
||||
Logger.Debug("Establishing MSSQL Database connection..");
|
||||
MSSQL = new MSSQLServer(LogConfig, Options.Value.MSSQLConnectionString);
|
||||
|
||||
Logger.Debug("Establishing Firebird Database connection..");
|
||||
Firebird = new Firebird(LogConfig,
|
||||
FirebirdConfig.Datasource,
|
||||
FirebirdConfig.Database,
|
||||
FirebirdConfig.Username,
|
||||
FirebirdConfig.Password);
|
||||
|
||||
// MSSQL = new MSSQLServer(LogConfig, AppConfig["MSSQLConnectionString"]);
|
||||
// Firebird = new Firebird(LogConfig, FBConfig["Datasource"], FBConfig["Database"], FBConfig["Username"], FBConfig["Password"]);
|
||||
|
||||
Logger.Debug("MSSQL Connection: [{0}]", MSSQL.CurrentConnectionString);
|
||||
Logger.Debug("Firebird Connection: [{0}]", Firebird.ConnectionString);
|
||||
oLogger.Debug("MSSQL Connection: [{0}]", MSSQL.CurrentConnectionString);
|
||||
oLogger.Debug("Firebird Connection: [{0}]", Firebird.ConnectionString);
|
||||
}
|
||||
|
||||
public string GetGDPictureKey()
|
||||
|
||||
Reference in New Issue
Block a user