public bool InsertCompanyAttach(List <MAS_COMPANYATTACHMENT> lData) { IDbConnection conn = null; bool ret = false; try { //SET CONNECTION conn = ConnectionFactory.GetConnection(); conn.ConnectionString = ConfigurationManager.GetConfiguration().DbConnectionString; //OPEN CONNECTION conn.Open(); Mas_BiddingCompanyBL bl = new Mas_BiddingCompanyBL(conn); /******* Inset table [tb_mas_CompanyAttachment] *******/ foreach (var item in lData) { MAS_COMPANYATTACHMENT data = new MAS_COMPANYATTACHMENT(); data = item; ret = bl.InsertCompanyAttachData(data); } /******************************************************/ } catch (Exception ex) { ret = false; logger.Error(ex.Message); logger.Error(ex.StackTrace); } finally { if (conn != null) { if (conn.State == ConnectionState.Open) { conn.Close(); } conn.Dispose(); } } return(ret); }
public bool UpdateCompanyAttach(List <MAS_COMPANYATTACHMENT> lData, string CompanyNo) { IDbConnection conn = null; IDbTransaction tran = null; bool ret = false; try { //SET CONNECTION conn = ConnectionFactory.GetConnection(); conn.ConnectionString = ConfigurationManager.GetConfiguration().DbConnectionString; //OPEN CONNECTION conn.Open(); tran = conn.BeginTransaction(IsolationLevel.Serializable); Mas_BiddingCompanyBL bl = new Mas_BiddingCompanyBL(conn, tran); /********** Delete CompanyAttach before Insert **********/ bool retDel = bl.DeleteCompanyAttachData(CompanyNo); /********************************************************/ /******* Inset table [tb_mas_CompanyAttachment] After delete *******/ if (retDel) { foreach (MAS_COMPANYATTACHMENT item in lData) { MAS_COMPANYATTACHMENT data = new MAS_COMPANYATTACHMENT(); data = item; ret = bl.InsertCompanyAttachData(data); } } /******************************************************/ tran.Commit(); } catch (Exception ex) { tran.Rollback(); ret = false; logger.Error(ex.Message); logger.Error(ex.StackTrace); } finally { if (tran != null) { tran.Dispose(); } if (conn != null) { if (conn.State == ConnectionState.Open) { conn.Close(); } conn.Dispose(); } } return(ret); }