Michele: Clienti dbcontext, model, controller
This commit is contained in:
parent
522117c328
commit
d85dcd5e0b
45
Controllers/ClientiController.cs
Normal file
45
Controllers/ClientiController.cs
Normal file
@ -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> _clienti;
|
||||||
|
private readonly ILogger<LoginController> _logger;
|
||||||
|
private readonly IConfiguration? _configuration;
|
||||||
|
|
||||||
|
public ClientiController(GESA_CLIENTI_DbContext dbClientiContext, DbSet<Clienti> clienti, ILogger<LoginController> logger, IConfiguration? configuration)
|
||||||
|
{
|
||||||
|
_dbClientiContext = dbClientiContext;
|
||||||
|
_clienti = clienti;
|
||||||
|
_logger = logger;
|
||||||
|
_configuration = configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("ListaClienti")]
|
||||||
|
public async Task<ActionResult<IEnumerable<Clienti>>> GetClienti()
|
||||||
|
{
|
||||||
|
List<Clienti> listClienti = new List<Clienti>();
|
||||||
|
//Clienti cliente = new Clienti();
|
||||||
|
_clienti = _dbClientiContext.Clienti;
|
||||||
|
var lista = await _clienti.ToListAsync();
|
||||||
|
|
||||||
|
foreach (var client in lista)
|
||||||
|
{
|
||||||
|
listClienti.Add(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
return listClienti;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Models/Clienti.cs
Normal file
12
Models/Clienti.cs
Normal file
@ -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; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
19
Models/Gesa_DbContext/GESA_CLIENTI_DbContext.cs
Normal file
19
Models/Gesa_DbContext/GESA_CLIENTI_DbContext.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace ApiSoftway.Models.Gesa_DbContext
|
||||||
|
{
|
||||||
|
public class GESA_CLIENTI_DbContext : DbContext
|
||||||
|
{
|
||||||
|
public DbSet<Clienti> Clienti { get; set; }
|
||||||
|
|
||||||
|
public GESA_CLIENTI_DbContext(DbContextOptions<GESA_CLIENTI_DbContext> options) : base (options)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
modelBuilder.Entity<Clienti>().ToView("API_CLIENTI");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -27,6 +27,12 @@ builder.Services.AddDbContext<GESA_DESTINAZIONI_DbContext>(options => options.Us
|
|||||||
builder.Services.AddDbContext<GESA_CONSEGNE_DbContext>(options => options.UseSqlServer(builder.Configuration.GetConnectionString("GESA")
|
builder.Services.AddDbContext<GESA_CONSEGNE_DbContext>(options => options.UseSqlServer(builder.Configuration.GetConnectionString("GESA")
|
||||||
, options => { options.CommandTimeout(commandTimeoutInSeconds); }
|
, options => { options.CommandTimeout(commandTimeoutInSeconds); }
|
||||||
));
|
));
|
||||||
|
|
||||||
|
builder.Services.AddDbContext<GESA_CLIENTI_DbContext>(options => options.UseSqlServer(builder.Configuration.GetConnectionString("GESA")
|
||||||
|
, options => { options.CommandTimeout(commandTimeoutInSeconds); }
|
||||||
|
));
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user