a7c488a630
- Add/Update tool api - Update family/magazines positions
233 lines
8.4 KiB
C#
233 lines
8.4 KiB
C#
using Step.Model.DTOModels.ToolModels;
|
|
using Step.NC;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Web.Http;
|
|
using static CMS_CORE_Library.DataStructures;
|
|
|
|
namespace Step.Controllers.WebApi
|
|
{
|
|
[RoutePrefix("api/tool_table")]
|
|
public class ToolTableController : ApiController
|
|
{
|
|
[Route("configuration"), HttpGet]
|
|
public IHttpActionResult GetToolTableConfiguration()
|
|
{
|
|
using (NcHandler ncHandler = new NcHandler())
|
|
{
|
|
ncHandler.Connect();
|
|
CmsError libraryError = ncHandler.GetToolTableConfiguration(out ToolTableConfiguration toolTableConfiguration);
|
|
if (libraryError.IsError())
|
|
if (libraryError.errorCode != CMS_ERROR_CODES.NOT_CONNECTED)
|
|
return BadRequest(libraryError.message);
|
|
|
|
return Ok(toolTableConfiguration);
|
|
}
|
|
}
|
|
|
|
[Route("tools"), HttpGet]
|
|
public IHttpActionResult GetToolTable()
|
|
{
|
|
using (NcHandler ncHandler = new NcHandler())
|
|
{
|
|
ncHandler.Connect();
|
|
CmsError libraryError = ncHandler.GetToolTableData(out List<SiemensToolModel> tools);
|
|
if (libraryError.IsError())
|
|
if (libraryError.errorCode != CMS_ERROR_CODES.NOT_CONNECTED)
|
|
return BadRequest(libraryError.message);
|
|
|
|
return Ok(tools);
|
|
}
|
|
}
|
|
|
|
[Route("siemens/tool"), HttpPost]
|
|
public IHttpActionResult AddTool([FromBody][Required]DTOSiemensToolModel tool)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return BadRequest(ModelState);
|
|
}
|
|
|
|
using (NcHandler ncHandler = new NcHandler())
|
|
{
|
|
// Convert from DTOModel to library model
|
|
SiemensToolModel siemensModel = ConvertFromDTOtoSiemensModel(tool);
|
|
|
|
ncHandler.Connect();
|
|
CmsError libraryError = ncHandler.AddTool(ref siemensModel);
|
|
if (libraryError.IsError())
|
|
if (libraryError.errorCode != CMS_ERROR_CODES.NOT_CONNECTED)
|
|
return BadRequest(libraryError.message);
|
|
|
|
return Ok(siemensModel);
|
|
}
|
|
}
|
|
|
|
[Route("siemens/tool/{id}"), HttpPut]
|
|
public IHttpActionResult UpdateTool(int id, [FromBody][Required]DTOSiemensToolModel tool)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return BadRequest(ModelState);
|
|
}
|
|
|
|
using (NcHandler ncHandler = new NcHandler())
|
|
{
|
|
// Convert from DTOModel to library model
|
|
SiemensToolModel siemensModel = ConvertFromDTOtoSiemensModel(tool);
|
|
|
|
ncHandler.Connect();
|
|
CmsError libraryError = ncHandler.UpdateTool(siemensModel);
|
|
|
|
if (libraryError.IsError())
|
|
if (libraryError.errorCode != CMS_ERROR_CODES.NOT_CONNECTED)
|
|
return BadRequest(libraryError.message);
|
|
|
|
return Ok();
|
|
}
|
|
}
|
|
|
|
private SiemensToolModel ConvertFromDTOtoSiemensModel(DTOSiemensToolModel dtoModel)
|
|
{
|
|
return new SiemensToolModel()
|
|
{
|
|
MagazinePositionType = dtoModel.MagazinePositionType,
|
|
ToolType = dtoModel.ToolType,
|
|
|
|
FamilyName = dtoModel.FamilyName,
|
|
|
|
IsActive = dtoModel.IsActive,
|
|
IsInhibited = dtoModel.IsInhibited,
|
|
IsInUse = dtoModel.IsInUse,
|
|
IsMeasured = dtoModel.IsMeasured,
|
|
ChangeTool = dtoModel.ChangeTool,
|
|
FixedPlace = dtoModel.FixedPlace,
|
|
PreAlarm = dtoModel.PreAlarm,
|
|
|
|
Cooling1 = dtoModel.Cooling1,
|
|
Cooling2 = dtoModel.Cooling2,
|
|
LeftSize = dtoModel.LeftSize,
|
|
RightSize = dtoModel.RightSize,
|
|
Rotation = dtoModel.Rotation
|
|
};
|
|
}
|
|
|
|
[Route("families"), HttpGet]
|
|
public IHttpActionResult GetFamilies()
|
|
{
|
|
using (NcHandler ncHandler = new NcHandler())
|
|
{
|
|
ncHandler.Connect();
|
|
CmsError libraryError = ncHandler.GetFamiliesData(out List<FamilyModel> families);
|
|
if (libraryError.IsError())
|
|
if (libraryError.errorCode != CMS_ERROR_CODES.NOT_CONNECTED)
|
|
return BadRequest(libraryError.message);
|
|
|
|
return Ok(families);
|
|
}
|
|
}
|
|
|
|
[Route("magazines_positions"), HttpGet]
|
|
public IHttpActionResult GetMagazinesPositions()
|
|
{
|
|
using (NcHandler ncHandler = new NcHandler())
|
|
{
|
|
ncHandler.Connect();
|
|
CmsError libraryError = ncHandler.GetMagazinesPositionsData(out List<MagazinePositionsModel> magazines);
|
|
if (libraryError.IsError())
|
|
if (libraryError.errorCode != CMS_ERROR_CODES.NOT_CONNECTED)
|
|
return BadRequest(libraryError.message);
|
|
|
|
return Ok(magazines);
|
|
}
|
|
}
|
|
|
|
[Route("family"), HttpPost]
|
|
public IHttpActionResult AddFamily([FromBody] dynamic body)
|
|
{
|
|
using (NcHandler ncHandler = new NcHandler())
|
|
{
|
|
ncHandler.Connect();
|
|
CmsError libraryError = ncHandler.AddFamily(body.name.ToString(), out FamilyModel family);
|
|
if (libraryError.IsError())
|
|
if (libraryError.errorCode != CMS_ERROR_CODES.NOT_CONNECTED)
|
|
return BadRequest(libraryError.message);
|
|
|
|
return Ok(family);
|
|
}
|
|
}
|
|
|
|
[Route("shank"), HttpPost]
|
|
public IHttpActionResult AddShank()
|
|
{
|
|
using (NcHandler ncHandler = new NcHandler())
|
|
{
|
|
ncHandler.Connect();
|
|
CmsError libraryError = ncHandler.AddShank(out ShankModel shank);
|
|
if (libraryError.IsError())
|
|
if (libraryError.errorCode != CMS_ERROR_CODES.NOT_CONNECTED)
|
|
return BadRequest(libraryError.message);
|
|
|
|
return Ok(shank);
|
|
}
|
|
}
|
|
|
|
[Route("shanks"), HttpGet]
|
|
public IHttpActionResult GetShanks()
|
|
{
|
|
using (NcHandler ncHandler = new NcHandler())
|
|
{
|
|
ncHandler.Connect();
|
|
CmsError libraryError = ncHandler.GetShanksData(out List<ShankModel> shanks);
|
|
if (libraryError.IsError())
|
|
if (libraryError.errorCode != CMS_ERROR_CODES.NOT_CONNECTED)
|
|
return BadRequest(libraryError.message);
|
|
|
|
return Ok(shanks);
|
|
}
|
|
}
|
|
|
|
[Route("family/{oldName}"), HttpPut]
|
|
public IHttpActionResult PutFamily(string oldName, [FromBody]dynamic body)
|
|
{
|
|
using (NcHandler ncHandler = new NcHandler())
|
|
{
|
|
ncHandler.Connect();
|
|
|
|
|
|
CmsError libraryError = ncHandler.UpdateFamilyName(oldName, body.name.ToString());
|
|
if (libraryError.IsError())
|
|
if (libraryError.errorCode != CMS_ERROR_CODES.NOT_CONNECTED)
|
|
return BadRequest(libraryError.message);
|
|
|
|
return Ok();
|
|
}
|
|
}
|
|
|
|
[Route("magazine_position/{magazineId}/{position}"), HttpPut]
|
|
public IHttpActionResult PutMagazinePosition(int magazineId, int position, [FromBody]dynamic body)
|
|
{
|
|
using (NcHandler ncHandler = new NcHandler())
|
|
{
|
|
ncHandler.Connect();
|
|
if (magazineId == 0 || position == 0 || body == null || body.type == null)
|
|
return BadRequest();
|
|
// Create Library model
|
|
MagazinePositionsModel pos = new MagazinePositionsModel()
|
|
{
|
|
Id = position,
|
|
MagazineId = magazineId,
|
|
Type = Convert.ToInt32(body.type)
|
|
};
|
|
// Update
|
|
CmsError libraryError = ncHandler.UpdateMagazinePosition(pos);
|
|
if (libraryError.IsError())
|
|
if (libraryError.errorCode != CMS_ERROR_CODES.NOT_CONNECTED)
|
|
return BadRequest(libraryError.message);
|
|
|
|
return Ok();
|
|
}
|
|
}
|
|
}
|
|
} |