From 4bc8b1597ff8258278e9c3d5798b8214ac912948 Mon Sep 17 00:00:00 2001 From: michele Date: Mon, 5 Aug 2024 17:29:17 +0200 Subject: [PATCH] Michele: aggiunto model SedeConsegna + dbcontext + controller e metodi per ricerca committente e sede committente --- Controllers/ClientiController.cs | 43 ++++++++++++------- .../GESA_SEDECONSEGNA_DbContext.cs | 24 +++++++++++ Models/SedeConsegna.cs | 19 ++++++++ Program.cs | 7 ++- 4 files changed, 76 insertions(+), 17 deletions(-) create mode 100644 Models/Gesa_DbContext/GESA_SEDECONSEGNA_DbContext.cs create mode 100644 Models/SedeConsegna.cs diff --git a/Controllers/ClientiController.cs b/Controllers/ClientiController.cs index 4ddc998..21591f1 100644 --- a/Controllers/ClientiController.cs +++ b/Controllers/ClientiController.cs @@ -11,35 +11,48 @@ namespace ApiSoftway.Controllers public class ClientiController : ControllerBase { private readonly GESA_CLIENTI_DbContext _dbClientiContext; + private readonly GESA_SEDECONSEGNA_DbContext _dbsedeconsegnaContext; private DbSet _clienti; + private DbSet _sedeconsegna; private readonly ILogger _logger; private readonly IConfiguration? _configuration; - public ClientiController(GESA_CLIENTI_DbContext dbClientiContext, ILogger logger, IConfiguration? configuration) + public ClientiController(GESA_CLIENTI_DbContext dbClientiContext, GESA_SEDECONSEGNA_DbContext dbsedeconsegnaContext, ILogger logger, IConfiguration? configuration) { _dbClientiContext = dbClientiContext; - + _dbsedeconsegnaContext = dbsedeconsegnaContext; _logger = logger; _configuration = configuration; } - //[HttpGet("ListaClienti")] - //public async Task>> GetClienti() - //{ - // List listClienti = new List(); - // //Clienti cliente = new Clienti(); - // _clienti = _dbClientiContext.Cli; - // var lista = await _clienti.ToListAsync(); + [HttpGet("GetCommittenti")] + public async Task>> GetClienti() + { + List listClienti = new List(); + _clienti = _dbClientiContext.Cli; + var lista = await _clienti.Where(x => x.Antipcon.Equals("C")).ToListAsync(); - // foreach (var client in lista) - // { - // listClienti.Add(client); - // } + foreach (var client in lista) + { + listClienti.Add(client); + } - // return listClienti; + return listClienti; + } - //} + [HttpGet("GetSediByCommittente")] + public async Task>> GetSediByCommittente(string codCom) + { + List listSedi = new List(); + _sedeconsegna = _dbsedeconsegnaContext.SedeConsegna; + var listaSedi = await _sedeconsegna.Where(x => x.Pccodcon.Contains(codCom)).ToListAsync(); + foreach (var sede in listaSedi) + { + listSedi.Add(sede); + } + return listSedi; + } } } diff --git a/Models/Gesa_DbContext/GESA_SEDECONSEGNA_DbContext.cs b/Models/Gesa_DbContext/GESA_SEDECONSEGNA_DbContext.cs new file mode 100644 index 0000000..ba56f30 --- /dev/null +++ b/Models/Gesa_DbContext/GESA_SEDECONSEGNA_DbContext.cs @@ -0,0 +1,24 @@ +using Microsoft.EntityFrameworkCore; + +namespace ApiSoftway.Models.Gesa_DbContext +{ + public class GESA_SEDECONSEGNA_DbContext : DbContext + { + public DbSet? SedeConsegna { get; set; } + + public GESA_SEDECONSEGNA_DbContext(DbContextOptions options) : base(options) + { + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().ToTable("GESAPIANICON"); + modelBuilder.Entity().HasKey(table => new + { + table.Pctipcon, + table.Pccodcon, + table.Cprownum + }); + } + } +} diff --git a/Models/SedeConsegna.cs b/Models/SedeConsegna.cs new file mode 100644 index 0000000..7d3488d --- /dev/null +++ b/Models/SedeConsegna.cs @@ -0,0 +1,19 @@ +using Microsoft.EntityFrameworkCore; +using System.ComponentModel.DataAnnotations; + +namespace ApiSoftway.Models +{ + public class SedeConsegna + { + [Key] + public string? Pctipcon { get; set; } + [Key] + public string? Pccodcon { get; set; } + [Key] + public int? Cprownum { get; set; } + public int? Cproword { get; set; } + public string? Pccodsed { get; set; } + public string? Pcdescri { get; set; } + public string? Pcindiri { get; set; } + } +} diff --git a/Program.cs b/Program.cs index 7688b2a..80be876 100644 --- a/Program.cs +++ b/Program.cs @@ -51,6 +51,9 @@ builder.Services.AddDbContext(options => options.UseSq 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 @@ -74,5 +77,5 @@ app.UseAuthorization(); app.MapControllers(); -//app.Run(); -app.Run("http://localhost:6000"); +app.Run(); +//app.Run("http://localhost:6000");