From 1a8d72e91005a7e1d8823de060d3ebd0bff6a18b Mon Sep 17 00:00:00 2001 From: michele Date: Mon, 27 Jan 2025 17:03:30 +0100 Subject: [PATCH] CLIENTI: Dbcontext, controller con metodo get cliente da codice + azienda, model. Program e appsetting --- ApiAdHoc_Odoo.sln | 25 +++++++++++ ApiAdHoc_Odoo/ApiAdHoc_Odoo.csproj | 15 +++++++ .../Controllers/ClientiController.cs | 43 +++++++++++++++++++ ApiAdHoc_Odoo/Data/Pi_ClientiDbContext.cs | 21 +++++++++ ApiAdHoc_Odoo/Models/Cliente.cs | 24 +++++++++++ ApiAdHoc_Odoo/Program.cs | 35 +++++++++++++++ ApiAdHoc_Odoo/Properties/launchSettings.json | 31 +++++++++++++ ApiAdHoc_Odoo/appsettings.Development.json | 8 ++++ ApiAdHoc_Odoo/appsettings.json | 12 ++++++ 9 files changed, 214 insertions(+) create mode 100644 ApiAdHoc_Odoo.sln create mode 100644 ApiAdHoc_Odoo/ApiAdHoc_Odoo.csproj create mode 100644 ApiAdHoc_Odoo/Controllers/ClientiController.cs create mode 100644 ApiAdHoc_Odoo/Data/Pi_ClientiDbContext.cs create mode 100644 ApiAdHoc_Odoo/Models/Cliente.cs create mode 100644 ApiAdHoc_Odoo/Program.cs create mode 100644 ApiAdHoc_Odoo/Properties/launchSettings.json create mode 100644 ApiAdHoc_Odoo/appsettings.Development.json create mode 100644 ApiAdHoc_Odoo/appsettings.json diff --git a/ApiAdHoc_Odoo.sln b/ApiAdHoc_Odoo.sln new file mode 100644 index 0000000..15d2950 --- /dev/null +++ b/ApiAdHoc_Odoo.sln @@ -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 diff --git a/ApiAdHoc_Odoo/ApiAdHoc_Odoo.csproj b/ApiAdHoc_Odoo/ApiAdHoc_Odoo.csproj new file mode 100644 index 0000000..c8aa732 --- /dev/null +++ b/ApiAdHoc_Odoo/ApiAdHoc_Odoo.csproj @@ -0,0 +1,15 @@ + + + + net8.0 + enable + enable + + + + + + + + + diff --git a/ApiAdHoc_Odoo/Controllers/ClientiController.cs b/ApiAdHoc_Odoo/Controllers/ClientiController.cs new file mode 100644 index 0000000..a879894 --- /dev/null +++ b/ApiAdHoc_Odoo/Controllers/ClientiController.cs @@ -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>> GetApiClienti(string codAzi) + //{ + // return await _clientiContext.Clienti.Where(x => x.Azienda == codAzi).ToListAsync(); + //} + + // GET: api/ApiClienti/{codice} + [HttpGet("{codCli},{codAzi}")] + public async Task> 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; + } + } +} diff --git a/ApiAdHoc_Odoo/Data/Pi_ClientiDbContext.cs b/ApiAdHoc_Odoo/Data/Pi_ClientiDbContext.cs new file mode 100644 index 0000000..76d224b --- /dev/null +++ b/ApiAdHoc_Odoo/Data/Pi_ClientiDbContext.cs @@ -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 options) : base(options) { } + + public DbSet Clienti { get; set; } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + // Map the view to the model + modelBuilder.Entity() + .ToView("PI_APICLIENTI")/*;*/ + .HasNoKey(); // Views typically don't have a primary key + } + } +} diff --git a/ApiAdHoc_Odoo/Models/Cliente.cs b/ApiAdHoc_Odoo/Models/Cliente.cs new file mode 100644 index 0000000..c0a2106 --- /dev/null +++ b/ApiAdHoc_Odoo/Models/Cliente.cs @@ -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; } + } +} diff --git a/ApiAdHoc_Odoo/Program.cs b/ApiAdHoc_Odoo/Program.cs new file mode 100644 index 0000000..b09fe1e --- /dev/null +++ b/ApiAdHoc_Odoo/Program.cs @@ -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(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(); diff --git a/ApiAdHoc_Odoo/Properties/launchSettings.json b/ApiAdHoc_Odoo/Properties/launchSettings.json new file mode 100644 index 0000000..d35cb85 --- /dev/null +++ b/ApiAdHoc_Odoo/Properties/launchSettings.json @@ -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" + } + } + } +} diff --git a/ApiAdHoc_Odoo/appsettings.Development.json b/ApiAdHoc_Odoo/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/ApiAdHoc_Odoo/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/ApiAdHoc_Odoo/appsettings.json b/ApiAdHoc_Odoo/appsettings.json new file mode 100644 index 0000000..294ac90 --- /dev/null +++ b/ApiAdHoc_Odoo/appsettings.json @@ -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" + } +}