METODO PER CREAZIONE SERIALE IN ANAGRAFICA

This commit is contained in:
Marco Audiffredi 2023-10-13 18:20:36 +02:00
parent 8711248cf0
commit 0533a6678e
2 changed files with 46 additions and 1 deletions

View File

@ -1,5 +1,6 @@
using Humanizer;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Newtonsoft.Json;
using NuGet.Common;
using System.Diagnostics;
@ -19,6 +20,7 @@ namespace VirtualTask.Controllers
string tenant = string.Empty;
string errMes = string.Empty;
HttpClient client;
string _serchiam = "SER_ANAGRA";
public AnagController()
{
@ -104,7 +106,7 @@ namespace VirtualTask.Controllers
Uri baseAddress = new Uri(urlBase);
client = new HttpClient();
client.BaseAddress = baseAddress;
model.ancodice = getNewSeriale();
string data = JsonConvert.SerializeObject(model);
StringContent content = new StringContent(data, Encoding.UTF8, "application/json");
HttpResponseMessage response = client.PostAsync(baseAddress, content).Result;
@ -313,5 +315,34 @@ namespace VirtualTask.Controllers
string e = helper.GetStringValue("errMsg");
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier, ErrMsg = e });
}
private string getNewSeriale()
{
int p = -1;
string seriale = string.Empty;
SessionHelper helper = new SessionHelper(this);
token = helper.GetStringValue("tok");
apiUrl = helper.GetStringValue("apiUrl");
urlBase = apiUrl + "progressiviList";
urlBase = urlBase + "?token=" + token;
Uri baseAddress = new Uri(urlBase);
client = new HttpClient();
client.BaseAddress = baseAddress;
List<Progressivo> progressivi = new List<Progressivo>();
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
if (response.IsSuccessStatusCode)
{
string data = response.Content.ReadAsStringAsync().Result;
progressivi = JsonConvert.DeserializeObject<List<Progressivo>>(data);
var last= progressivi.Where(t=>t.tipo_prog.Equals(_serchiam)).First();
p = last.val_prog;
p++;
seriale=Convert.ToString(p);
seriale = seriale.PadLeft(10, '0');
}
//todo AGGIORNO IL VALORE DEL PROGRESSIVO
return seriale;
}
}
}

14
Models/Progressivo.cs Normal file
View File

@ -0,0 +1,14 @@
namespace VirtualTask.Models
{
public class Progressivo
{
/// <summary>Azienda</summary>
public string? azienda { get; set; }
/// <summary>stringa definisce il tipo di progressivo da gestire</summary>
public string? tipo_prog { get; set; }
/// <summary>valore progressivo</summary>
public int val_prog { get; set; }
}
}