diff --git a/Controllers/FotoController.cs b/Controllers/FotoController.cs new file mode 100644 index 0000000..c13d31b --- /dev/null +++ b/Controllers/FotoController.cs @@ -0,0 +1,86 @@ +using Microsoft.AspNetCore.Mvc; + +namespace VirtualTask.Controllers +{ + + [Route("foto")] + public class FotoController : Controller + { + private readonly string _rootPath = "/mnt/storagebox"; + + [HttpGet("{folder}/{fileName}")] + public IActionResult ShowOrServe(string folder, string fileName) + { + if (string.IsNullOrEmpty(folder) || string.IsNullOrEmpty(fileName)) + return Content("Parametri non validi"); + + var safeFolder = Path.GetFileName(folder); // sicurezza + var safeFileName = Path.GetFileName(fileName); + + // Percorso: /mnt/storagebox/{folder}/PHOTO/{fileName} + var filePath = Path.Combine(_rootPath, safeFolder, "PHOTO", safeFileName); + + + //SOLO PER TEST!!!!!! + //filePath = "C:\\DATI\\V000000009_2.jpg"; + + + if (!System.IO.File.Exists(filePath)) + return NotFound("File non trovato"); + + //var acceptHeader = Request.Headers["Accept"].ToString(); + + //if (!string.IsNullOrEmpty(acceptHeader) && acceptHeader.Contains("image")) + //{ + // // rileva content-type dinamico + // var ext = Path.GetExtension(safeFileName).ToLowerInvariant(); + // var contentType = ext switch + // { + // ".png" => "image/png", + // ".webp" => "image/webp", + // ".jpg" or ".jpeg" => "image/jpeg", + // _ => "application/octet-stream" + // }; + + // var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read); + // return File(stream, contentType); + //} + + // Se non è richiesta immagine → mostra view Razor + ViewBag.Folder = safeFolder; + ViewBag.FileName = safeFileName; + return View("ShowImage"); + } + + // Endpoint che restituisce il file binario, usato dentro la view + [HttpGet("raw/{folder}/{fileName}")] + public IActionResult RawImage(string folder, string fileName) + { + var safeFolder = Path.GetFileName(folder); + var safeFileName = Path.GetFileName(fileName); + + var filePath = Path.Combine(_rootPath, safeFolder, "PHOTO", safeFileName); + + //SOLO PER TEST!!!!!! + //filePath = "C:\\DATI\\V000000009_2.jpg"; + + + if (!System.IO.File.Exists(filePath)) + return NotFound("File non trovato"); + + var ext = Path.GetExtension(safeFileName).ToLowerInvariant(); + var contentType = ext switch + { + ".png" => "image/png", + ".jpg" or ".jpeg" => "image/jpeg", + ".webp" => "image/webp", + _ => "application/octet-stream" + }; + + var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read); + return File(stream, contentType); + } + } + + +} diff --git a/Controllers/Rapp_NewController.cs b/Controllers/Rapp_NewController.cs index d7bc13b..6d78c1e 100644 --- a/Controllers/Rapp_NewController.cs +++ b/Controllers/Rapp_NewController.cs @@ -401,6 +401,27 @@ namespace VirtualTask.Controllers #endregion + #region FOTO ALLEGATE + public IActionResult ShowImage(string filePath) + { + //ViewBag.FileName = Path.GetFileName(filePath); + ViewBag.FileName = filePath; + return View(); + } + + public IActionResult GetImage(string filePath) + { + //var filePath = Path.Combine(_basePath, fileName); + + if (!System.IO.File.Exists(filePath)) + return NotFound(); + + var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read); + return File(stream, "image/jpeg"); + } + + #endregion + //metodo per riempire combobox con la tabella tecnici private List GetTecnici() { diff --git a/Models/Rapp_New.cs b/Models/Rapp_New.cs index e21e2e3..0cf3bae 100644 --- a/Models/Rapp_New.cs +++ b/Models/Rapp_New.cs @@ -172,7 +172,7 @@ namespace VirtualTask.Models public string? tipo_intervento { get; set; } [Display(Name = "FOTO 1")] - public string? rafoto { get; set; } + public string? rafoto1 { get; set; } [Display(Name = "FOTO 2")] public string? rafoto2 { get; set; } diff --git a/Views/Foto/ShowImage.cshtml b/Views/Foto/ShowImage.cshtml new file mode 100644 index 0000000..178abec --- /dev/null +++ b/Views/Foto/ShowImage.cshtml @@ -0,0 +1,32 @@ +@{ + ViewData["Title"] = "Visualizza immagine"; + var folder = ViewBag.Folder as string; + var fileName = ViewBag.FileName as string; +} + + +
+
+
+
+ @if (!string.IsNullOrEmpty(folder) && !string.IsNullOrEmpty(fileName)) + { +
+ Immagine: @fileName +
+ +

+ ⬅ Torna indietro +

+ } + else + { +

Nessuna immagine specificata.

+ } + +
+
+
+
diff --git a/Views/Rapp_New/Create.cshtml b/Views/Rapp_New/Create.cshtml index c47371e..7d2950f 100644 --- a/Views/Rapp_New/Create.cshtml +++ b/Views/Rapp_New/Create.cshtml @@ -308,9 +308,9 @@
 
-
- - +
+ +
 
diff --git a/Views/Rapp_New/Delete.cshtml b/Views/Rapp_New/Delete.cshtml index 71aa0e4..de4efdb 100644 --- a/Views/Rapp_New/Delete.cshtml +++ b/Views/Rapp_New/Delete.cshtml @@ -164,7 +164,7 @@ @Html.DisplayNameFor(model => model.tipo_intervento)   @Html.DisplayFor(model => model.tipo_intervento)
- @Html.DisplayNameFor(model => model.rafoto)   @Html.DisplayFor(model => model.rafoto) + @Html.DisplayNameFor(model => model.rafoto1)   @Html.DisplayFor(model => model.rafoto1)
@Html.DisplayNameFor(model => model.rafoto2)   @Html.DisplayFor(model => model.rafoto2) diff --git a/Views/Rapp_New/Details.cshtml b/Views/Rapp_New/Details.cshtml index 450a149..5047aec 100644 --- a/Views/Rapp_New/Details.cshtml +++ b/Views/Rapp_New/Details.cshtml @@ -316,139 +316,32 @@ } } - @*
- @Html.DisplayNameFor(model => model.azienda_chiamata) @Html.DisplayFor(model => model.azienda_chiamata) -
*@ - - @*
- @Html.DisplayNameFor(model => model.codice_chiusura_2) @Html.DisplayFor(model => model.codice_chiusura_2) -
-
- @Html.DisplayNameFor(model => model.codice_chiusura_3) @Html.DisplayFor(model => model.codice_chiusura_3) -
-
- @Html.DisplayNameFor(model => model.codice_chiusura_4) @Html.DisplayFor(model => model.codice_chiusura_4) -
-
- @Html.DisplayNameFor(model => model.codice_chiusura_5) @Html.DisplayFor(model => model.codice_chiusura_5) -
-
- @Html.DisplayNameFor(model => model.codice_chiusura_6) @Html.DisplayFor(model => model.codice_chiusura_6) -
-
- @Html.DisplayNameFor(model => model.codice_chiusura_7) @Html.DisplayFor(model => model.codice_chiusura_7) -
-
- @Html.DisplayNameFor(model => model.codice_chiusura_8) @Html.DisplayFor(model => model.codice_chiusura_8) -
-
- @Html.DisplayNameFor(model => model.codice_chiusura_9) @Html.DisplayFor(model => model.codice_chiusura_9) -
-
- @Html.DisplayNameFor(model => model.codice_chiusura_10) @Html.DisplayFor(model => model.codice_chiusura_10) -
*@ - @*
- @Html.DisplayNameFor(model => model.generato) @Html.DisplayFor(model => model.generato) -
*@ - @*
- @Html.DisplayNameFor(model => model.azienda_tecnico) @Html.DisplayFor(model => model.azienda_tecnico) -
*@ - - @*
- @Html.DisplayNameFor(model => model.rifiutata) @Html.DisplayFor(model => model.rifiutata) -
*@ - - @*
- @Html.DisplayNameFor(model => model.incarico) @Html.DisplayFor(model => model.incarico) -
*@ - @*
- @Html.DisplayNameFor(model => model.data_validita) @Html.DisplayFor(model => model.data_validita) -
*@ - @*
- @Html.DisplayNameFor(model => model.immagine) @Html.DisplayFor(model => model.immagine) -
*@ - @* -
- @Html.DisplayNameFor(model => model.data_effettiva) @Html.DisplayFor(model => model.data_effettiva) -
*@ - @*
- @Html.DisplayNameFor(model => model.note_intervento) @Html.DisplayFor(model => model.note_intervento) -
*@ - @*
- @Html.DisplayNameFor(model => model.nuovo_contratto) @Html.DisplayFor(model => model.nuovo_contratto) -
*@ - @* -
- @Html.DisplayNameFor(model => model.causale) @Html.DisplayFor(model => model.causale) -
*@ + @{ + if (!string.IsNullOrEmpty(Model.rafoto1)) + { + //
+ // @Html.DisplayNameFor(model => model.rafoto1) @Html.DisplayFor(model => model.rafoto1) + //
+
+ + Immagine: @Html.DisplayNameFor(model => model.rafoto1) + +
+ } + } + + + + + + + + - @*
- @Html.DisplayNameFor(model => model.tipo_rapportino) @Html.DisplayFor(model => model.tipo_rapportino) -
*@ - @* - - - - - - - - - - - - - - - - - - - *@
Torna alla lista
diff --git a/Views/Rapp_New/Edit.cshtml b/Views/Rapp_New/Edit.cshtml index 0cc0ea9..c315394 100644 --- a/Views/Rapp_New/Edit.cshtml +++ b/Views/Rapp_New/Edit.cshtml @@ -343,9 +343,9 @@
@**@ @**@ - @Html.HiddenFor(x => x.rafoto) - @Html.DisplayFor(model => model.rafoto) - + @Html.HiddenFor(x => x.rafoto1) + @Html.DisplayFor(model => model.rafoto1) +
@**@ diff --git a/Views/Rapp_New/Index.cshtml b/Views/Rapp_New/Index.cshtml index dc91783..19ccd81 100644 --- a/Views/Rapp_New/Index.cshtml +++ b/Views/Rapp_New/Index.cshtml @@ -186,7 +186,7 @@ @Html.HiddenFor(modelItem => item.totale) @Html.HiddenFor(modelItem => item.note_pagamento) @Html.HiddenFor(modelItem => item.tipo_intervento) - @Html.HiddenFor(modelItem => item.rafoto) + @Html.HiddenFor(modelItem => item.rafoto1) @Html.HiddenFor(modelItem => item.rafoto2) @Html.HiddenFor(modelItem => item.rafoto3) @Html.HiddenFor(modelItem => item.rafoto4) diff --git a/Views/Rapp_New/ShowImage.cshtml b/Views/Rapp_New/ShowImage.cshtml new file mode 100644 index 0000000..6e462c8 --- /dev/null +++ b/Views/Rapp_New/ShowImage.cshtml @@ -0,0 +1,19 @@ +@{ + ViewData["Title"] = "Visualizza immagine"; + var fileName = ViewBag.FileName as string; +} + +

@ViewData["Title"]

+ +@if (!string.IsNullOrEmpty(fileName)) +{ +
+ Immagine: @fileName +
+} +else +{ +

Nessuna immagine specificata.

+}