Added import-export tool table

Added scada new image field "negate"
This commit is contained in:
Lucio Maranta
2019-03-28 13:03:35 +01:00
parent 723a6f956b
commit 3ae585b734
25 changed files with 292 additions and 42 deletions
@@ -549,5 +549,49 @@ namespace Step.Database.Controllers
dbCtx.SaveChanges();
}
public DTOExportToolTableModel GetExportData()
{
return new DTOExportToolTableModel
{
Tools = FindTools(),
Families = FindFamilies(),
Shanks = FindShanks()
};
}
public void ImportData(DTOExportToolTableModel data)
{
List<DbNcToolModel> tools = FindTools();
List<DbNcFamilyModel> families = FindFamilies();
List<DbNcShankModel> shanks = FindShanks();
// loop thought new families
foreach (var family in data.Families)
{
// Check if not exist
if (families.FirstOrDefault(x => x.FamilyId == family.FamilyId) == null)
dbCtx.Families.Add(family);
}
// loop thought new shanks
foreach (var shank in data.Shanks)
{
// Check if not exist
if (shanks.FirstOrDefault(x => x.ShankId == shank.ShankId) == null)
dbCtx.Shanks.Add(shank);
}
// loop thought new tools
foreach (var tool in data.Tools)
{
// Check if not exist
if (tools.FirstOrDefault(x => x.ToolId == tool.ToolId) == null)
dbCtx.Tools.Add(tool);
}
// Save
dbCtx.SaveChanges();
}
}
}