API for Cordonel Calibrations offsets

This commit is contained in:
Stoyan Zlatev 2023-08-29 13:56:24 +02:00
parent 3f40b39b39
commit eba79a4d75
4 changed files with 105 additions and 8 deletions

View File

@ -1,4 +1,7 @@
using System;
using LaaProductionSQL;
using System;
using System.ComponentModel.DataAnnotations;
using System.Configuration;
using System.Net;
using System.Net.Http;
using System.Text;
@ -8,16 +11,13 @@ using Xylem.Common.Logic.ServiceCore;
namespace Xylem.Common.Service.MeterProcessState.Controllers
{
[RoutePrefix("api/TestBench")]
public class TestBenchController : ApiController
{
public static class GlobalConfig
{
public static Lazy<String> connectionString = new Lazy<String>(()
=>
System.Configuration.ConfigurationManager.ConnectionStrings["default"].ConnectionString
);
public static Lazy<String> ConnectionString = new Lazy<String>(()
=> ConfigurationManager.ConnectionStrings["default"].ConnectionString);
}
/// <summary>
@ -34,7 +34,7 @@ namespace Xylem.Common.Service.MeterProcessState.Controllers
{
return await Task.Run(() =>
{
using (var dataacces = new SqlDataAccess(GlobalConfig.connectionString.Value))
using (var dataacces = new SqlDataAccess(GlobalConfig.ConnectionString.Value))
{
StringBuilder sb = new StringBuilder();
@ -82,7 +82,7 @@ namespace Xylem.Common.Service.MeterProcessState.Controllers
{
return await Task.Run(() =>
{
using (var dataacces = new SqlDataAccess(GlobalConfig.connectionString.Value))
using (var dataacces = new SqlDataAccess(GlobalConfig.ConnectionString.Value))
{
StringBuilder sb = new StringBuilder();
@ -122,5 +122,87 @@ namespace Xylem.Common.Service.MeterProcessState.Controllers
return Request.CreateResponse(HttpStatusCode.InternalServerError, ex);
}
}
[HttpGet]
[Route("GetOffsetCalibration/{pcbId}")]
public IHttpActionResult GetOffsetCalibration(int pcbId)
{
var offset = SQLConnection
.CreateSQLConnection(GlobalConfig.ConnectionString.Value)
.CreateCommand($@"
SELECT [PcbId]
, [TestRunNr]
, [Offset]
FROM [Cordonel_Calibrations]
WHERE [PcbId] = @{nameof(pcbId)}")
.SetParameter(nameof(pcbId), pcbId)
.FirstOrDefault(x => new CordonelCalibration
{
PcbId = x.GetInt(),
TestRunNr = x.GetInt(),
Offset = x.GetValue<double>()
});
return this.Json(offset);
}
[HttpPost]
public IHttpActionResult AddOffsetCalibration([FromBody] CordonelCalibration model)
{
var rowsAffected = SQLConnection
.CreateSQLConnection(GlobalConfig.ConnectionString.Value)
.CreateCommand($@"
INSERT
INTO [Cordonel_Calibrations]
( [PcbId]
, [TestRunNr]
, [Offset])
VALUES (@{nameof(CordonelCalibration.PcbId)}
, @{nameof(CordonelCalibration.TestRunNr)}
, @{nameof(CordonelCalibration.Offset)})")
.SetParameter(nameof(CordonelCalibration.PcbId), model.PcbId)
.SetParameter(nameof(CordonelCalibration.TestRunNr), model.TestRunNr)
.SetParameter(nameof(CordonelCalibration.Offset), model.Offset)
.ExecuteNonQuery();
if (rowsAffected == 1)
{
return this.Ok();
}
return this.BadRequest("Invalid data.");
}
[HttpPost]
public IHttpActionResult SetOffsetCalibration([FromBody] CordonelCalibration model)
{
var rowsAffected = SQLConnection
.CreateSQLConnection(GlobalConfig.ConnectionString.Value)
.CreateCommand($@"
UPDATE [Cordonel_Calibrations]
SET [TestRunNr] = @{nameof(CordonelCalibration.TestRunNr)}
, [Offset] = @{nameof(CordonelCalibration.Offset)}
WHERE [PcbId] = @{nameof(CordonelCalibration.PcbId)}")
.SetParameter(nameof(CordonelCalibration.TestRunNr), model.TestRunNr)
.SetParameter(nameof(CordonelCalibration.Offset), model.Offset)
.SetParameter(nameof(CordonelCalibration.PcbId), model.PcbId)
.ExecuteNonQuery();
if (rowsAffected == 1)
{
return this.Ok();
}
return this.BadRequest("Invalid data.");
}
public class CordonelCalibration
{
public int PcbId { get; set; }
public int TestRunNr { get; set; }
public double Offset { get; set; }
}
}
}

View File

@ -49,6 +49,9 @@
<LangVersion>7</LangVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="LaaProductionSQL, Version=1.0.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\LaaProductionSQL.1.0.4\lib\netstandard2.0\LaaProductionSQL.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.4.1.0\lib\net472\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll</HintPath>
</Reference>
@ -65,6 +68,9 @@
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data.SqlClient, Version=4.6.1.5, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Data.SqlClient.4.8.5\lib\net461\System.Data.SqlClient.dll</HintPath>
</Reference>
<Reference Include="System.IO.Compression" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Web.ApplicationServices" />
@ -320,6 +326,7 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="Properties\PublishProfiles\a.pubxml" />
<Content Include="README.md" />
<None Include="Scripts\jquery-1.10.2.intellisense.js" />
<Content Include="Scripts\jquery-1.10.2.js" />
<Content Include="Scripts\jquery-1.10.2.min.js" />

View File

@ -0,0 +1,6 @@
CREATE TABLE [Cordonel_Calibrations] (
[PcbId] INT NOT NULL,
[TestRunNr] INT NOT NULL,
[Offset] FLOAT NOT NULL,
CONSTRAINT [PK_Cordonel_Calibrations_PcbId] PRIMARY KEY ([PcbId])
);

View File

@ -6,6 +6,7 @@
<package id="EntityFramework" version="6.1.3" targetFramework="net46" />
<package id="jQuery" version="1.10.2" targetFramework="net46" />
<package id="jQuery.Validation" version="1.11.1" targetFramework="net46" />
<package id="LaaProductionSQL" version="1.0.4" targetFramework="net472" />
<package id="Microsoft.AspNet.Identity.Core" version="2.2.1" targetFramework="net46" />
<package id="Microsoft.AspNet.Identity.EntityFramework" version="2.2.1" targetFramework="net46" />
<package id="Microsoft.AspNet.Identity.Owin" version="2.2.1" targetFramework="net46" />
@ -39,6 +40,7 @@
<package id="Respond" version="1.2.0" targetFramework="net46" />
<package id="Swashbuckle" version="5.5.3" targetFramework="net46" />
<package id="Swashbuckle.Core" version="5.6.0" targetFramework="net46" />
<package id="System.Data.SqlClient" version="4.8.5" targetFramework="net472" />
<package id="WebActivatorEx" version="2.2.0" targetFramework="net46" />
<package id="WebGrease" version="1.5.2" targetFramework="net46" />
</packages>