basic zugferd validation

This commit is contained in:
Jonathan Jenne 2020-03-11 16:51:27 +01:00
parent 3d5bfd5f39
commit 4c4ea524eb
3 changed files with 52 additions and 22 deletions

View File

@ -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 DevExpress.XtraGrid.GridControl, DevExpress.XtraGrid.v19.2, Version=19.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
@ -9,42 +10,69 @@ using System.Text.Json.Serialization;
namespace ZUGFeRDRESTService.Controllers namespace ZUGFeRDRESTService.Controllers
{ {
public class ZugferdValidationResponse
{
public string status;
public string message;
public List<string> errors;
public static string RESPONSE_OK = "OK";
public static string RESPONSE_ERROR = "ERROR";
public ZugferdValidationResponse()
{
status = RESPONSE_OK;
message = String.Empty;
errors = new List<string>();
}
}
[Route("api/[controller]")] [Route("api/[controller]")]
[ApiController] [ApiController]
public class ZugferdValidationController : ControllerBase public class ZugferdValidationController : ControllerBase
{ {
public static string RESPONSE_OK = "OK";
public static string RESPONSE_ERROR = "ERROR";
private readonly IZugferdValidationDataService _dataService; private readonly IZugferdValidationDataService _dataService;
public class ZugferdValidationResponse
{
public string status;
public string message;
public List<string> errors;
public ZugferdValidationResponse()
{
status = RESPONSE_OK;
message = String.Empty;
errors = new List<string>();
}
}
public ZugferdValidationController(IZugferdValidationDataService dataService) public ZugferdValidationController(IZugferdValidationDataService dataService)
{ {
_dataService = dataService; _dataService = dataService;
} }
// POST: api/ZugferdValidation /// <summary>
/// POST: api/ZugferdValidation
/// </summary>
/// <param name="files">This parameter's name needs to correspond to the html form's file-input name</param>
[HttpPost] [HttpPost]
public ZugferdValidationResponse Post(List<IFormFile> files) public async Task<ZugferdValidationResponse> Post(List<IFormFile> files)
{ {
var oFiles = files; var oFilePaths = new List<String>();
var oFileNames = new List<String>();
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 var oResponse = new ZugferdValidationResponse
{ {
message = "You uploaded " + oFiles.Count + " files." message = "You uploaded the following file: " + oFileNames.First()
}; };
return oResponse; return oResponse;

View File

@ -8,7 +8,7 @@
<form method="post" action="/api/zugferdvalidation" enctype="multipart/form-data" > <form method="post" action="/api/zugferdvalidation" enctype="multipart/form-data" >
<p> <p>
<span>PDF Datei:</span> <span>PDF Datei:</span>
<input type="file" /> <input type="file" name="files" />
</p> </p>
<button type="submit">Submit</button> <button type="submit">Submit</button>