diff --git a/Controllers/ClientiController.cs b/Controllers/ClientiController.cs new file mode 100644 index 0000000..4e50431 --- /dev/null +++ b/Controllers/ClientiController.cs @@ -0,0 +1,45 @@ +using ApiSoftway.Models; +using ApiSoftway.Models.Gesa_DbContext; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace ApiSoftway.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class ClientiController : ControllerBase + { + private readonly GESA_CLIENTI_DbContext _dbClientiContext; + private DbSet _clienti; + private readonly ILogger _logger; + private readonly IConfiguration? _configuration; + + public ClientiController(GESA_CLIENTI_DbContext dbClientiContext, DbSet clienti, ILogger logger, IConfiguration? configuration) + { + _dbClientiContext = dbClientiContext; + _clienti = clienti; + _logger = logger; + _configuration = configuration; + } + + [HttpGet("ListaClienti")] + public async Task>> GetClienti() + { + List listClienti = new List(); + //Clienti cliente = new Clienti(); + _clienti = _dbClientiContext.Clienti; + var lista = await _clienti.ToListAsync(); + + foreach (var client in lista) + { + listClienti.Add(client); + } + + return listClienti; + + } + + + } +} diff --git a/Models/Clienti.cs b/Models/Clienti.cs new file mode 100644 index 0000000..b66b193 --- /dev/null +++ b/Models/Clienti.cs @@ -0,0 +1,12 @@ +namespace ApiSoftway.Models +{ + public class Clienti + { + public string? antipcon { get; set; } + public string? ancodice { get; set; } + public string? andescri { get; set; } + public string? ancodfis { get; set; } + public string? anpariva { get; set; } + + } +} diff --git a/Models/Gesa_DbContext/GESA_CLIENTI_DbContext.cs b/Models/Gesa_DbContext/GESA_CLIENTI_DbContext.cs new file mode 100644 index 0000000..c59fe1f --- /dev/null +++ b/Models/Gesa_DbContext/GESA_CLIENTI_DbContext.cs @@ -0,0 +1,19 @@ +using Microsoft.EntityFrameworkCore; + +namespace ApiSoftway.Models.Gesa_DbContext +{ + public class GESA_CLIENTI_DbContext : DbContext + { + public DbSet Clienti { get; set; } + + public GESA_CLIENTI_DbContext(DbContextOptions options) : base (options) + { + + } + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().ToView("API_CLIENTI"); + } + + } +} diff --git a/Program.cs b/Program.cs index dafc8b0..00626b3 100644 --- a/Program.cs +++ b/Program.cs @@ -27,6 +27,12 @@ builder.Services.AddDbContext(options => options.Us 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