diff --git a/Libs/CMS_CORE_Library.dll b/Libs/CMS_CORE_Library.dll index 6cc8eb0b..f69ef120 100644 Binary files a/Libs/CMS_CORE_Library.dll and b/Libs/CMS_CORE_Library.dll differ diff --git a/Step.Database/Controllers/NcToolManagerController.cs b/Step.Database/Controllers/NcToolManagerController.cs index 7f63ee49..3bee648d 100644 --- a/Step.Database/Controllers/NcToolManagerController.cs +++ b/Step.Database/Controllers/NcToolManagerController.cs @@ -1,5 +1,6 @@ using Step.Model.DatabaseModels; using Step.Model.DTOModels.ToolModels; +using Step.Utils; using System; using System.Collections.Generic; using System.Data.Entity; @@ -224,14 +225,16 @@ namespace Step.Database.Controllers public DbNcToolModel UpdateTool(int toolId, DTONewNcToolModel dtoTool) { DbNcToolModel tool = FindTool(toolId); + // Update db model - tool.FamilyId = dtoTool.FamilyId; - tool.OffsetLength = dtoTool.OffsetLength; - tool.ResidualLife = dtoTool.ResidualLife; - tool.ResidualRevive = dtoTool.ResidualRevive; - tool.OffsetId1 = dtoTool.OffsetId1; - tool.OffsetId2 = dtoTool.OffsetId2; - tool.OffsetId3 = dtoTool.OffsetId3; + SupportFunctions.CopyProperties(dtoTool, tool); + //tool.FamilyId = dtoTool.FamilyId; + //tool.OffsetLength = dtoTool.OffsetLength; + //tool.ResidualLife = dtoTool.ResidualLife; + //tool.ResidualRevive = dtoTool.ResidualRevive; + //tool.OffsetId1 = dtoTool.OffsetId1; + //tool.OffsetId2 = dtoTool.OffsetId2; + //tool.OffsetId3 = dtoTool.OffsetId3; // Save dbCtx.SaveChanges(); @@ -265,10 +268,10 @@ namespace Step.Database.Controllers public DbNcFamilyModel UpdateFamily(int familyId, DTONewNcFamilyModel family) { DbNcFamilyModel dbFamily = FindFamily(familyId); - dbFamily = (DbNcFamilyModel)family; + + SupportFunctions.CopyProperties(family, dbFamily); dbCtx.SaveChanges(); - dbCtx.Families.Attach(dbFamily); return dbFamily; } diff --git a/Step.NC/NcHandler.cs b/Step.NC/NcHandler.cs index dff1d34c..abc3af7a 100644 --- a/Step.NC/NcHandler.cs +++ b/Step.NC/NcHandler.cs @@ -1219,6 +1219,7 @@ namespace Step.NC { using (NcToolManagerController toolsManager = new NcToolManagerController()) { + StartEditData(); using (var dbContextTransaction = toolsManager.dbCtx.Database.BeginTransaction()) { // Update db family diff --git a/Step.Utils/supportFunctions.cs b/Step.Utils/supportFunctions.cs index 08613588..bc4477fc 100644 --- a/Step.Utils/supportFunctions.cs +++ b/Step.Utils/supportFunctions.cs @@ -1,4 +1,5 @@ -using static Step.Model.Constants; +using System.Reflection; +using static Step.Model.Constants; namespace Step.Utils { @@ -21,7 +22,6 @@ namespace Step.Utils case "SPINDLE": return HEAD_TYPE.SPINDLE; case "AWJ": return HEAD_TYPE.AWJ; default: return HEAD_TYPE.WJ; - } } @@ -66,16 +66,39 @@ namespace Step.Utils switch (unit) { case MAINTENANCE_UNIT_OF_MEASURE.mm: - return number; + return number; + case MAINTENANCE_UNIT_OF_MEASURE.H: - return number * 60; + return number * 60; + case MAINTENANCE_UNIT_OF_MEASURE.D: - return number * (24 * 60); + return number * (24 * 60); + case MAINTENANCE_UNIT_OF_MEASURE.M: - return (30 * number) * (24 * 60); + return (30 * number) * (24 * 60); + default: - return number; + return number; + } + } + + public static void CopyProperties(TParent parent, TChild child) where TParent : class where TChild : class + { + var parentProperties = parent.GetType().GetProperties(); + var childProperties = child.GetType().GetProperties(); + + foreach (var parentProperty in parentProperties) + { + foreach (var childProperty in childProperties) + { + if (parentProperty.Name == childProperty.Name && parentProperty.PropertyType == childProperty.PropertyType) + { + childProperty.SetValue(child, parentProperty.GetValue(parent)); + break; + } + } } } } -} + +} \ No newline at end of file