diff --git a/Libs/CMS_CORE_Library.dll b/Libs/CMS_CORE_Library.dll
index 83e0794f..fc0dc885 100644
Binary files a/Libs/CMS_CORE_Library.dll and b/Libs/CMS_CORE_Library.dll differ
diff --git a/Step.Config/Config/toolManagerConfig.xml b/Step.Config/Config/toolManagerConfig.xml
index 1871da31..d8a1dc71 100644
--- a/Step.Config/Config/toolManagerConfig.xml
+++ b/Step.Config/Config/toolManagerConfig.xml
@@ -9,7 +9,7 @@
true
true
true
- false
+ true
true
true
true
diff --git a/Step.Model/DTOModels/ToolModels/DTONcToolModel.cs b/Step.Model/DTOModels/ToolModels/DTONcToolModel.cs
index 746e4bc7..2094e45e 100644
--- a/Step.Model/DTOModels/ToolModels/DTONcToolModel.cs
+++ b/Step.Model/DTOModels/ToolModels/DTONcToolModel.cs
@@ -37,7 +37,7 @@ namespace Step.Model.DTOModels.ToolModels
[Required]
public bool CounterClockwiseRotation { get; set; }
- public int? ShankId { get; set; }
+ public int? ShankId { get; set; } = null;
public static explicit operator DTONcTool(DbNcToolModel obj)
{
@@ -110,7 +110,7 @@ namespace Step.Model.DTOModels.ToolModels
{
Id = obj.ToolId,
FamilyId = obj.FamilyId,
- ShankId = obj.ShankId == null ? 0 : obj.ShankId.Value,
+ ShankId = obj.ShankId,
OffsetLength = obj.OffsetLength,
ResidualLife = obj.ResidualLife,
ResidualRevive = obj.ResidualRevive,
diff --git a/Step.Model/DatabaseModels/NcShankModel.cs b/Step.Model/DatabaseModels/NcShankModel.cs
index 8947ac63..43ec5582 100644
--- a/Step.Model/DatabaseModels/NcShankModel.cs
+++ b/Step.Model/DatabaseModels/NcShankModel.cs
@@ -26,7 +26,7 @@ namespace Step.Model.DatabaseModels
public DbNcMagazinePositionModel MagazinePosition { get; set; }
- public List Tools { get; set; }
+ public List Tools { get; set; }
public static explicit operator NcShankModel(DbNcShankModel obj)
{
diff --git a/Step.NC/NcHandler.cs b/Step.NC/NcHandler.cs
index ce25004d..5f8d0a3e 100644
--- a/Step.NC/NcHandler.cs
+++ b/Step.NC/NcHandler.cs
@@ -928,8 +928,13 @@ namespace Step.NC
{
config.FamilyOptionActive = false;
categories.Add("family");
+ config.ToolsConfiguration = config.ToolsConfiguration.Where(x => !(x.Name == "familyId")).ToList();
config.ToolsConfiguration = config.ToolsConfiguration.Concat(config.FamiliesConfiguration.FamilyConfiguration).ToList();
}
+ else
+ {
+ config.ToolsConfiguration = config.ToolsConfiguration.Concat(config.FamiliesConfiguration.FamilyReadOnlyConfiguration).ToList();
+ }
if (!ToolManagerConfig.OffsetOpt)
categories.Add("offset");
diff --git a/Step/Controllers/WebApi/NcToolManagerController.cs b/Step/Controllers/WebApi/NcToolManagerController.cs
index 2bd736cc..ecf2abe8 100644
--- a/Step/Controllers/WebApi/NcToolManagerController.cs
+++ b/Step/Controllers/WebApi/NcToolManagerController.cs
@@ -28,32 +28,27 @@ namespace Step.Controllers.WebApi
if (cmsError.IsError())
return BadRequest(cmsError.localizationKey);
- if (!ToolManagerConfig.FamilyOpt)
+ // If option is active, add family data to tools
+ using (NcToolManagerController toolsManager = new NcToolManagerController())
{
- // If option is active, add family data to tools
- using (NcToolManagerController toolsManager = new NcToolManagerController())
+ // Get families
+ List families = toolsManager.GetFamilies();
+
+ List toolsWithFamilies = new List();
+ // Create tool&family return objecs
+ foreach (var tool in tools)
{
- // Get families
- List families = toolsManager.GetFamilies();
-
- List toolsWithFamilies = new List();
- // Create tool&family return objecs
- foreach (var tool in tools)
- {
- toolsWithFamilies.Add
- (
- CreateToolAndFamilyObj( // Create return model with family data & tool data
- tool,
- families.Where(x => x.Id == tool.FamilyId).FirstOrDefault() // Find matching family
- )
- );
- }
-
- return Ok(toolsWithFamilies);
+ toolsWithFamilies.Add
+ (
+ CreateToolAndFamilyObj( // Create return model with family data & tool data
+ tool,
+ families.Where(x => x.Id == tool.FamilyId).FirstOrDefault() // Find matching family
+ )
+ );
}
- }
- return Ok(tools);
+ return Ok(toolsWithFamilies);
+ }
}
}
@@ -68,17 +63,29 @@ namespace Step.Controllers.WebApi
// Check if option is active
if (ToolManagerConfig.FamilyOpt)
{
- // Check if family exists
- DbNcFamilyModel fam = toolsManager.FindFamily(dtoToolWithFamily.FamilyId);
- if (fam == null)
- return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS);
+ if (dtoToolWithFamily.FamilyId == 0)
+ {
+ // If param equal to 0 create a new family
+ DTONewNcFamilyModel newFamily = new DTONewNcFamilyModel() { Name = "NewFamily" };
+ // Add new family & update family id
+ DbNcFamilyModel newFam = toolsManager.AddFamily(newFamily);
+ dtoToolWithFamily.FamilyId = newFam.FamilyId;
+ }
+ else
+ {
+ // Check if family exists
+ DbNcFamilyModel fam = toolsManager.FindFamily(dtoToolWithFamily.FamilyId);
+ if (fam == null)
+ return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS);
+ }
}
else
{
- // Copy only family data
+ // Copy only family data from tool&fam model
DTONewNcFamilyModel newFamily = new DTONewNcFamilyModel();
SupportFunctions.CopyProperties(dtoToolWithFamily, newFamily);
+ // Add new family
DbNcFamilyModel dbFam = toolsManager.AddFamily(newFamily);
if (dbFam == null)
return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS);
@@ -86,14 +93,7 @@ namespace Step.Controllers.WebApi
}
// Check if option is active
- if (ToolManagerConfig.ShankOpt)
- {
- // If option is active check if shank exists
- DbNcShankModel shank = toolsManager.FindShankWithTools(dtoToolWithFamily.ShankId.Value);
- if (shank == null)
- return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS);
- }
- else
+ if (!ToolManagerConfig.ShankOpt)
{
// If option is not active create a shank
DTONewNcShankModel newShank = new DTONewNcShankModel()
@@ -107,6 +107,8 @@ namespace Step.Controllers.WebApi
// Connect tool to new shank
dtoToolWithFamily.ShankId = ncShank.ShankId;
}
+ else
+ dtoToolWithFamily.ShankId = null;
}
using (NcHandler ncHandler = new NcHandler())
@@ -119,8 +121,8 @@ namespace Step.Controllers.WebApi
return Ok(CreateToolAndFamilyObj(newTool, dtoToolWithFamily));
}
}
-
- [Route("tool/{toolId:int}"), HttpPut]
+
+ [Route("tool/{toolId:int}"), HttpPut]
public IHttpActionResult PutTool(int toolId, [FromBody][Required]DTONewNcToolWithFamilyModel dtoToolWithFamily)
{
if (!ModelState.IsValid)
@@ -145,7 +147,7 @@ namespace Step.Controllers.WebApi
// If option is active
if (!ToolManagerConfig.FamilyOpt)
{
- // Copy only family
+ // Copy only family
DTONewNcFamilyModel newFamily = new DTONewNcFamilyModel();
SupportFunctions.CopyProperties(dtoToolWithFamily, newFamily);
// Update only family data
@@ -202,25 +204,27 @@ namespace Step.Controllers.WebApi
{
ncHandler.Connect();
+ CmsError cmsError;
if (!ToolManagerConfig.ShankOpt && tool.ShankId != null)
{
// If option is active find & delete tool shank
DbNcShankModel shank = toolsManager.FindShankWithTools(tool.ShankId.Value);
- CmsError cmsError = ncHandler.DeleteNcShank(shank.ShankId);
+ cmsError = ncHandler.DeleteNcShank(shank.ShankId);
if (cmsError.IsError())
return BadRequest(cmsError.localizationKey);
}
-
if (!ToolManagerConfig.FamilyOpt)
{
DbNcFamilyModel fam = toolsManager.FindFamily(tool.FamilyId);
- CmsError cmsError = ncHandler.DeleteNcFamily(fam);
+ cmsError = ncHandler.DeleteNcFamily(fam);
if (cmsError.IsError())
return BadRequest(cmsError.localizationKey);
}
- ncHandler.DeleteNcTool(tool);
+ cmsError = ncHandler.DeleteNcTool(tool);
+ if (cmsError.IsError())
+ return BadRequest(cmsError.localizationKey);
return Ok();
}
@@ -398,7 +402,7 @@ namespace Step.Controllers.WebApi
}
}
}
-
+
#endregion Families
#region Magazine positions
@@ -482,7 +486,7 @@ namespace Step.Controllers.WebApi
{
shanks = toolsManager.GetAvailableShanksWithoutChilds();
}
-
+
return Ok(shanks);
}
}
@@ -492,7 +496,7 @@ namespace Step.Controllers.WebApi
{
using (NcToolManagerController toolsManager = new NcToolManagerController())
{
- List tools = toolsManager.GetAvailableTools();
+ List tools = toolsManager.GetAvailableTools();
return Ok(tools);
}