diff --git a/src/WorkFlowCheck.API/Controllers/SystemController.cs b/src/WorkFlowCheck.API/Controllers/SystemController.cs index 99a9029..65bc9d4 100644 --- a/src/WorkFlowCheck.API/Controllers/SystemController.cs +++ b/src/WorkFlowCheck.API/Controllers/SystemController.cs @@ -93,6 +93,58 @@ namespace WorkFlowCheck.API.Controllers } return retVal; } + [HttpGet("GetAllPDFFiles")] + public async Task>> GetAllPDFilesAsync() + { + var retVal = new ApiResponseDTO>() + { + IsSuccess = true, + }; + try + { + var imageFolder = Path.Combine(Directory.GetCurrentDirectory(), "PDF"); + var files = Directory.GetFiles(imageFolder) + .Select(f => + { + var fileInfo = new FileInfo(f); + return new + { + FileName = fileInfo.Name, + FileSize = FormatFileSize(fileInfo.Length), + CreatedDate = fileInfo.CreationTime.ToString("yyyy.MM.dd HH:mm"), + }; + }); + + var checkListFileInfos = new List(); + foreach (var file in files.OrderBy(o => o.FileName).ToList()) + { + var checkListFileInfoDTO = new ImageFileDTO() + { + FileName = file.FileName, + FileSize = file.FileSize, + CreateDate = file.CreatedDate, + + }; + checkListFileInfos.Add(checkListFileInfoDTO); + } + + if (checkListFileInfos != null) + { + retVal.IsSuccess = true; + retVal.Data = checkListFileInfos; + } + else + { + retVal.IsSuccess = false; + retVal.Errors.Add("No data!"); + } + } + catch (Exception ex) + { + Log.Error(ex.Message); + } + return retVal; + } [HttpGet("DownloadFile/{filename}")] public async Task> DownloadFile(string filename) @@ -112,6 +164,38 @@ namespace WorkFlowCheck.API.Controllers byte[] response = System.IO.File.ReadAllBytes(imageFile); + if (response != null) + { + + retVal.IsSuccess = true; + retVal.Data = response; + } + else + { + retVal.IsSuccess = false; + retVal.Errors.Add("No data!"); + } + + return retVal; + } + [HttpGet("DownloadPDFFile/{filename}")] + public async Task> DownloadPDFFile(string filename) + { + var retVal = new ApiResponseDTO() + { + IsSuccess = false, + }; + var imageFile = Path.Combine(Directory.GetCurrentDirectory(), "PDF", filename); + + if (!System.IO.File.Exists(imageFile)) + { + retVal.Errors.Add($"{filename} does not exist"); + return retVal; + } + + byte[] response = System.IO.File.ReadAllBytes(imageFile); + + if (response != null) { diff --git a/src/WorkFlowCheck.Common/DTO/PDFFileDTO.cs b/src/WorkFlowCheck.Common/DTO/PDFFileDTO.cs new file mode 100644 index 0000000..e9c2b8f --- /dev/null +++ b/src/WorkFlowCheck.Common/DTO/PDFFileDTO.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WorkFlowCheck.Common.DTO +{ + public class PDFFileDTO + { + public string Id { get; set; } + public string FileName { get; set; } + public string FileSize { get; set; } + public string CreateDate { get; set; } + } +} diff --git a/src/WorkFlowCheck.Web/Pages/BaseStock/ImageFiles/ImageFilesPage.cshtml b/src/WorkFlowCheck.Web/Pages/BaseStock/ImageFiles/ImageFilesPage.cshtml index a96b802..5e3662b 100644 --- a/src/WorkFlowCheck.Web/Pages/BaseStock/ImageFiles/ImageFilesPage.cshtml +++ b/src/WorkFlowCheck.Web/Pages/BaseStock/ImageFiles/ImageFilesPage.cshtml @@ -3,7 +3,7 @@ @using WorkFlowCheck.Common.Helper @using WorkFlowCheck.Common.DTO @{ - ViewData["Title"] = "Berendezések"; + ViewData["Title"] = "Képek"; }

@ViewData["Title"]

diff --git a/src/WorkFlowCheck.Web/Pages/BaseStock/PDFFiles/PDFFilesPage.cshtml b/src/WorkFlowCheck.Web/Pages/BaseStock/PDFFiles/PDFFilesPage.cshtml new file mode 100644 index 0000000..ffff064 --- /dev/null +++ b/src/WorkFlowCheck.Web/Pages/BaseStock/PDFFiles/PDFFilesPage.cshtml @@ -0,0 +1,80 @@ +@page +@model WorkFlowCheck.Web.Pages.BaseStock.PDFFiles.PDFFilesPageModel +@using WorkFlowCheck.Common.Helper +@using WorkFlowCheck.Common.DTO +@{ + ViewData["Title"] = "PDF fájlok"; +} +

@ViewData["Title"]

+ +
+ + + + + + + + + + + + + + + + + + + +
ID@DisplayNameHelper.GetDisplayName(nameof(PDFFileDTO.FileName), typeof(PDFFileDTO))@DisplayNameHelper.GetDisplayName(nameof(PDFFileDTO.CreateDate), typeof(PDFFileDTO))@DisplayNameHelper.GetDisplayName(nameof(PDFFileDTO.FileSize), typeof(PDFFileDTO))Action
ID@DisplayNameHelper.GetDisplayName(nameof(PDFFileDTO.FileName), typeof(PDFFileDTO))@DisplayNameHelper.GetDisplayName(nameof(PDFFileDTO.FileSize), typeof(PDFFileDTO))@DisplayNameHelper.GetDisplayName(nameof(PDFFileDTO.CreateDate), typeof(PDFFileDTO))Action
+
+ +@section Scripts { + +} diff --git a/src/WorkFlowCheck.Web/Pages/BaseStock/PDFFiles/PDFFilesPage.cshtml.cs b/src/WorkFlowCheck.Web/Pages/BaseStock/PDFFiles/PDFFilesPage.cshtml.cs new file mode 100644 index 0000000..ad5be14 --- /dev/null +++ b/src/WorkFlowCheck.Web/Pages/BaseStock/PDFFiles/PDFFilesPage.cshtml.cs @@ -0,0 +1,47 @@ +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using WorkFlowCheck.Web.Services.Interfaces; + +namespace WorkFlowCheck.Web.Pages.BaseStock.PDFFiles +{ + [Authorize] + public class PDFFilesPageModel : PageModel + { + private readonly ILogger _logger; + private readonly ISystemService _systemService; + public PDFFilesPageModel(ILogger logger, ISystemService systemService) + { + _logger = logger; + _systemService = systemService; + } + public async Task OnGet() + { + } + public async Task OnGetLoadPDFFiles() + { + var results = await _systemService.GetAllPDFFilesAsync(); + return new JsonResult(new { data = results }); + } + public async Task OnGetDownloadFile(string filename) + { + var response = await _systemService.DownloadPDFFile(filename); + + + if (response.IsSuccess) + { + + var result = new FileContentResult(response.Data, "application/pdf") + { + FileDownloadName = filename, + FileContents = response.Data + }; + return result; + } + else + { + return new JsonResult(new { success = false }); + } + } + } +} diff --git a/src/WorkFlowCheck.Web/Pages/Shared/_Layout.cshtml b/src/WorkFlowCheck.Web/Pages/Shared/_Layout.cshtml index 61fbd33..00cd26e 100644 --- a/src/WorkFlowCheck.Web/Pages/Shared/_Layout.cshtml +++ b/src/WorkFlowCheck.Web/Pages/Shared/_Layout.cshtml @@ -38,6 +38,7 @@
  • Lokációk
  • Fényképek
  • +
  • PDF állomány