From 4c4ea524eb356d3c18aea1cbd3a9e975026d85bb Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Wed, 11 Mar 2020 16:51:27 +0100 Subject: [PATCH] basic zugferd validation --- Controls.LookupGrid/My Project/licenses.licx | 2 + .../ZugferdValidationController.cs | 68 +++++++++++++------ .../ZUGFeRDRESTService/Pages/Index.cshtml | 2 +- 3 files changed, 51 insertions(+), 21 deletions(-) diff --git a/Controls.LookupGrid/My Project/licenses.licx b/Controls.LookupGrid/My Project/licenses.licx index fb064627..ca29cac8 100644 --- a/Controls.LookupGrid/My Project/licenses.licx +++ b/Controls.LookupGrid/My Project/licenses.licx @@ -1 +1,3 @@ +DevExpress.XtraEditors.GridLookUpEdit, DevExpress.XtraGrid.v19.2, Version=19.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a +DevExpress.XtraEditors.Repository.RepositoryItemGridLookUpEdit, DevExpress.XtraGrid.v19.2, Version=19.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a DevExpress.XtraGrid.GridControl, DevExpress.XtraGrid.v19.2, Version=19.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a diff --git a/WEBSERVICES/ZUGFeRDRESTService/Controllers/ZugferdValidationController.cs b/WEBSERVICES/ZUGFeRDRESTService/Controllers/ZugferdValidationController.cs index 5e1114b5..f8d462c3 100644 --- a/WEBSERVICES/ZUGFeRDRESTService/Controllers/ZugferdValidationController.cs +++ b/WEBSERVICES/ZUGFeRDRESTService/Controllers/ZugferdValidationController.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; @@ -9,42 +10,69 @@ using System.Text.Json.Serialization; namespace ZUGFeRDRESTService.Controllers { - public class ZugferdValidationResponse + [Route("api/[controller]")] + [ApiController] + public class ZugferdValidationController : ControllerBase { - public string status; - public string message; - public List errors; - public static string RESPONSE_OK = "OK"; public static string RESPONSE_ERROR = "ERROR"; - public ZugferdValidationResponse() + private readonly IZugferdValidationDataService _dataService; + + public class ZugferdValidationResponse { - status = RESPONSE_OK; - message = String.Empty; - errors = new List(); - } - } + public string status; + public string message; + public List errors; - [Route("api/[controller]")] - [ApiController] - public class ZugferdValidationController : ControllerBase - { - private readonly IZugferdValidationDataService _dataService; + + + public ZugferdValidationResponse() + { + status = RESPONSE_OK; + message = String.Empty; + errors = new List(); + } + } public ZugferdValidationController(IZugferdValidationDataService dataService) { _dataService = dataService; } - // POST: api/ZugferdValidation + /// + /// POST: api/ZugferdValidation + /// + /// This parameter's name needs to correspond to the html form's file-input name [HttpPost] - public ZugferdValidationResponse Post(List files) + public async Task Post(List files) { - var oFiles = files; + var oFilePaths = new List(); + var oFileNames = new List(); + + if (files.Count == 0) { + return new ZugferdValidationResponse() + { + status = RESPONSE_ERROR, + message = "No File received!" + }; + } + + foreach (var formFile in files) + { + var oFilePath = Path.GetTempFileName(); + oFilePaths.Add(oFilePath); + oFileNames.Add(formFile.FileName); + + using (var oStream = new FileStream(oFilePath, FileMode.Create)) + { + await formFile.CopyToAsync(oStream); + } + } + var oResponse = new ZugferdValidationResponse { - message = "You uploaded " + oFiles.Count + " files." + message = "You uploaded the following file: " + oFileNames.First() }; return oResponse; diff --git a/WEBSERVICES/ZUGFeRDRESTService/Pages/Index.cshtml b/WEBSERVICES/ZUGFeRDRESTService/Pages/Index.cshtml index b98ed0e6..b5f02066 100644 --- a/WEBSERVICES/ZUGFeRDRESTService/Pages/Index.cshtml +++ b/WEBSERVICES/ZUGFeRDRESTService/Pages/Index.cshtml @@ -8,7 +8,7 @@

PDF Datei: - +