diff --git a/Step.NC/NcHandler.cs b/Step.NC/NcHandler.cs index 0740ff4f..cbf6a767 100644 --- a/Step.NC/NcHandler.cs +++ b/Step.NC/NcHandler.cs @@ -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(); diff --git a/Step/Controllers/WebApi/NcToolManagerController.cs b/Step/Controllers/WebApi/NcToolManagerController.cs index f9a99f55..c93aa6eb 100644 --- a/Step/Controllers/WebApi/NcToolManagerController.cs +++ b/Step/Controllers/WebApi/NcToolManagerController.cs @@ -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);