Michele: aggiunto model SedeConsegna + dbcontext + controller e metodi per ricerca committente e sede committente
This commit is contained in:
parent
c6afc2c9c4
commit
4bc8b1597f
@ -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> _clienti;
|
||||
private DbSet<SedeConsegna> _sedeconsegna;
|
||||
private readonly ILogger<LoginController> _logger;
|
||||
private readonly IConfiguration? _configuration;
|
||||
|
||||
public ClientiController(GESA_CLIENTI_DbContext dbClientiContext, ILogger<LoginController> logger, IConfiguration? configuration)
|
||||
public ClientiController(GESA_CLIENTI_DbContext dbClientiContext, GESA_SEDECONSEGNA_DbContext dbsedeconsegnaContext, ILogger<LoginController> logger, IConfiguration? configuration)
|
||||
{
|
||||
_dbClientiContext = dbClientiContext;
|
||||
|
||||
_dbsedeconsegnaContext = dbsedeconsegnaContext;
|
||||
_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.Cli;
|
||||
// var lista = await _clienti.ToListAsync();
|
||||
[HttpGet("GetCommittenti")]
|
||||
public async Task<ActionResult<IEnumerable<Clienti>>> GetClienti()
|
||||
{
|
||||
List<Clienti> listClienti = new List<Clienti>();
|
||||
_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<ActionResult<IEnumerable<SedeConsegna>>> GetSediByCommittente(string codCom)
|
||||
{
|
||||
List<SedeConsegna> listSedi = new List<SedeConsegna>();
|
||||
_sedeconsegna = _dbsedeconsegnaContext.SedeConsegna;
|
||||
var listaSedi = await _sedeconsegna.Where(x => x.Pccodcon.Contains(codCom)).ToListAsync();
|
||||
|
||||
foreach (var sede in listaSedi)
|
||||
{
|
||||
listSedi.Add(sede);
|
||||
}
|
||||
|
||||
return listSedi;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
24
Models/Gesa_DbContext/GESA_SEDECONSEGNA_DbContext.cs
Normal file
24
Models/Gesa_DbContext/GESA_SEDECONSEGNA_DbContext.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ApiSoftway.Models.Gesa_DbContext
|
||||
{
|
||||
public class GESA_SEDECONSEGNA_DbContext : DbContext
|
||||
{
|
||||
public DbSet<SedeConsegna>? SedeConsegna { get; set; }
|
||||
|
||||
public GESA_SEDECONSEGNA_DbContext(DbContextOptions<GESA_SEDECONSEGNA_DbContext> options) : base(options)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<SedeConsegna>().ToTable("GESAPIANICON");
|
||||
modelBuilder.Entity<SedeConsegna>().HasKey(table => new
|
||||
{
|
||||
table.Pctipcon,
|
||||
table.Pccodcon,
|
||||
table.Cprownum
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
19
Models/SedeConsegna.cs
Normal file
19
Models/SedeConsegna.cs
Normal file
@ -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; }
|
||||
}
|
||||
}
|
||||
@ -51,6 +51,9 @@ builder.Services.AddDbContext<GESA_AUTOMEZZI_DbContext>(options => options.UseSq
|
||||
builder.Services.AddDbContext<GESA_CONSEGNE_M_DbContext>(options => options.UseSqlServer(builder.Configuration.GetConnectionString("GESA")
|
||||
, options => { options.CommandTimeout(commandTimeoutInSeconds); }
|
||||
));
|
||||
builder.Services.AddDbContext<GESA_SEDECONSEGNA_DbContext>(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");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user