gestione Upload Foto
This commit is contained in:
parent
6f4aaa9a49
commit
927dc4f52d
@ -379,6 +379,13 @@ namespace ApiPolo.Controllers
|
||||
c.desc_interv_stampa = a.desc_interv_stampa != null ? a.desc_interv_stampa : false;
|
||||
c.note_interv_stampa = a.note_interv_stampa != null ? a.note_interv_stampa :false;
|
||||
|
||||
|
||||
c.ftp_url_stor = a.ftp_url_stor != null ? a.ftp_url_stor : string.Empty;
|
||||
c.ftp_usr_stor = a.ftp_usr_stor != null ? a.ftp_usr_stor : string.Empty;
|
||||
c.ftp_pwd_stor = a.ftp_pwd_stor != null ? a.ftp_pwd_stor : string.Empty;
|
||||
c.root_stor = a.root_stor != null ? a.root_stor : string.Empty;
|
||||
c.abilita_foto = a.abilita_foto != null ? a.abilita_foto : false;
|
||||
|
||||
}
|
||||
return c;
|
||||
}
|
||||
@ -2851,6 +2858,7 @@ namespace ApiPolo.Controllers
|
||||
string ten = getClaimValueByToken(token, "tenant");
|
||||
string tecnico = getClaimValueByToken(token, "tccodice");
|
||||
string tenConf = getClaimValueByToken(token, "tenantConfigurazioni");
|
||||
|
||||
if (string.IsNullOrEmpty(ten))
|
||||
{
|
||||
ten = tenConf;
|
||||
@ -6815,6 +6823,31 @@ namespace ApiPolo.Controllers
|
||||
files.CopyTo(ftpStream);
|
||||
}
|
||||
}
|
||||
private static async Task FtpSendStorage(string ftpUrl, string ftp_usr, string ftp_pwd, IFormFile files, string filename)
|
||||
{
|
||||
//ftpUrl = "ftp://u460585.your-storagebox.de/MARRO/" + filename;
|
||||
//ftp_usr = "u460585";
|
||||
//ftp_pwd = "FygAh5sGcQbAt9aV";
|
||||
|
||||
ftpUrl = ftpUrl + filename;
|
||||
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpUrl);
|
||||
request.Method = WebRequestMethods.Ftp.UploadFile;
|
||||
request.Credentials = new NetworkCredential(ftp_usr, ftp_pwd);
|
||||
request.UseBinary = true;
|
||||
request.KeepAlive = false;
|
||||
request.ContentLength = files.Length;
|
||||
|
||||
using (Stream requestStream = request.GetRequestStream())
|
||||
using (Stream fileStream = files.OpenReadStream())
|
||||
{
|
||||
await fileStream.CopyToAsync(requestStream);
|
||||
}
|
||||
|
||||
using (FtpWebResponse response = (FtpWebResponse)await request.GetResponseAsync())
|
||||
{
|
||||
Console.WriteLine($"Upload completato, stato: {response.StatusDescription}");
|
||||
}
|
||||
}
|
||||
private static string CheckFtp(string url, string ftp_usr, string ftp_pwd)
|
||||
{
|
||||
string _esito = "OK";
|
||||
@ -6881,6 +6914,67 @@ namespace ApiPolo.Controllers
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary></summary>
|
||||
private async Task<Rapp_New> updPathFoto(string tenant, string seriale_rapportino, string pathFoto, int posizione, Rapp_New entitasViewModel)
|
||||
{
|
||||
using (var transaction = _VT_rapptable.Database.BeginTransaction())
|
||||
{
|
||||
switch (posizione)
|
||||
{
|
||||
case 1:
|
||||
entitasViewModel.rafoto1 = pathFoto;
|
||||
break;
|
||||
case 2:
|
||||
entitasViewModel.rafoto2 = pathFoto;
|
||||
break;
|
||||
case 3:
|
||||
entitasViewModel.rafoto3 = pathFoto;
|
||||
break;
|
||||
case 4:
|
||||
entitasViewModel.rafoto4 = pathFoto;
|
||||
break;
|
||||
case 5:
|
||||
entitasViewModel.rafoto5 = pathFoto;
|
||||
break;
|
||||
case 6:
|
||||
entitasViewModel.rafoto6 = pathFoto;
|
||||
break;
|
||||
case 7:
|
||||
entitasViewModel.rafoto7 = pathFoto;
|
||||
break;
|
||||
case 8:
|
||||
entitasViewModel.rafoto8 = pathFoto;
|
||||
break;
|
||||
case 9:
|
||||
entitasViewModel.rafoto9 = pathFoto;
|
||||
break;
|
||||
case 10:
|
||||
entitasViewModel.rafoto10 = pathFoto;
|
||||
break;
|
||||
}
|
||||
_VT_rapptable.Entry(entitasViewModel).State = EntityState.Modified;
|
||||
await _VT_rapptable.SaveChangesAsync();
|
||||
transaction.Commit();
|
||||
}
|
||||
return entitasViewModel;
|
||||
}
|
||||
private int TrovaPrimoCampoLibero(Rapp_New entity)
|
||||
{
|
||||
int pos = -1;
|
||||
|
||||
if (string.IsNullOrEmpty(entity.rafoto1)) return 1;
|
||||
if (string.IsNullOrEmpty(entity.rafoto2)) return 2;
|
||||
if (string.IsNullOrEmpty(entity.rafoto3)) return 3;
|
||||
if (string.IsNullOrEmpty(entity.rafoto4)) return 4;
|
||||
if (string.IsNullOrEmpty(entity.rafoto5)) return 5;
|
||||
if (string.IsNullOrEmpty(entity.rafoto6)) return 6;
|
||||
if (string.IsNullOrEmpty(entity.rafoto7)) return 7;
|
||||
if (string.IsNullOrEmpty(entity.rafoto8)) return 8;
|
||||
if (string.IsNullOrEmpty(entity.rafoto9)) return 9;
|
||||
if (string.IsNullOrEmpty(entity.rafoto10)) return 10;
|
||||
|
||||
return pos; // tutti pieni
|
||||
}
|
||||
|
||||
/// <summary>Upload return:ActionResult</summary>
|
||||
[HttpPost]
|
||||
@ -7173,6 +7267,83 @@ namespace ApiPolo.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Upload foto return:ActionResult</summary>
|
||||
[HttpPost]
|
||||
[Route("{serialeRapportino}/uploadFoto")]
|
||||
public async Task<IActionResult> UploadFoto(string serialeRapportino, IFormFile file, string token)
|
||||
{
|
||||
string ten = getClaimValueByToken(token, "tenant");
|
||||
string ten2 = getClaimValueByToken(token, "tenant2");
|
||||
string tenConf = getClaimValueByToken(token, "tenantConfigurazioni");
|
||||
string tecnico = getClaimValueByToken(token, "tccodice");
|
||||
string url = string.Empty;
|
||||
string usr = string.Empty;
|
||||
string pwd = string.Empty;
|
||||
string url_storage = string.Empty;
|
||||
string usr_storage = string.Empty;
|
||||
string pwd_storage = string.Empty;
|
||||
string ip = string.Empty;
|
||||
int? port = 0;
|
||||
string fileName = string.Empty;
|
||||
|
||||
if (file == null || file.Length == 0)
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "Error: file non valido");
|
||||
|
||||
try
|
||||
{
|
||||
if (ten.Equals(Clienti.VT))
|
||||
{
|
||||
_confLette = await readConf(ten2);
|
||||
}
|
||||
else
|
||||
{
|
||||
_confLette = await readConf(tenConf);
|
||||
}
|
||||
_rapp_new = _VT_rapptable.Rapps;
|
||||
Rapp_New entitasViewModel = _rapp_new.Where(p => p.seriale_rapportino.Equals(serialeRapportino)).FirstOrDefault();
|
||||
if (entitasViewModel == null)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "Errore: seriale non valido " + serialeRapportino);
|
||||
}
|
||||
|
||||
int posiz = TrovaPrimoCampoLibero(entitasViewModel);
|
||||
string strPosiz = Convert.ToString(posiz);
|
||||
|
||||
if (posiz < 1 || posiz > 10)
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "Raggiunto limite max numero foto");
|
||||
|
||||
long size = file.Length;
|
||||
string root = _confLette.root_stor != null ? _confLette.root_stor.Trim() : string.Empty;
|
||||
fileName = String.Format("{0}_{1}{2}", serialeRapportino, strPosiz, Path.GetExtension(file.FileName));
|
||||
//string relativePath = $"/uploads/{serialeRapportino}/{fileName}";
|
||||
|
||||
string absolutePath = root + fileName;
|
||||
url_storage = _confLette.ftp_url_stor != null ? _confLette.ftp_url_stor.Trim() : string.Empty;
|
||||
usr_storage = _confLette.ftp_usr_stor != null ? _confLette.ftp_usr_stor.Trim() : string.Empty;
|
||||
pwd_storage = _confLette.ftp_pwd_stor != null ? _confLette.ftp_pwd_stor.Trim() : string.Empty;
|
||||
|
||||
await FtpSendStorage(url_storage, usr_storage, pwd_storage, file, fileName);
|
||||
await updPathFoto(ten, serialeRapportino, absolutePath, posiz, entitasViewModel);
|
||||
|
||||
|
||||
return Ok(new { count = posiz, size });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
string errMsg = string.Empty;
|
||||
if (ex.Message != null)
|
||||
{
|
||||
sb.AppendLine(ex.Message);
|
||||
}
|
||||
if (ex.InnerException != null)
|
||||
{
|
||||
sb.AppendLine(ex.InnerException.Message);
|
||||
}
|
||||
errMsg = sb.ToString();
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "Error in uploadFoto: " + errMsg);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IMPIANTI COMPONENTI
|
||||
@ -12419,6 +12590,10 @@ namespace ApiPolo.Controllers
|
||||
//}
|
||||
|
||||
_chiamate = getChiamateByTenant(ten);
|
||||
var chiamata_new = _chiamate.Where(x => x.chserial!=null && x.chserial.Equals(t.chserial)).FirstOrDefault();
|
||||
c = fillChiamateOut(chiamata_new, ten);
|
||||
|
||||
|
||||
//switch (ten)
|
||||
//{
|
||||
// case Clienti.LW:
|
||||
|
||||
@ -212,5 +212,22 @@ namespace ApiPolo.Models
|
||||
|
||||
/// <summary>Status</summary>
|
||||
public string? err_status_code { get; set; }
|
||||
|
||||
|
||||
|
||||
/// <summary>url ftp per upload delle immagini nello STORAGE WEB</summary>
|
||||
public string? ftp_url_stor { get; set; }
|
||||
|
||||
/// <summary>utente ftp per upload delle immagini nello STORAGE WEB</summary>
|
||||
public string? ftp_usr_stor { get; set; }
|
||||
|
||||
/// <summary>password ftp per upload delle immagini nello STORAGE WEB</summary>
|
||||
public string? ftp_pwd_stor { get; set; }
|
||||
|
||||
/// <summary>abilita l'upload delle foto impianto</summary>
|
||||
public bool? abilita_foto { get; set; }
|
||||
|
||||
/// <summary>root (mappatura) dello STORAGE WEB</summary>
|
||||
public string? root_stor { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -219,5 +219,22 @@ namespace ApiPolo.Models
|
||||
/// <summary>stampa note intervento nel buono</summary>
|
||||
public bool? desc_interv_stampa { get; set; }
|
||||
|
||||
|
||||
|
||||
/// <summary>url ftp per upload delle immagini nello STORAGE WEB</summary>
|
||||
public string? ftp_url_stor { get; set; }
|
||||
|
||||
/// <summary>utente ftp per upload delle immagini nello STORAGE WEB</summary>
|
||||
public string? ftp_usr_stor { get; set; }
|
||||
|
||||
/// <summary>password ftp per upload delle immagini nello STORAGE WEB</summary>
|
||||
public string? ftp_pwd_stor { get; set; }
|
||||
|
||||
/// <summary>abilita l'upload delle foto impianto</summary>
|
||||
public bool? abilita_foto { get; set; }
|
||||
|
||||
/// <summary>root (mappatura) dello STORAGE WEB</summary>
|
||||
public string? root_stor { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,7 +145,7 @@ namespace ApiPolo
|
||||
//gen.SwaggerDoc("v1", new OpenApiInfo { Title = "POLO API WS2016", Version = "v3.3" });
|
||||
DateTime oggi = DateTime.Now;
|
||||
string dt = oggi.ToString();
|
||||
gen.SwaggerDoc("v1", new OpenApiInfo { Title = "API VIRTUAL TASK - v.app 1.30", Version = dt });
|
||||
gen.SwaggerDoc("v1", new OpenApiInfo { Title = "API VIRTUAL TASK - v.app 1.34", Version = dt });
|
||||
|
||||
var filePath = Path.Combine(System.AppContext.BaseDirectory, "ApiPolo.xml");
|
||||
gen.IncludeXmlComments(filePath);
|
||||
|
||||
@ -5,4 +5,8 @@ la chiamata appena inserita per poterla poi lavorare come una normale chiamata e
|
||||
|
||||
- aggiunta la gestione da Api della parte del buono che descrive l'impianto, al solito in formato html
|
||||
campo riferimento_impianto su Chiamate_out
|
||||
*************************************************************************************
|
||||
verione 1.34
|
||||
|
||||
- Upload foto
|
||||
*************************************************************************************
|
||||
@ -11,9 +11,11 @@
|
||||
//connessione non sicura: Encrypt=False
|
||||
|
||||
//"ApiStr": "Data Source=172.25.30.1;Initial Catalog=API_POLO;User Id=sa; Password=p0l01nf.;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False",
|
||||
"ApiStr": "Data Source=dbsql01.poloinformatico.it;Initial Catalog=API_POLO;User Id=apipolo; Password=38HdflydkDrXI4l;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False;Encrypt=False;TrustServerCertificate=True",
|
||||
"VIRTUAL_TASK": "Data Source=dbsql01.poloinformatico.it;Initial Catalog=VIRTUAL_TASK;User Id=apipolo; Password=38HdflydkDrXI4l;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False;Encrypt=False;TrustServerCertificate=True",
|
||||
/*"VIRTUAL_TASK": "Data Source=MARCO_PC\\SQL_2022;Initial Catalog=VIRTUAL_TASK;User Id=sa; Password=p0l01nf.;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False",*/
|
||||
//"ApiStr": "Data Source=dbsql01.poloinformatico.it;Initial Catalog=API_POLO;User Id=apipolo; Password=38HdflydkDrXI4l;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False;Encrypt=False;TrustServerCertificate=True",
|
||||
"ApiStr": "Data Source=MARCO_PC\\SQL_2022;Initial Catalog=API_POLO;User Id=sa; Password=p0l01nf.;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False;Encrypt=False;TrustServerCertificate=True",
|
||||
|
||||
//"VIRTUAL_TASK": "Data Source=dbsql01.poloinformatico.it;Initial Catalog=VIRTUAL_TASK;User Id=apipolo; Password=38HdflydkDrXI4l;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False;Encrypt=False;TrustServerCertificate=True"
|
||||
"VIRTUAL_TASK": "Data Source=MARCO_PC\\SQL_2022;Initial Catalog=VIRTUAL_TASK;User Id=sa; Password=p0l01nf.;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False",
|
||||
//"VIRTUAL_TASK": "Data Source=172.25.30.1;Initial Catalog=VIRTUAL_TASK;User Id=sa; Password=p0l01nf.;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
|
||||
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user