Fix osai tool update

This commit is contained in:
Lucio Maranta
2019-01-28 16:50:40 +01:00
parent 805b5f9f1c
commit dc94950fae
2 changed files with 20 additions and 18 deletions
+18 -3
View File
@@ -1771,19 +1771,34 @@ namespace Step.NC
}
}
public CmsError UpdateTool(int toolId, DTONewNcToolModel newTool, out DTONcToolModel toolWithOffsets)
public CmsError UpdateTool(int toolId, DTONewNcToolModel newTool, out DTONcToolModel toolWithOffsets, DTONewNcToolWithFamilyModel dtoToolWithFamily)
{
toolWithOffsets = new DTONcToolModel();
CmsError cmsError = NO_ERROR;
using (NcToolManagerController toolsManager = new NcToolManagerController())
{
using (var dbContextTransaction = toolsManager.dbCtx.Database.BeginTransaction())
{
// If option is active
if (!ToolManagerConfig.FamilyOpt)
{
// Copy only family
DTONewNcFamilyModel newFamily = new DTONewNcFamilyModel();
SupportFunctions.CopyProperties(dtoToolWithFamily, newFamily);
// Update only family data
newFamily = (DTONcFamilyModel)toolsManager.UpdateFamily(dtoToolWithFamily.FamilyId, newFamily);
// Update Nc families
cmsError = UpdateNcFamily(toolsManager);
if (cmsError.IsError())
ManageErrorAndTransaction(cmsError, dbContextTransaction, true);
}
// Update database tool Tool
DbNcToolModel dbTool = toolsManager.UpdateTool(toolId, newTool);
// Populate updated tool with offset data
CmsError cmsError = GetToolData(dbTool, ref toolWithOffsets);
cmsError = GetToolData(dbTool, ref toolWithOffsets);
if (cmsError.IsError())
{
dbContextTransaction.Rollback();
@@ -155,22 +155,9 @@ namespace Step.Controllers.WebApi
using (NcHandler ncHandler = new NcHandler())
{
ncHandler.Connect();
CmsError cmsError;
// If option is active
if (!ToolManagerConfig.FamilyOpt)
{
// Copy only family
DTONewNcFamilyModel newFamily = new DTONewNcFamilyModel();
SupportFunctions.CopyProperties(dtoToolWithFamily, newFamily);
// Update only family data
cmsError = ncHandler.UpdateFamily(dtoToolWithFamily.FamilyId, newFamily, out DTONcFamilyModel newFam);
if (cmsError.IsError())
return BadRequest(cmsError.localizationKey);
}
// Update
cmsError = ncHandler.UpdateTool(toolId, dtoToolWithFamily, out DTONcToolModel newTool);
CmsError cmsError = ncHandler.UpdateTool(toolId, dtoToolWithFamily, out DTONcToolModel newTool, dtoToolWithFamily);
if (cmsError.IsError())
return BadRequest(cmsError.localizationKey);