diff --git a/ApiSoftway.csproj b/ApiSoftway.csproj new file mode 100644 index 0000000..59f6e4d --- /dev/null +++ b/ApiSoftway.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + diff --git a/ApiSoftway.sln b/ApiSoftway.sln new file mode 100644 index 0000000..a36d9fc --- /dev/null +++ b/ApiSoftway.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.6.33723.286 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApiSoftway", "ApiSoftway.csproj", "{56487A04-3FAD-4F88-B3EE-DF1C6CA8D246}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {56487A04-3FAD-4F88-B3EE-DF1C6CA8D246}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {56487A04-3FAD-4F88-B3EE-DF1C6CA8D246}.Debug|Any CPU.Build.0 = Debug|Any CPU + {56487A04-3FAD-4F88-B3EE-DF1C6CA8D246}.Release|Any CPU.ActiveCfg = Release|Any CPU + {56487A04-3FAD-4F88-B3EE-DF1C6CA8D246}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {8410D81F-DE3A-4944-A62C-0CBF17FDD6F9} + EndGlobalSection +EndGlobal diff --git a/Controllers/GiriController.cs b/Controllers/GiriController.cs new file mode 100644 index 0000000..9dac255 --- /dev/null +++ b/Controllers/GiriController.cs @@ -0,0 +1,329 @@ +using ApiSoftway.Models; +using ApiSoftway.Models.Gesa_DbContext; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using Microsoft.IdentityModel.Tokens; +using System.Diagnostics; +using System.IdentityModel.Tokens.Jwt; +using System.Security.Claims; +using System.Text; + +namespace ApiSoftway.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class GiriController : ControllerBase + { + private readonly ILogger _logger; + private readonly GESA_GIRI_DbContext _giri_context; + private readonly GESA_DESTINAZIONI_DbContext _destinazioni_context; + private readonly GESA_CONSEGNE_DbContext _consegne_context; + private readonly IConfiguration? _configuration; + private DbSet? _giri; + private DbSet? _destinazioni; + private DbSet? _consegne; + public GiriController(ILogger logger, IConfiguration? configuration, GESA_GIRI_DbContext giri_context, GESA_DESTINAZIONI_DbContext destinazioni_context + , GESA_CONSEGNE_DbContext consegne_context) + { + _logger = logger; + _configuration = configuration; + _giri_context = giri_context; + _destinazioni_context = destinazioni_context; + _consegne_context = consegne_context; + } + + //[HttpGet("listaGiri")] + //public async Task>> listaGiri(string token) + //{ + + // List lst = new List(); + // string usr = getClaimValueByToken(token, "codice"); + // _giri = _giri_context.Giri; + // var r= await _giri.Where(t => t.Brautist != null && t.Brautist.Equals(usr)).OrderByDescending(t=>t.Brdatcar).Take(1).ToListAsync(); + // foreach(Giri giri in r) + // { + // Giri_out o=new Giri_out(); + // o.Autista = giri.Autista; + // o.Brdatcar = giri.Brdatcar; + // o.Brautist = giri.Brautist; + // o.num_dest=giri.num_dest; + // o.ItemList = formattaGiro(giri); + // lst.Add(o); + // } + // return lst; + //} + //[HttpGet("listaDestinazioni")] + //public async Task>> listaDestinazioni(string token, DateTime data) + //{ + + // List lst = new List(); + // string usr = getClaimValueByToken(token, "codice"); + // _destinazioni = _destinazioni_context.Destinazioni; + // var r = await _destinazioni.Where(t => t.CodAutista != null && t.CodAutista.Equals(usr)&& t.DataCarico != null && t.DataCarico == data).OrderByDescending(t => t.DataCarico).ToListAsync(); + // foreach(Destinazioni d in r) + // { + // Destinazioni_out o = new Destinazioni_out(); + // o.Autista = d.Autista; + // o.CodAutista = d.CodAutista; + // o.DescAutomezzo = d.DescAutomezzo; + // o.CodAutomezzo=d.CodAutomezzo; + // o.DataCarico = d.DataCarico; + // o.Brserial=d.Brserial; + // o.Brmerce=d.Brmerce; + // o.Brnote=d.Brnote; + // o.Cproword=d.Cproword; + // o.IndirizzoSede=d.IndirizzoSede; + // o.Sede=d.Sede; + // o.ItemList = formattaDestinazione(d); + // lst.Add(o); + // } + // return lst; + //} + + [HttpGet("listaDestinazioni")] + public async Task>> listaDestinazioni2(string token) + { + //step 1: ricavo la data a partire dal login + string usr = getClaimValueByToken(token, "codice"); + _giri = _giri_context.Giri; + var g = await _giri.Where(t => t.Brautist != null && t.Brautist.Equals(usr)).OrderByDescending(t => t.Brdatcar).Take(1).ToListAsync(); + DateTime? data = g.First().Brdatcar; + + + List lst = new List(); + _destinazioni = _destinazioni_context.Destinazioni; + var r = await _destinazioni.Where(t => t.CodAutista != null && t.CodAutista.Equals(usr) && t.DataCarico != null && t.DataCarico == data).OrderByDescending(t => t.DataCarico).ToListAsync(); + foreach (Destinazioni d in r) + { + Destinazioni_out o = new Destinazioni_out(); + o.Autista = d.Autista; + o.CodAutista = d.CodAutista; + o.DescAutomezzo = d.DescAutomezzo; + o.CodAutomezzo = d.CodAutomezzo; + o.DataCarico = d.DataCarico; + o.Brserial = d.Brserial; + o.Brmerce = d.Brmerce; + o.Brnote = d.Brnote; + o.Cproword = d.Cproword; + o.IndirizzoSede = d.IndirizzoSede; + o.Sede = d.Sede; + o.CodCommittente = d.CodCommittente; + o.Committente = d.Committente; + o.CodSede = d.CodSede; + o.ItemList = formattaDestinazione(d); + if(!string.IsNullOrEmpty(d.consFattaSerial)) + { + ConsegnaFatta cf=new ConsegnaFatta(); + cf.consFattaSerial= d.consFattaSerial; + cf.consFattaRow= d.consFattaRow; + cf.consFattaAut= d.consFattaAut; + cf.consFattaBanSca = d.consFattaBanSca; + cf.consFattaBanCar= d.consFattaBanCar; + string nota = !string.IsNullOrEmpty(d.consFattaNotBan) ? d.consFattaNotBan.Trim() : string.Empty; + cf.consFattaNotBan= nota; + cf.consFattaImpor=d.consFattaImpor; + cf.consFattaMezzo= d.consFattaMezzo; + string nota2 = !string.IsNullOrEmpty(d.consFattaNotImp) ? d.consFattaNotImp.Trim() : string.Empty; + cf.consFattaNotImp=nota2; + + o.ConsFatta=cf; + } + + lst.Add(o); + } + return lst; + } + + /// Salva i dati della consegna + [HttpPost] + [Route("destinazione/salva")] + public async Task> timbrature_salva([FromBody] Consegna model, string token) + { + Consegna_out tOut = new Consegna_out(); + string usr = getClaimValueByToken(token, "codice"); + try + { + + //string tecnico = getClaimValueByToken(token, "tccodice"); + if (await checkConsegnaPresente(token, model) == 0) + { + Consegna t = fillConsegna(model, token); + using (var transaction = _consegne_context.Database.BeginTransaction()) + { + await _consegne_context.Cons.AddAsync(t); + await _consegne_context.SaveChangesAsync(); + transaction.Commit(); + } + + tOut = fillConsegna_out(model, token); + tOut.err_status_code = "200"; + return StatusCode(StatusCodes.Status200OK, tOut); + } + else + { + return StatusCode(StatusCodes.Status500InternalServerError, "timbratura presente."); + } + + //return tOut; + } + catch (Exception ex) + { + string errmsg = ex.InnerException != null ? ex.InnerException.Message : ex.Message; + tOut.err_title = ex.Message; + tOut.err_detail = errmsg; + tOut.err_status_code = "500"; + return StatusCode(StatusCodes.Status500InternalServerError, tOut); + } + } + + private async Task checkConsegnaPresente(string token, Consegna model) + { + int trovati = 0; + _consegne = _consegne_context.Cons; + var ti = await _consegne.Where(t => t.Serial.Equals(model.Serial) && t.Cprownum == model.Cprownum ).ToListAsync(); + if (ti.Any()) + { + trovati = ti.Count(); + } + + return trovati; + } + private string getClaimValueByToken(string token, string claimName) + { + string t = string.Empty; + + var handler = new JwtSecurityTokenHandler(); + var jwtSecurityToken = handler.ReadJwtToken(token); + if (jwtSecurityToken != null) + { + var id = jwtSecurityToken.Claims.First(claim => claim.Type == claimName).Value; + t = id; + } + return t; + } + private string formattaGiro(Giri g) + { + string item = string.Empty; + if (g != null) + { + StringBuilder sb = new StringBuilder(); + var dateString1 = g.Brdatcar.Value.ToString("dd-MM-yyyy"); + sb.AppendLine("Giro del "+dateString1); + sb.AppendLine("Assegnato a "+g.Autista); + sb.AppendLine("Numero consegne " + g.num_dest.ToString()); + item=sb.ToString(); + sb = null; + } + + return item; + } + private string formattaDestinazione(Destinazioni d) + { + string item = string.Empty; + if (d != null) + { + StringBuilder sb = new StringBuilder(); + //var dateString1 = d.DataCarico.Value.ToString("dd-MM-yyyy"); + string comm = !string.IsNullOrEmpty(d.Committente) ? d.Committente.Trim() : string.Empty; + + sb.Append("Committente " + comm); + sb.Append("
"); + string sed = !string.IsNullOrEmpty(d.Sede) ? d.Sede.Trim() : string.Empty; + sb.Append("Sede Consegna " + sed); + sb.Append("
"); + string ind = !string.IsNullOrEmpty(d.IndirizzoSede) ? d.IndirizzoSede.Trim() : string.Empty; + sb.Append("Indirizzo " + ind); + sb.Append("
"); + item = sb.ToString(); + sb = null; + } + + return item; + } + private Consegna fillConsegna(Consegna i, string token) + { + Consegna r = new Consegna(); + + string usr = getClaimValueByToken(token, "codice"); + + r.Piautist = usr; + r.Cprownum = i.Cprownum; + r.Ccddd = i.Ccddd; + r.cpccchk = i.cpccchk; + r.Ccda = i.Ccda; + r.Dcda = i.Dcda; + r.Pinotban = i.Pinotban; + r.Ccadd = i.Ccadd; + r.Ccda = i.Ccda; + r.Ccddd=i.Ccddd; + r.Datdoc= i.Datdoc; + r.Dcda=i.Dcda; + r.Descb=i.Descb; + r.Nbanc = i.Nbanc; + r.Ndoc = i.Ndoc; + r.Pibansca = i.Pibansca; + r.Pinotban = i.Pinotban; + r.Pinotimp = i.Pinotimp; + r.Tipob1 = i.Tipob1; + r.Tipob2 = i.Tipob2; + r.Tipob =i.Tipob; + r.Sdoc = i.Sdoc; + r.Serial = i.Serial; + r.Tcda=i.Tcda; + r.Tca = i.Tca; + r.Cca = i.Cca; + r.Dca = i.Dca; + r.Piconseg = i.Piconseg; + r.Pimezzo = i.Pimezzo; + r.Piimport= i.Piimport; + + + + return r; + } + private Consegna_out fillConsegna_out(Consegna i, string token) + { + Consegna_out r = new Consegna_out(); + + string usr = getClaimValueByToken(token, "codice"); + + r.Piautist = usr; + r.Cprownum = i.Cprownum; + r.Ccddd = i.Ccddd; + r.cpccchk = i.cpccchk; + r.Ccda = i.Ccda; + r.Dcda = i.Dcda; + r.Pinotban = i.Pinotban; + r.Ccadd = i.Ccadd; + r.Ccda = i.Ccda; + r.Ccddd = i.Ccddd; + r.Datdoc = i.Datdoc; + r.Dcda = i.Dcda; + r.Descb = i.Descb; + r.Nbanc = i.Nbanc; + r.Ndoc = i.Ndoc; + r.Pibansca = i.Pibansca; + r.Pinotban = i.Pinotban; + r.Pinotimp = i.Pinotimp; + r.Tipob1 = i.Tipob1; + r.Tipob2 = i.Tipob2; + r.Tipob = i.Tipob; + r.Sdoc = i.Sdoc; + r.Serial = i.Serial; + r.Tcda = i.Tcda; + r.Tca = i.Tca; + r.Cca = i.Cca; + r.Dca = i.Dca; + r.Piconseg = i.Piconseg; + r.Pimezzo = i.Pimezzo; + r.Piimport = i.Piimport; + + + + return r; + } + } + +} diff --git a/Controllers/LoginController.cs b/Controllers/LoginController.cs new file mode 100644 index 0000000..905d02c --- /dev/null +++ b/Controllers/LoginController.cs @@ -0,0 +1,93 @@ +using ApiSoftway.Models; +using ApiSoftway.Models.Gesa_DbContext; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.IdentityModel.Tokens; +using System.IdentityModel.Tokens.Jwt; +using System.Security.Claims; +using System.Text; + +namespace ApiSoftway.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class LoginController : ControllerBase + { + private readonly ILogger _logger; + private readonly GESA_PERSONALE_DbContext _personale_context; + private DbSet? _personale; + private readonly IConfiguration? _configuration; + public LoginController(ILogger logger, GESA_PERSONALE_DbContext personale_context, IConfiguration? configuration) + { + _logger = logger; + _personale_context = personale_context; + _configuration = configuration; + } + + /// Login iniziale return:ActionResult + [HttpPost("loginPersonale")] + public async Task> loginPersonale([FromBody] Login model) + { + Login_out o = new Login_out(); + try + { + if (string.IsNullOrEmpty(model.Username) || string.IsNullOrEmpty(model.Password)) + { + o.err_detail = "Username e Password non possono essere vuoti."; + o.err_title = "Username e Password non possono essere vuoti."; + o.err_status_code = "200"; + return StatusCode(StatusCodes.Status200OK, o); + } + else + { + _personale = _personale_context.Personale; + var pers=await _personale.Where(t=> t.Tcuser!=null && t.Tcuser.Equals(model.Username)&& t.Tcpwd!=null && t.Tcpwd.Equals(model.Password)).Take(1).ToListAsync(); + + if (pers == null || (pers != null && pers.Count == 0)) + { + o.err_detail = "Username o Password non trovati."; + o.err_title = "Username o Password non trovati."; + o.err_status_code = "404"; + return StatusCode(StatusCodes.Status404NotFound, o); + } + else + { + var authClaims = new List + { + //new Claim(ClaimTypes.Name, model.Username), + new Claim(ClaimTypes.Name,pers.First().Tcuser), + new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()), + new Claim("user", pers.First().Tcuser), + new Claim("codice", pers.First().Catcodice), + new Claim("nome", pers.First().Catnome), + }; + var authSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["JWT:Secret"])); + var token = new JwtSecurityToken( + issuer: _configuration["JWT:ValidIssuer"], + audience: _configuration["JWT:ValidAudience"], + expires: DateTime.Now.AddMonths(3), + claims: authClaims, + signingCredentials: new SigningCredentials(authSigningKey, SecurityAlgorithms.HmacSha256) + ); + string tok = new JwtSecurityTokenHandler().WriteToken(token); + o.Tok = tok; + o.Tccodice = pers.First().Catcodice; + o.Tcruolo = pers.First().Tcruolo; + o.Tcdescri = pers.First().Catnome; + return StatusCode(StatusCodes.Status200OK, o); + } + } + } + catch (Exception ex) + { + string err = "Errore: " + ex.Message; + o.err_detail = err; + o.err_title = err; + o.err_status_code = "200"; + return StatusCode(StatusCodes.Status500InternalServerError, o); + } + + } + } +} diff --git a/Controllers/TokenController.cs b/Controllers/TokenController.cs new file mode 100644 index 0000000..5afec54 --- /dev/null +++ b/Controllers/TokenController.cs @@ -0,0 +1,121 @@ +using ApiSoftway.Models; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using System.IdentityModel.Tokens.Jwt; + +namespace ApiSoftway.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class TokenController : ControllerBase + { + private readonly ILogger _logger; + private readonly IConfiguration? _configuration; + private readonly TOKEN_DbContext _token_context; + public TokenController(ILogger logger, IConfiguration? configuration, TOKEN_DbContext token_context) + { + _logger = logger; + _configuration = configuration; + _token_context = token_context; + } + private Token fillTokenByInput(string tokenDevice, string tokenLogin) + { + Token r = new Token(); + + string ten = "GESA"; + string tecnico = getClaimValueByToken(tokenLogin, "codice"); + + r.tenant = ten; + r.usr = tecnico; + r.token = tokenDevice; + r.ts = DateTime.Now; + return r; + } + private string getClaimValueByToken(string token, string claimName) + { + string t = string.Empty; + + var handler = new JwtSecurityTokenHandler(); + var jwtSecurityToken = handler.ReadJwtToken(token); + if (jwtSecurityToken != null) + { + var id = jwtSecurityToken.Claims.First(claim => claim.Type == claimName).Value; + t = id; + } + return t; + } + [HttpPost] + [Route("add")] + public async Task> addToken(string tokenDevice, string token) + { + Token_out t = new Token_out(); + bool da_inserire = false; + + try + { + List co = new List(); + if (_token_context is not null && _token_context.tok is not null) + { + co = await _token_context.tok.Where(c => c.token.Equals(tokenDevice)).ToListAsync(); + } + Token inp = fillTokenByInput(tokenDevice, token); + + if (co.Count == 0) + { + da_inserire = true; + } + else + { + //il token c'è. controllo che sia associato all'utente corretto + //string ten = getClaimValueByToken(token, "tenant"); + string ten = "GESA"; + string tecnico = getClaimValueByToken(token, "tccodice"); + + bool token_corretto_presente = false; + foreach (Token tt in co) + { + if (tt.usr is not null && tt.usr.Equals(tecnico) && tt.tenant is not null && tt.tenant.Equals(ten)) + { + token_corretto_presente = true; + } + else + { + using (var transaction = _token_context.Database.BeginTransaction()) + { + Token entitasViewModel = _token_context.tok.Where(p => p.Id == tt.Id).FirstOrDefault(); + _token_context.Entry(entitasViewModel).State = EntityState.Deleted; + await _token_context.SaveChangesAsync(); + transaction.Commit(); + } + } + } + if (!token_corretto_presente) + da_inserire = true; + } + if (da_inserire) + { + using (var transaction = _token_context.Database.BeginTransaction()) + { + await _token_context.tok.AddAsync(inp); + await _token_context.SaveChangesAsync(); + transaction.Commit(); + } + t.err_status_code = "200"; + } + return StatusCode(StatusCodes.Status200OK, t); + } + catch (Exception ex) + { + string errmsg = ex.InnerException != null ? ex.InnerException.Message : ex.Message; + t.err_title = ex.Message; + t.err_detail = errmsg; + t.err_status_code = "500"; + return StatusCode(StatusCodes.Status500InternalServerError, t); + } + + } + + + } +} diff --git a/Models/Consegna.cs b/Models/Consegna.cs new file mode 100644 index 0000000..6b95a63 --- /dev/null +++ b/Models/Consegna.cs @@ -0,0 +1,40 @@ +using System.ComponentModel.DataAnnotations; + +namespace ApiSoftway.Models +{ + public class Consegna + { + [Key] + public string? Serial { get; set; } + + [Key] + public int? Cprownum { get; set; } + public string? Tcda { get; set; } + public string? Ccda { get; set; } + public string? Dcda { get; set; } + public string? Tca { get; set; } + public string? Cca { get; set; } + public string? Dca { get; set; } + public string? Tipob { get; set; } + public int? Nbanc { get; set; } + public string? Descb { get; set; } + public string? Tipob1 { get; set; } + public string? Tipob2 { get; set; } + public string? Ccddd { get; set; } + public string? Ccadd { get; set; } + public string? Ndoc { get; set; } + public string? Sdoc { get; set; } + public DateTime? Datdoc { get; set; } + public string? cpccchk { get; set; } + public string? Piconseg { get; set; } + public string? Pimezzo { get; set; } + public string? Piautist { get; set; } + public int? Pibansca { get; set; } + + [System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(18, 5)")] + public decimal? Piimport { get; set; } + public string? Pinotimp { get; set; } + public string? Pinotban { get; set; } + + } +} diff --git a/Models/Consegna_out.cs b/Models/Consegna_out.cs new file mode 100644 index 0000000..f677d6b --- /dev/null +++ b/Models/Consegna_out.cs @@ -0,0 +1,44 @@ + + +namespace ApiSoftway.Models +{ + public class Consegna_out + { + public string? Serial { get; set; } + public int? Cprownum { get; set; } + public string? Tcda { get; set; } + public string? Ccda { get; set; } + public string? Dcda { get; set; } + public string? Tca { get; set; } + public string? Cca { get; set; } + public string? Dca { get; set; } + public string? Tipob { get; set; } + public int? Nbanc { get; set; } + public string? Descb { get; set; } + public string? Tipob1 { get; set; } + public string? Tipob2 { get; set; } + public string? Ccddd { get; set; } + public string? Ccadd { get; set; } + public string? Ndoc { get; set; } + public string? Sdoc { get; set; } + public DateTime? Datdoc { get; set; } + public string? cpccchk { get; set; } + public string? Piconseg { get; set; } + public string? Pimezzo { get; set; } + public string? Piautist { get; set; } + public int? Pibansca { get; set; } + + [System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(18, 5)")] + public decimal? Piimport { get; set; } + public string? Pinotimp { get; set; } + public string? Pinotban { get; set; } + + + /// errore titolo + public string? err_title { get; set; } + /// errore dettaglio + public string? err_detail { get; set; } + /// errore status code (200, 500) + public string? err_status_code { get; set; } + } +} diff --git a/Models/Destinazioni.cs b/Models/Destinazioni.cs new file mode 100644 index 0000000..43ed533 --- /dev/null +++ b/Models/Destinazioni.cs @@ -0,0 +1,36 @@ +using Microsoft.EntityFrameworkCore; + +namespace ApiSoftway.Models +{ + [Keyless] + public class Destinazioni + { + public string? CodAutomezzo { get; set; } + public string? DescAutomezzo { get; set; } + public string? Brserial { get; set; } + public DateTime? DataCarico { get; set; } + public string? CodCommittente { get; set; } + public string? Committente { get; set; } + public string? CodAutista { get; set; } + public string? Autista { get; set; } + public string? CodSede { get; set; } + public string? Sede { get; set; } + public string? IndirizzoSede { get; set; } + public int? Cproword { get; set; } + public string? Brmerce { get; set; } + public string? Brnote { get; set; } + + public string? consFattaSerial { get; set; } + public int? consFattaRow { get; set; } + public int? consFattaBanCar { get; set; } + public int? consFattaBanSca { get; set; } + public string? consFattaMezzo { get; set; } + public string? consFattaAut { get; set; } + + [System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(18, 5)")] + public decimal? consFattaImpor { get; set; } + public string? consFattaNotImp { get; set; } + public string? consFattaNotBan { get; set; } + + } +} diff --git a/Models/Destinazioni_out.cs b/Models/Destinazioni_out.cs new file mode 100644 index 0000000..5d9d216 --- /dev/null +++ b/Models/Destinazioni_out.cs @@ -0,0 +1,39 @@ +using Microsoft.EntityFrameworkCore; + +namespace ApiSoftway.Models +{ + [Keyless] + public class Destinazioni_out + { + public string? CodAutomezzo { get; set; } + public string? DescAutomezzo { get; set; } + public string? Brserial { get; set; } + public DateTime? DataCarico { get; set; } + public string? CodCommittente { get; set; } + public string? Committente { get; set; } + public string? CodAutista { get; set; } + public string? Autista { get; set; } + public string? CodSede { get; set; } + public string? Sede { get; set; } + public string? IndirizzoSede { get; set; } + public int? Cproword { get; set; } + public string? Brmerce { get; set; } + public string? Brnote { get; set; } + public string? ItemList { get; set; } + public ConsegnaFatta? ConsFatta { get; set; } + } + public class ConsegnaFatta + { + public string? consFattaSerial { get; set; } + public int? consFattaRow { get; set; } + public int? consFattaBanCar { get; set; } + public int? consFattaBanSca { get; set; } + public string? consFattaMezzo { get; set; } + public string? consFattaAut { get; set; } + + [System.ComponentModel.DataAnnotations.Schema.Column(TypeName = "decimal(18, 5)")] + public decimal? consFattaImpor { get; set; } + public string? consFattaNotImp { get; set; } + public string? consFattaNotBan { get; set; } + } +} diff --git a/Models/Gesa_DbContext/GESA_CONSEGNE_DbContext.cs b/Models/Gesa_DbContext/GESA_CONSEGNE_DbContext.cs new file mode 100644 index 0000000..54106f1 --- /dev/null +++ b/Models/Gesa_DbContext/GESA_CONSEGNE_DbContext.cs @@ -0,0 +1,25 @@ +using Microsoft.EntityFrameworkCore; + +namespace ApiSoftway.Models.Gesa_DbContext +{ + public class GESA_CONSEGNE_DbContext : DbContext + { + /// + public DbSet? Cons { get; set; } + + /// + public GESA_CONSEGNE_DbContext(DbContextOptions options) : base(options) + { + } + + /// + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().ToTable("GESASMOVIB"); + modelBuilder.Entity().HasKey(table => new { + table.Serial, + table.Cprownum + }); + } + } +} diff --git a/Models/Gesa_DbContext/GESA_DESTINAZIONI_DbContext.cs b/Models/Gesa_DbContext/GESA_DESTINAZIONI_DbContext.cs new file mode 100644 index 0000000..4120a77 --- /dev/null +++ b/Models/Gesa_DbContext/GESA_DESTINAZIONI_DbContext.cs @@ -0,0 +1,17 @@ +using Microsoft.EntityFrameworkCore; + +namespace ApiSoftway.Models.Gesa_DbContext +{ + public class GESA_DESTINAZIONI_DbContext : DbContext + { + public DbSet? Destinazioni { get; set; } + public GESA_DESTINAZIONI_DbContext(DbContextOptions options) : base(options) + { + } + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().ToView("API_DESTINAZIONI"); + } + } + +} diff --git a/Models/Gesa_DbContext/GESA_GIRI_DbContext.cs b/Models/Gesa_DbContext/GESA_GIRI_DbContext.cs new file mode 100644 index 0000000..f156397 --- /dev/null +++ b/Models/Gesa_DbContext/GESA_GIRI_DbContext.cs @@ -0,0 +1,16 @@ +using Microsoft.EntityFrameworkCore; + +namespace ApiSoftway.Models.Gesa_DbContext +{ + public class GESA_GIRI_DbContext : DbContext + { + public DbSet? Giri { get; set; } + public GESA_GIRI_DbContext(DbContextOptions options) : base(options) + { + } + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().ToView("API_GIRI"); + } + } +} diff --git a/Models/Gesa_DbContext/GESA_PERSONALE_DbContext.cs b/Models/Gesa_DbContext/GESA_PERSONALE_DbContext.cs new file mode 100644 index 0000000..73ec6a2 --- /dev/null +++ b/Models/Gesa_DbContext/GESA_PERSONALE_DbContext.cs @@ -0,0 +1,16 @@ +using Microsoft.EntityFrameworkCore; + +namespace ApiSoftway.Models.Gesa_DbContext +{ + public class GESA_PERSONALE_DbContext : DbContext + { + public DbSet? Personale { get; set; } + public GESA_PERSONALE_DbContext(DbContextOptions options) : base(options) + { + } + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().ToView("API_PERSONALE"); + } + } +} diff --git a/Models/Giri.cs b/Models/Giri.cs new file mode 100644 index 0000000..68e1911 --- /dev/null +++ b/Models/Giri.cs @@ -0,0 +1,14 @@ +using Microsoft.EntityFrameworkCore; + +namespace ApiSoftway.Models +{ + [Keyless] + public class Giri + { + public DateTime? Brdatcar { get; set; } + public string? Brautist { get; set; } + public string? Autista { get; set; } + public int? num_dest { get; set; } + + } +} diff --git a/Models/Giri_out.cs b/Models/Giri_out.cs new file mode 100644 index 0000000..c66d1c6 --- /dev/null +++ b/Models/Giri_out.cs @@ -0,0 +1,12 @@ +namespace ApiSoftway.Models +{ + public class Giri_out + { + public DateTime? Brdatcar { get; set; } + public string? Brautist { get; set; } + public string? Autista { get; set; } + public int? num_dest { get; set; } + + public string? ItemList { get; set; } + } +} diff --git a/Models/Login.cs b/Models/Login.cs new file mode 100644 index 0000000..e3d7f8f --- /dev/null +++ b/Models/Login.cs @@ -0,0 +1,12 @@ +namespace ApiSoftway.Models +{ + public class Login + { + /// Username + public string? Username { get; set; } + + /// Password + public string? Password { get; set; } + + } +} diff --git a/Models/Login_out.cs b/Models/Login_out.cs new file mode 100644 index 0000000..964b839 --- /dev/null +++ b/Models/Login_out.cs @@ -0,0 +1,26 @@ +namespace ApiSoftway.Models +{ + public class Login_out + { + /// token + public string? Tok { get; set; } + + /// token + public string? Tccodice { get; set; } + + /// token + public string? Tcdescri { get; set; } + + /// ruolo + public string? Tcruolo { get; set; } + + /// Error Message + public string? err_title { get; set; } + + /// Error Message detail + public string? err_detail { get; set; } + + /// Status + public string? err_status_code { get; set; } + } +} diff --git a/Models/Personale.cs b/Models/Personale.cs new file mode 100644 index 0000000..4952099 --- /dev/null +++ b/Models/Personale.cs @@ -0,0 +1,17 @@ +using Microsoft.EntityFrameworkCore; + +namespace ApiSoftway.Models +{ + [Keyless] + public class Personale + { + public string? Catcodice { get; set; } = null; + public string? Catnome { get; set; } = null; + public string? Cattelefono { get; set; } = null; + public string? Catcellulare { get; set; } = null; + public string? Tcuser { get; set; } = null; + public string? Tcpwd { get; set; } = null; + public string? Tcruolo { get; set; } = null; + + } +} diff --git a/Models/TOKEN_DbContext.cs b/Models/TOKEN_DbContext.cs new file mode 100644 index 0000000..7e53e85 --- /dev/null +++ b/Models/TOKEN_DbContext.cs @@ -0,0 +1,20 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.IdentityModel.Tokens; + +namespace ApiSoftway.Models +{ + public class TOKEN_DbContext : DbContext + { + public DbSet? tok { get; set; } + + /// ConfigurazioniDbContext + public TOKEN_DbContext(DbContextOptions options) : base(options) + { + } + /// OnModelCreating + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().ToTable("Token"); + } + } +} diff --git a/Models/Token.cs b/Models/Token.cs new file mode 100644 index 0000000..317273e --- /dev/null +++ b/Models/Token.cs @@ -0,0 +1,25 @@ +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; + +namespace ApiSoftway.Models +{ + public class Token + { + /// id + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + [Key] + public int Id { get; set; } + + /// tenant azienda + public string? tenant { get; set; } + + /// utente login + public string? usr { get; set; } + + /// token device + public string? token { get; set; } + + /// timestamp inserimento + public DateTime? ts { get; set; } + } +} diff --git a/Models/Token_out.cs b/Models/Token_out.cs new file mode 100644 index 0000000..ceed60e --- /dev/null +++ b/Models/Token_out.cs @@ -0,0 +1,29 @@ +namespace ApiSoftway.Models +{ + public class Token_out + { + /// tenant azienda + public string? tenant { get; set; } + + /// utente login + public string? usr { get; set; } + + /// token device + public string? token { get; set; } + + /// timestamp inserimento + public DateTime? ts { get; set; } + + /// Error Message + public string? err_title { get; set; } + + /// Error Message detail + public string? err_detail { get; set; } + + /// Status + public string? err_status_code { get; set; } + + /// response + public string? response { get; set; } + } +} diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..8cc2218 --- /dev/null +++ b/Program.cs @@ -0,0 +1,53 @@ +using ApiSoftway.Models.Gesa_DbContext; +using ApiSoftway.Models; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; + +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddControllers(); +const int commandTimeoutInSeconds = 300; + +#region Istaze Dbcontext +builder.Services.AddDbContext(options => options.UseSqlServer(builder.Configuration.GetConnectionString("ApiStr") + , options => { options.CommandTimeout(commandTimeoutInSeconds); } + )); + +builder.Services.AddDbContext(options => options.UseSqlServer(builder.Configuration.GetConnectionString("GESA") + , options => { options.CommandTimeout(commandTimeoutInSeconds); } + )); +builder.Services.AddDbContext(options => options.UseSqlServer(builder.Configuration.GetConnectionString("GESA") + , options => { options.CommandTimeout(commandTimeoutInSeconds); } + )); +builder.Services.AddDbContext(options => options.UseSqlServer(builder.Configuration.GetConnectionString("GESA") + , options => { options.CommandTimeout(commandTimeoutInSeconds); } + )); +builder.Services.AddDbContext(options => options.UseSqlServer(builder.Configuration.GetConnectionString("GESA") + , options => { options.CommandTimeout(commandTimeoutInSeconds); } + )); +#endregion + + +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment() || app.Environment.IsProduction()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +//app.Run(); +app.Run("http://localhost:6000"); diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json new file mode 100644 index 0000000..1ce0d55 --- /dev/null +++ b/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:58993", + "sslPort": 44389 + } + }, + "profiles": { + "ApiSoftway": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7126;http://localhost:5127", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/appsettings.Development.json b/appsettings.Development.json new file mode 100644 index 0000000..183691e --- /dev/null +++ b/appsettings.Development.json @@ -0,0 +1,20 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } + //, + //"AllowedHosts": "*", + //"Kestrel": { + // "Endpoints": { + // "Http": { + // "Url": "http://localhost:5400" + // }, + // "Https": { + // "Url": "https://localhost:5401" + // } + // } + //} +} diff --git a/appsettings.json b/appsettings.json new file mode 100644 index 0000000..31f88b6 --- /dev/null +++ b/appsettings.json @@ -0,0 +1,19 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*", + "ConnectionStrings": { + + "GESA": "Data Source=10.0.0.10;Initial Catalog=AHRGESA;User Id=sa; Password=p0l01nf.;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", + "ApiStr": "Data Source=10.0.0.10;Initial Catalog=API_POLO;User Id=sa; Password=p0l01nf.;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False" + }, + "JWT": { + "ValidAudience": "http://localhost:4200", + "ValidIssuer": "http://localhost:61955", + "Secret": "ByYM000OLlMQG6VVVp1OH7Xzyr7gHuw1qvUC5dcGt3SNM" + } +}