CLIENTI: Dbcontext, controller con metodo get cliente da codice + azienda, model.
Program e appsetting
This commit is contained in:
parent
c66879b3ba
commit
1a8d72e910
25
ApiAdHoc_Odoo.sln
Normal file
25
ApiAdHoc_Odoo.sln
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.10.34928.147
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApiAdHoc_Odoo", "ApiAdHoc_Odoo\ApiAdHoc_Odoo.csproj", "{CB497A62-1900-4CD2-AEED-B4F61E5A0D3D}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{CB497A62-1900-4CD2-AEED-B4F61E5A0D3D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{CB497A62-1900-4CD2-AEED-B4F61E5A0D3D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CB497A62-1900-4CD2-AEED-B4F61E5A0D3D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CB497A62-1900-4CD2-AEED-B4F61E5A0D3D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {A15B48F2-40FF-4A1C-A2F8-A5ED7B6B3F66}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
15
ApiAdHoc_Odoo/ApiAdHoc_Odoo.csproj
Normal file
15
ApiAdHoc_Odoo/ApiAdHoc_Odoo.csproj
Normal file
@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.1" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
43
ApiAdHoc_Odoo/Controllers/ClientiController.cs
Normal file
43
ApiAdHoc_Odoo/Controllers/ClientiController.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ApiAdHoc_Odoo.Models;
|
||||
using ApiAdHoc_Odoo.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
|
||||
namespace ApiAdHoc_Odoo.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class ClientiController : ControllerBase
|
||||
{
|
||||
private readonly Pi_ClientiDbContext _clientiContext;
|
||||
|
||||
public ClientiController(Pi_ClientiDbContext clientiContext)
|
||||
{
|
||||
_clientiContext = clientiContext;
|
||||
}
|
||||
|
||||
//COMMENTATA PERCHE' L'IMPORT INIZIALE VERRA' FATTO DA FILE QUINDI NON CI SERVIRA' PIU' QUESTA CHIAMATA.
|
||||
//// GET: api/ApiClienti
|
||||
//[HttpGet("{codAzi}")]
|
||||
//public async Task<ActionResult<IEnumerable<Cliente>>> GetApiClienti(string codAzi)
|
||||
//{
|
||||
// return await _clientiContext.Clienti.Where(x => x.Azienda == codAzi).ToListAsync();
|
||||
//}
|
||||
|
||||
// GET: api/ApiClienti/{codice}
|
||||
[HttpGet("{codCli},{codAzi}")]
|
||||
public async Task<ActionResult<Cliente>> GetApiCliente(string codCli, string codAzi)
|
||||
{
|
||||
var cliente = await _clientiContext.Clienti.FirstOrDefaultAsync(c => c.Codice == codCli && c.Azienda == codAzi);
|
||||
|
||||
if (cliente == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
return cliente;
|
||||
}
|
||||
}
|
||||
}
|
||||
21
ApiAdHoc_Odoo/Data/Pi_ClientiDbContext.cs
Normal file
21
ApiAdHoc_Odoo/Data/Pi_ClientiDbContext.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using ApiAdHoc_Odoo.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
|
||||
namespace ApiAdHoc_Odoo.Data
|
||||
{
|
||||
public class Pi_ClientiDbContext : DbContext
|
||||
{
|
||||
public Pi_ClientiDbContext(DbContextOptions<Pi_ClientiDbContext> options) : base(options) { }
|
||||
|
||||
public DbSet<Cliente> Clienti { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
// Map the view to the model
|
||||
modelBuilder.Entity<Cliente>()
|
||||
.ToView("PI_APICLIENTI")/*;*/
|
||||
.HasNoKey(); // Views typically don't have a primary key
|
||||
}
|
||||
}
|
||||
}
|
||||
24
ApiAdHoc_Odoo/Models/Cliente.cs
Normal file
24
ApiAdHoc_Odoo/Models/Cliente.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace ApiAdHoc_Odoo.Models
|
||||
{
|
||||
public class Cliente
|
||||
{
|
||||
public string Azienda { get; set; }
|
||||
public string Codice { get; set; }
|
||||
public string Descrizione { get; set; }
|
||||
public string Partiva { get; set; }
|
||||
public string CodFisc { get; set; }
|
||||
public string Telefono { get; set; }
|
||||
public string Cellulare { get; set; }
|
||||
public string Email { get; set; }
|
||||
public string Indirizzo { get; set; }
|
||||
public string Citta { get; set; }
|
||||
public string Cap { get; set; }
|
||||
public string Provincia { get; set; }
|
||||
public string CodAgente { get; set; }
|
||||
public string DescriAgente { get; set; }
|
||||
public int Blocco { get; set; }
|
||||
public DateTime Obsolescenza { get; set; }
|
||||
}
|
||||
}
|
||||
35
ApiAdHoc_Odoo/Program.cs
Normal file
35
ApiAdHoc_Odoo/Program.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using ApiAdHoc_Odoo.Data;
|
||||
using ApiAdHoc_Odoo.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllers();
|
||||
|
||||
#region istanze dbContext
|
||||
builder.Services.AddDbContext<Pi_ClientiDbContext>(options =>
|
||||
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
|
||||
#endregion
|
||||
|
||||
builder.Services.AddControllers();
|
||||
|
||||
// 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.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
31
ApiAdHoc_Odoo/Properties/launchSettings.json
Normal file
31
ApiAdHoc_Odoo/Properties/launchSettings.json
Normal file
@ -0,0 +1,31 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:63210",
|
||||
"sslPort": 0
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "http://localhost:5280",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
8
ApiAdHoc_Odoo/appsettings.Development.json
Normal file
8
ApiAdHoc_Odoo/appsettings.Development.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
12
ApiAdHoc_Odoo/appsettings.json
Normal file
12
ApiAdHoc_Odoo/appsettings.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Data Source=poloinformatico15.clienti.init-s.it;Initial Catalog=AHR_PI;User Id=sa; Password=p0l01nf.;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False; encrypt=false"
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user