public int AddNew(ItemDTO dtoItem, List <ItemProcessDTO> NewProcess, List <BOMDTO> NewComponent, List <ItemMachineDTO> NewItemMachine) { ItemValidator validator = new ItemValidator(); validator.ValidateBeforeSaveNew(dtoItem, null); Database db = CommonLib.Common.CurrentDatabase; db.KeepConnection = true; db.BeginTransaction(); try { ItemDAO daoItem = new ItemDAO(CommonLib.Common.CurrentDatabase); daoItem.AddNew(null, dtoItem); ItemProcessDAO daoItemProcess = new ItemProcessDAO(CommonLib.Common.CurrentDatabase); BOMDAO daoBOM = new BOMDAO(CommonLib.Common.CurrentDatabase); ItemMachineDAO daoItemMachine = new ItemMachineDAO(CommonLib.Common.CurrentDatabase); foreach (ItemProcessDTO dto in NewProcess) { daoItemProcess.AddNew(null, dto); } //Component foreach (BOMDTO dto in NewComponent) { daoBOM.AddNew(null, dto); } //Item Machine foreach (ItemMachineDTO dto in NewItemMachine) { daoItemMachine.AddNew(null, dto); } db.Commit(); return(1); } catch (Exception err) { db.Rollback(); throw err; } finally { if (db.DBConnectionState == ConnectionState.Open) { db.Close(); } } }