WIP Added family/tool/shank add API
This commit is contained in:
@@ -35,6 +35,16 @@ namespace Step.Database.Controllers
|
||||
return families;
|
||||
}
|
||||
|
||||
public NcToolModel FindTool(int toolId)
|
||||
{
|
||||
return dbCtx.Tools
|
||||
.Include("Offset1")
|
||||
.Include("Offset2")
|
||||
.Include("Offset3")
|
||||
.Where(x => x.ToolId == toolId)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
public List<NcToolModel> GetTools()
|
||||
{
|
||||
List<NcToolModel> tools = dbCtx.Tools
|
||||
@@ -77,6 +87,18 @@ namespace Step.Database.Controllers
|
||||
return (NcToolModel)tool;
|
||||
}
|
||||
|
||||
public NcToolModel UpdateTool(NcToolModel tool, DTONcToolModel dtoTool)
|
||||
{
|
||||
tool.FamilyId = dtoTool.FamilyId;
|
||||
tool.Type = dtoTool.Type;
|
||||
tool.OffsetLenght = dtoTool.OffsetLenght;
|
||||
tool.ResidualLife = dtoTool.ResidualLife;
|
||||
tool.ResidualRevive = dtoTool.ResidualRevive;
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
|
||||
return (NcToolModel)tool;
|
||||
}
|
||||
|
||||
public NcFamilyModel AddFamily(DTONcFamilyModel family)
|
||||
{
|
||||
@@ -86,5 +108,14 @@ namespace Step.Database.Controllers
|
||||
|
||||
return (NcFamilyModel)family;
|
||||
}
|
||||
|
||||
public NcShankModel AddShank(DTONcShankModel shank)
|
||||
{
|
||||
dbCtx.Shanks.Add((NcShankModel)shank);
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
|
||||
return (NcShankModel)shank;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
+1
-1
@@ -13,7 +13,7 @@ namespace Step.Database.Migrations
|
||||
|
||||
string IMigrationMetadata.Id
|
||||
{
|
||||
get { return "201806260745029_InitMigration"; }
|
||||
get { return "201806271056363_InitMigration"; }
|
||||
}
|
||||
|
||||
string IMigrationMetadata.Source
|
||||
+3
-3
@@ -201,14 +201,14 @@ namespace Step.Database.Migrations
|
||||
"dbo.shank",
|
||||
c => new
|
||||
{
|
||||
magazine_id = c.Byte(nullable: false),
|
||||
position_id = c.Byte(nullable: false),
|
||||
magazine_id = c.Byte(),
|
||||
position_id = c.Byte(),
|
||||
id = c.Int(nullable: false, identity: true),
|
||||
balluf = c.Short(),
|
||||
magazine_position_type = c.Byte(nullable: false),
|
||||
})
|
||||
.PrimaryKey(t => t.id)
|
||||
.ForeignKey("dbo.magazine_position", t => new { t.magazine_id, t.position_id }, cascadeDelete: true)
|
||||
.ForeignKey("dbo.magazine_position", t => new { t.magazine_id, t.position_id })
|
||||
.Index(t => new { t.magazine_id, t.position_id });
|
||||
|
||||
CreateTable(
|
||||
File diff suppressed because one or more lines are too long
@@ -78,9 +78,9 @@
|
||||
<Compile Include="Controllers\UsersController.cs" />
|
||||
<Compile Include="Controllers\MachinesUsersController.cs" />
|
||||
<Compile Include="DatabaseContext.cs" />
|
||||
<Compile Include="Migrations\201806260745029_InitMigration.cs" />
|
||||
<Compile Include="Migrations\201806260745029_InitMigration.Designer.cs">
|
||||
<DependentUpon>201806260745029_InitMigration.cs</DependentUpon>
|
||||
<Compile Include="Migrations\201806271056363_InitMigration.cs" />
|
||||
<Compile Include="Migrations\201806271056363_InitMigration.Designer.cs">
|
||||
<DependentUpon>201806271056363_InitMigration.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Migrations\Configuration.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
@@ -116,8 +116,8 @@
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Migrations\201806260745029_InitMigration.resx">
|
||||
<DependentUpon>201806260745029_InitMigration.cs</DependentUpon>
|
||||
<EmbeddedResource Include="Migrations\201806271056363_InitMigration.resx">
|
||||
<DependentUpon>201806271056363_InitMigration.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
using Step.Model.DatabaseModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Step.Model.DTOModels.ToolModels
|
||||
{
|
||||
public class DTONcShankModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public short? Balluf { get; set; }
|
||||
|
||||
public byte MagazinePositionType { get; set; }
|
||||
|
||||
public byte? MagazineId { get; set; }
|
||||
|
||||
public byte? PositionId { get; set; }
|
||||
|
||||
public static explicit operator DTONcShankModel(NcShankModel obj)
|
||||
{
|
||||
return new DTONcShankModel()
|
||||
{
|
||||
Id = obj.ShankId,
|
||||
Balluf = obj.Balluf,
|
||||
MagazinePositionType = obj.MagazinePositionType,
|
||||
MagazineId = obj.MagazineId,
|
||||
PositionId = obj.PositionId
|
||||
};
|
||||
}
|
||||
|
||||
public static explicit operator NcShankModel(DTONcShankModel obj)
|
||||
{
|
||||
return new NcShankModel()
|
||||
{
|
||||
ShankId = obj.Id,
|
||||
Balluf = obj.Balluf,
|
||||
MagazinePositionType = obj.MagazinePositionType,
|
||||
MagazineId = obj.MagazineId,
|
||||
PositionId = obj.PositionId
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -113,6 +113,7 @@
|
||||
<Compile Include="DTOModels\ToolModels\DTOEdgeModel.cs" />
|
||||
<Compile Include="DTOModels\ToolModels\DTOMagazineStatusModel.cs" />
|
||||
<Compile Include="DTOModels\ToolModels\DTONcFamilyModel.cs" />
|
||||
<Compile Include="DTOModels\ToolModels\DTONcShankModel.cs" />
|
||||
<Compile Include="DTOModels\ToolModels\DTONcToolModel.cs" />
|
||||
<Compile Include="DTOModels\ToolModels\DTOShankModel.cs" />
|
||||
<Compile Include="DTOModels\ToolModels\DTOSiemensToolModel.cs" />
|
||||
|
||||
@@ -1071,6 +1071,14 @@ namespace Step.NC
|
||||
}
|
||||
}
|
||||
|
||||
public NcToolModel UpdateTool(NcToolModel tool, DTONcToolModel dtoTool)
|
||||
{
|
||||
using (NcToolManagerController toolsManager = new NcToolManagerController())
|
||||
{
|
||||
return toolsManager.UpdateTool(tool, dtoTool);
|
||||
}
|
||||
}
|
||||
|
||||
public NcFamilyModel AddFamily(DTONcFamilyModel family)
|
||||
{
|
||||
using (NcToolManagerController toolsManager = new NcToolManagerController())
|
||||
@@ -1078,6 +1086,14 @@ namespace Step.NC
|
||||
return toolsManager.AddFamily(family);
|
||||
}
|
||||
}
|
||||
|
||||
public NcShankModel AddShank(DTONcShankModel shank)
|
||||
{
|
||||
using (NcToolManagerController toolsManager = new NcToolManagerController())
|
||||
{
|
||||
return toolsManager.AddShank(shank);
|
||||
}
|
||||
}
|
||||
#endregion Write data
|
||||
}
|
||||
}
|
||||
+66
-7
@@ -1,4 +1,5 @@
|
||||
using Step.Model.DatabaseModels;
|
||||
using Step.Database.Controllers;
|
||||
using Step.Model.DatabaseModels;
|
||||
using Step.Model.DTOModels.ToolModels;
|
||||
using Step.NC;
|
||||
using System;
|
||||
@@ -12,7 +13,7 @@ using System.Web.Http;
|
||||
namespace Step.Controllers.WebApi
|
||||
{
|
||||
[RoutePrefix("api/tool_manager/nc")]
|
||||
public class NcToolTableController : ApiController
|
||||
public class NcToolManagerApiController : ApiController
|
||||
{
|
||||
[Route("tools"), HttpGet]
|
||||
public IHttpActionResult GetNcToolTable()
|
||||
@@ -77,7 +78,7 @@ namespace Step.Controllers.WebApi
|
||||
}
|
||||
|
||||
[Route("tool"), HttpPost]
|
||||
public IHttpActionResult AddTool([FromBody][Required]DTONcToolModel tool)
|
||||
public IHttpActionResult AddTool([FromBody][Required]DTONcToolModel dtoTool)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState);
|
||||
@@ -85,14 +86,36 @@ namespace Step.Controllers.WebApi
|
||||
using (NcHandler ncHandler = new NcHandler())
|
||||
{
|
||||
ncHandler.Connect();
|
||||
NcToolModel newTool = ncHandler.AddTool(tool);
|
||||
NcToolModel newTool = ncHandler.AddTool(dtoTool);
|
||||
|
||||
return Ok(newTool);
|
||||
}
|
||||
}
|
||||
|
||||
[Route("tool"), HttpPost]
|
||||
public IHttpActionResult AddFamily([FromBody][Required]DTONcFamilyModel family)
|
||||
[Route("tool/{toolId:int}"), HttpPut]
|
||||
public IHttpActionResult PutTool(int toolId, [FromBody][Required]DTONcToolModel dtoTool)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState);
|
||||
|
||||
using (NcToolManagerController toolsManager = new NcToolManagerController())
|
||||
{
|
||||
NcToolModel tool = toolsManager.FindTool(toolId);
|
||||
if (tool == null)
|
||||
return NotFound();
|
||||
|
||||
using (NcHandler ncHandler = new NcHandler())
|
||||
{
|
||||
ncHandler.Connect();
|
||||
NcToolModel newTool = ncHandler.UpdateTool(tool, dtoTool);
|
||||
|
||||
return Ok(newTool);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Route("family"), HttpPost]
|
||||
public IHttpActionResult AddFamily([FromBody][Required]DTONcFamilyModel dtoFamily)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState);
|
||||
@@ -100,10 +123,46 @@ namespace Step.Controllers.WebApi
|
||||
using (NcHandler ncHandler = new NcHandler())
|
||||
{
|
||||
ncHandler.Connect();
|
||||
NcFamilyModel newFamily = ncHandler.AddFamily(family);
|
||||
NcFamilyModel newFamily = ncHandler.AddFamily(dtoFamily);
|
||||
|
||||
return Ok(newFamily);
|
||||
}
|
||||
}
|
||||
|
||||
[Route("tool/{toolId:int}"), HttpPut]
|
||||
public IHttpActionResult PutFamily(int toolId, [FromBody][Required]DTONcToolModel dtoTool)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState);
|
||||
|
||||
using (NcToolManagerController toolsManager = new NcToolManagerController())
|
||||
{
|
||||
NcToolModel tool = toolsManager.FindTool(toolId);
|
||||
if (tool == null)
|
||||
return NotFound();
|
||||
|
||||
using (NcHandler ncHandler = new NcHandler())
|
||||
{
|
||||
ncHandler.Connect();
|
||||
NcToolModel newTool = ncHandler.UpdateTool(tool, dtoTool);
|
||||
|
||||
return Ok(newTool);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Route("shank"), HttpPost]
|
||||
public IHttpActionResult AddShank([FromBody][Required] DTONcShankModel dtoShank)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState);
|
||||
|
||||
using (NcHandler ncHandler = new NcHandler())
|
||||
{
|
||||
ncHandler.Connect();
|
||||
NcShankModel shank = ncHandler.AddShank(dtoShank);
|
||||
return Ok(shank);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -11,7 +11,7 @@ using static CMS_CORE_Library.DataStructures;
|
||||
namespace Step.Controllers.WebApi
|
||||
{
|
||||
[RoutePrefix("api/tool_manager")]
|
||||
public class SiemensToolTableController : ApiController
|
||||
public class SiemensToolManagerController : ApiController
|
||||
{
|
||||
[Route("tools"), HttpGet]
|
||||
public IHttpActionResult GetToolTable()
|
||||
+2
-2
@@ -174,8 +174,8 @@
|
||||
<Compile Include="Controllers\WebApi\ConfigurationController.cs" />
|
||||
<Compile Include="Controllers\WebApi\LanguageController.cs" />
|
||||
<Compile Include="Controllers\WebApi\MaintenanceController.cs" />
|
||||
<Compile Include="Controllers\WebApi\NcToolTableController.cs" />
|
||||
<Compile Include="Controllers\WebApi\SiemensToolTableController.cs" />
|
||||
<Compile Include="Controllers\WebApi\NcToolManagerController.cs" />
|
||||
<Compile Include="Controllers\WebApi\SiemensToolManagerController.cs" />
|
||||
<Compile Include="Controllers\WebApi\UserController.cs" />
|
||||
<Compile Include="Controllers\WebApi\NcApiController.cs" />
|
||||
<Compile Include="Listeners\Database\DatabaseTest.cs" />
|
||||
|
||||
Reference in New Issue
Block a user