169 lines
5.1 KiB
C#
169 lines
5.1 KiB
C#
using Step.Database.Controllers;
|
|
using Step.Model.DatabaseModels;
|
|
using Step.Model.DTOModels.ToolModels;
|
|
using Step.NC;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Web.Http;
|
|
|
|
namespace Step.Controllers.WebApi
|
|
{
|
|
[RoutePrefix("api/tool_manager/nc")]
|
|
public class NcToolManagerApiController : ApiController
|
|
{
|
|
[Route("tools"), HttpGet]
|
|
public IHttpActionResult GetNcToolTable()
|
|
{
|
|
using (NcHandler ncHandler = new NcHandler())
|
|
{
|
|
ncHandler.Connect();
|
|
ncHandler.GetToolTableData(out List<NcToolModel> tools);
|
|
|
|
return Ok(tools);
|
|
}
|
|
}
|
|
|
|
[Route("families"), HttpGet]
|
|
public IHttpActionResult GetFamilies()
|
|
{
|
|
using (NcHandler ncHandler = new NcHandler())
|
|
{
|
|
ncHandler.Connect();
|
|
ncHandler.GetFamilies(out List<NcFamilyModel> families);
|
|
|
|
return Ok(families);
|
|
}
|
|
}
|
|
|
|
[Route("magazines_positions"), HttpGet]
|
|
public IHttpActionResult GetMagazinesPositions()
|
|
{
|
|
using (NcHandler ncHandler = new NcHandler())
|
|
{
|
|
ncHandler.Connect();
|
|
ncHandler.GetPositions(out List<NcMagazinePositionModel> magazines);
|
|
|
|
return Ok(magazines);
|
|
}
|
|
}
|
|
|
|
[Route("magazine/{magazineId:int}/positions"), HttpGet]
|
|
public IHttpActionResult GetMagazinesPositions(int magazineId)
|
|
{
|
|
using (NcHandler ncHandler = new NcHandler())
|
|
{
|
|
ncHandler.Connect();
|
|
ncHandler.GetPositions(out List<NcMagazinePositionModel> magazines);
|
|
|
|
magazines = magazines.Where(x => x.MagazineId == magazineId).ToList();
|
|
|
|
return Ok(magazines);
|
|
}
|
|
}
|
|
|
|
[Route("shanks"), HttpGet]
|
|
public IHttpActionResult GetShanks()
|
|
{
|
|
using (NcHandler ncHandler = new NcHandler())
|
|
{
|
|
ncHandler.Connect();
|
|
ncHandler.GetShanksData(out List<NcShankModel> shanks);
|
|
|
|
return Ok(shanks);
|
|
}
|
|
}
|
|
|
|
[Route("tool"), HttpPost]
|
|
public IHttpActionResult AddTool([FromBody][Required]DTONcToolModel dtoTool)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
return BadRequest(ModelState);
|
|
|
|
using (NcHandler ncHandler = new NcHandler())
|
|
{
|
|
ncHandler.Connect();
|
|
NcToolModel newTool = ncHandler.AddTool(dtoTool);
|
|
|
|
return Ok(newTool);
|
|
}
|
|
}
|
|
|
|
[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);
|
|
|
|
using (NcHandler ncHandler = new NcHandler())
|
|
{
|
|
ncHandler.Connect();
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|