modifiche per gestione FOTO
This commit is contained in:
parent
063fdbba1c
commit
13abd0f91f
86
Controllers/FotoController.cs
Normal file
86
Controllers/FotoController.cs
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -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<SelectListItem> GetTecnici()
|
||||
{
|
||||
|
||||
@ -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; }
|
||||
|
||||
32
Views/Foto/ShowImage.cshtml
Normal file
32
Views/Foto/ShowImage.cshtml
Normal file
@ -0,0 +1,32 @@
|
||||
@{
|
||||
ViewData["Title"] = "Visualizza immagine";
|
||||
var folder = ViewBag.Folder as string;
|
||||
var fileName = ViewBag.FileName as string;
|
||||
}
|
||||
|
||||
|
||||
<div class="agy-project-wrapper agy-project-page-wrapper">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="row" style="float:left;width:80%;">
|
||||
@if (!string.IsNullOrEmpty(folder) && !string.IsNullOrEmpty(fileName))
|
||||
{
|
||||
<div>
|
||||
<img src="@Url.Action("RawImage", "Foto", new { folder = folder, fileName = fileName })"
|
||||
alt="Immagine: @fileName"
|
||||
style="max-width:800px; height:auto; border:1px solid #ccc;" />
|
||||
</div>
|
||||
|
||||
<p>
|
||||
<a href="javascript:history.back()">⬅ Torna indietro</a>
|
||||
</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p>Nessuna immagine specificata.</p>
|
||||
}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -308,9 +308,9 @@
|
||||
</div>
|
||||
<div class="col-lg-6 col-md-6 col-sm-12 col-12"> </div>
|
||||
<div class="form-group">
|
||||
<h5><label asp-for="rafoto" class="agy-client-quote"></label></h5>
|
||||
<input asp-for="rafoto" class="agy-form-field require" placeholder="Foto 1" />
|
||||
<span asp-validation-for="rafoto" class="text-danger"></span>
|
||||
<h5><label asp-for="rafoto1" class="agy-client-quote"></label></h5>
|
||||
<input asp-for="rafoto1" class="agy-form-field require" placeholder="Foto 1" />
|
||||
<span asp-validation-for="rafoto1" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="col-lg-6 col-md-6 col-sm-12 col-12"> </div>
|
||||
<div class="form-group">
|
||||
|
||||
@ -164,7 +164,7 @@
|
||||
<b>@Html.DisplayNameFor(model => model.tipo_intervento)</b> @Html.DisplayFor(model => model.tipo_intervento)
|
||||
</div>
|
||||
<div class="col-md-10">
|
||||
<b>@Html.DisplayNameFor(model => model.rafoto)</b> @Html.DisplayFor(model => model.rafoto)
|
||||
<b>@Html.DisplayNameFor(model => model.rafoto1)</b> @Html.DisplayFor(model => model.rafoto1)
|
||||
</div>
|
||||
<div class="col-md-10">
|
||||
<b>@Html.DisplayNameFor(model => model.rafoto2)</b> @Html.DisplayFor(model => model.rafoto2)
|
||||
|
||||
@ -316,139 +316,32 @@
|
||||
}
|
||||
}
|
||||
|
||||
@* <div class="col-md-10">
|
||||
<b>@Html.DisplayNameFor(model => model.azienda_chiamata)</b> @Html.DisplayFor(model => model.azienda_chiamata)
|
||||
</div>*@
|
||||
|
||||
@* <div class="col-md-10">
|
||||
<b>@Html.DisplayNameFor(model => model.codice_chiusura_2)</b> @Html.DisplayFor(model => model.codice_chiusura_2)
|
||||
</div>
|
||||
<div class="col-md-10">
|
||||
<b>@Html.DisplayNameFor(model => model.codice_chiusura_3)</b> @Html.DisplayFor(model => model.codice_chiusura_3)
|
||||
</div>
|
||||
<div class="col-md-10">
|
||||
<b>@Html.DisplayNameFor(model => model.codice_chiusura_4)</b> @Html.DisplayFor(model => model.codice_chiusura_4)
|
||||
</div>
|
||||
<div class="col-md-10">
|
||||
<b>@Html.DisplayNameFor(model => model.codice_chiusura_5)</b> @Html.DisplayFor(model => model.codice_chiusura_5)
|
||||
</div>
|
||||
<div class="col-md-10">
|
||||
<b>@Html.DisplayNameFor(model => model.codice_chiusura_6)</b> @Html.DisplayFor(model => model.codice_chiusura_6)
|
||||
</div>
|
||||
<div class="col-md-10">
|
||||
<b>@Html.DisplayNameFor(model => model.codice_chiusura_7)</b> @Html.DisplayFor(model => model.codice_chiusura_7)
|
||||
</div>
|
||||
<div class="col-md-10">
|
||||
<b>@Html.DisplayNameFor(model => model.codice_chiusura_8)</b> @Html.DisplayFor(model => model.codice_chiusura_8)
|
||||
</div>
|
||||
<div class="col-md-10">
|
||||
<b>@Html.DisplayNameFor(model => model.codice_chiusura_9)</b> @Html.DisplayFor(model => model.codice_chiusura_9)
|
||||
</div>
|
||||
<div class="col-md-10">
|
||||
<b>@Html.DisplayNameFor(model => model.codice_chiusura_10)</b> @Html.DisplayFor(model => model.codice_chiusura_10)
|
||||
</div>*@
|
||||
@* <div class="col-md-10">
|
||||
<b>@Html.DisplayNameFor(model => model.generato)</b> @Html.DisplayFor(model => model.generato)
|
||||
</div>*@
|
||||
@* <div class="col-md-10">
|
||||
<b>@Html.DisplayNameFor(model => model.azienda_tecnico)</b> @Html.DisplayFor(model => model.azienda_tecnico)
|
||||
</div>*@
|
||||
|
||||
@* <div class="col-md-10">
|
||||
<b>@Html.DisplayNameFor(model => model.rifiutata)</b> @Html.DisplayFor(model => model.rifiutata)
|
||||
</div>*@
|
||||
|
||||
@* <div class="col-md-10">
|
||||
<b>@Html.DisplayNameFor(model => model.incarico)</b> @Html.DisplayFor(model => model.incarico)
|
||||
</div>*@
|
||||
|
||||
|
||||
@* <div class="col-md-10">
|
||||
<b>@Html.DisplayNameFor(model => model.data_validita)</b> @Html.DisplayFor(model => model.data_validita)
|
||||
</div>*@
|
||||
@* <div class="col-md-10">
|
||||
<b>@Html.DisplayNameFor(model => model.immagine)</b> @Html.DisplayFor(model => model.immagine)
|
||||
</div>*@
|
||||
@*
|
||||
<div class="col-md-10">
|
||||
<b>@Html.DisplayNameFor(model => model.data_effettiva)</b> @Html.DisplayFor(model => model.data_effettiva)
|
||||
</div>*@
|
||||
|
||||
@* <div class="col-md-10">
|
||||
<b>@Html.DisplayNameFor(model => model.note_intervento)</b> @Html.DisplayFor(model => model.note_intervento)
|
||||
</div>*@
|
||||
@* <div class="col-md-10">
|
||||
<b>@Html.DisplayNameFor(model => model.nuovo_contratto)</b> @Html.DisplayFor(model => model.nuovo_contratto)
|
||||
</div>*@
|
||||
@*
|
||||
<div class="col-md-10">
|
||||
<b>@Html.DisplayNameFor(model => model.causale)</b> @Html.DisplayFor(model => model.causale)
|
||||
</div>*@
|
||||
@{
|
||||
if (!string.IsNullOrEmpty(Model.rafoto1))
|
||||
{
|
||||
// <div class="col-md-10">
|
||||
// <b>@Html.DisplayNameFor(model => model.rafoto1)</b> @Html.DisplayFor(model => model.rafoto1)
|
||||
// </div>
|
||||
<div>
|
||||
<a href="@Url.Action("ShowOrServe", "Foto", new { folder = Model.azienda_impianto, fileName = Model.rafoto1 })">
|
||||
Immagine: @Html.DisplayNameFor(model => model.rafoto1)
|
||||
</a>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@* <div class="col-md-10">
|
||||
<b>@Html.DisplayNameFor(model => model.tipo_rapportino)</b> @Html.DisplayFor(model => model.tipo_rapportino)
|
||||
</div>*@
|
||||
|
||||
@* <dt class="col-sm-2" hidden>
|
||||
@Html.DisplayNameFor(model => model.rafoto)
|
||||
</dt>
|
||||
<dd class="col-sm-10" hidden>
|
||||
@Html.DisplayFor(model => model.rafoto)
|
||||
</dd>
|
||||
<dt class="col-sm-2" hidden>
|
||||
@Html.DisplayNameFor(model => model.rafoto2)
|
||||
</dt>
|
||||
<dd class="col-sm-10" hidden>
|
||||
@Html.DisplayFor(model => model.rafoto2)
|
||||
</dd>
|
||||
<dt class="col-sm-2" hidden>
|
||||
@Html.DisplayNameFor(model => model.rafoto3)
|
||||
</dt>
|
||||
<dd class="col-sm-10" hidden>
|
||||
@Html.DisplayFor(model => model.rafoto3)
|
||||
</dd>
|
||||
<dt class="col-sm-2" hidden>
|
||||
@Html.DisplayNameFor(model => model.rafoto4)
|
||||
</dt>
|
||||
<dd class="col-sm-10" hidden>
|
||||
@Html.DisplayFor(model => model.rafoto4)
|
||||
</dd>
|
||||
<dt class="col-sm-2" hidden>
|
||||
@Html.DisplayNameFor(model => model.rafoto5)
|
||||
</dt>
|
||||
<dd class="col-sm-10" hidden>
|
||||
@Html.DisplayFor(model => model.rafoto5)
|
||||
</dd>
|
||||
<dt class="col-sm-2" hidden>
|
||||
@Html.DisplayNameFor(model => model.rafoto6)
|
||||
</dt>
|
||||
<dd class="col-sm-10" hidden>
|
||||
@Html.DisplayFor(model => model.rafoto6)
|
||||
</dd>
|
||||
<dt class="col-sm-2" hidden>
|
||||
@Html.DisplayNameFor(model => model.rafoto7)
|
||||
</dt>
|
||||
<dd class="col-sm-10" hidden>
|
||||
@Html.DisplayFor(model => model.rafoto7)
|
||||
</dd>
|
||||
<dt class="col-sm-2" hidden>
|
||||
@Html.DisplayNameFor(model => model.rafoto8)
|
||||
</dt>
|
||||
<dd class="col-sm-10" hidden>
|
||||
@Html.DisplayFor(model => model.rafoto8)
|
||||
</dd>
|
||||
<dt class="col-sm-2" hidden>
|
||||
@Html.DisplayNameFor(model => model.rafoto9)
|
||||
</dt>
|
||||
<dd class="col-sm-10" hidden>
|
||||
@Html.DisplayFor(model => model.rafoto9)
|
||||
</dd>
|
||||
<dt class="col-sm-2" hidden>
|
||||
@Html.DisplayNameFor(model => model.rafoto10)
|
||||
</dt>
|
||||
<dd class="col-sm-10" hidden>
|
||||
@Html.DisplayFor(model => model.rafoto10)
|
||||
</dd>*@
|
||||
<div>
|
||||
<a asp-action="Index" value="Torna alla lista" class="agy-btn submitForm">Torna alla lista</a>
|
||||
</div>
|
||||
|
||||
@ -343,9 +343,9 @@
|
||||
<div class="form-group">
|
||||
@*<label asp-for="rafoto" class="control-label"></label>*@
|
||||
@*<input asp-for="rafoto" class="form-control" />*@
|
||||
@Html.HiddenFor(x => x.rafoto)
|
||||
@Html.DisplayFor(model => model.rafoto)
|
||||
<span asp-validation-for="rafoto" class="text-danger"></span>
|
||||
@Html.HiddenFor(x => x.rafoto1)
|
||||
@Html.DisplayFor(model => model.rafoto1)
|
||||
<span asp-validation-for="rafoto1" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@*<label asp-for="rafoto2" class="control-label"></label>*@
|
||||
|
||||
@ -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)
|
||||
|
||||
19
Views/Rapp_New/ShowImage.cshtml
Normal file
19
Views/Rapp_New/ShowImage.cshtml
Normal file
@ -0,0 +1,19 @@
|
||||
@{
|
||||
ViewData["Title"] = "Visualizza immagine";
|
||||
var fileName = ViewBag.FileName as string;
|
||||
}
|
||||
|
||||
<h2>@ViewData["Title"]</h2>
|
||||
|
||||
@if (!string.IsNullOrEmpty(fileName))
|
||||
{
|
||||
<div>
|
||||
<img src="@Url.Action("GetImage", "Rapp_New", new { filePath = fileName })"
|
||||
alt="Immagine: @fileName"
|
||||
style="max-width:600px; height:auto; border:1px solid #ccc;" />
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p>Nessuna immagine specificata.</p>
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user