public static int InsertOrUpdateT_WQX_REF_LAB(global::System.Int32? lAB_IDX, global::System.String lAB_NAME, string lAB_ACCRED_IND, string lAB_ACCRED_AUTHORITY, string oRG_ID, bool aCT_IND) { using (OpenEnvironmentEntities ctx = new OpenEnvironmentEntities()) { try { Boolean insInd = true; T_WQX_REF_LAB a = new T_WQX_REF_LAB(); if (ctx.T_WQX_REF_LAB.Any(o => o.LAB_IDX == lAB_IDX)) { //update case a = (from c in ctx.T_WQX_REF_LAB where c.LAB_IDX == lAB_IDX select c).FirstOrDefault(); insInd = false; } else { if (ctx.T_WQX_REF_LAB.Any(o => o.LAB_NAME == lAB_NAME && o.ORG_ID == oRG_ID)) { //update case a = (from c in ctx.T_WQX_REF_LAB where c.LAB_NAME == lAB_NAME && c.ORG_ID == oRG_ID select c).FirstOrDefault(); insInd = false; } } if (lAB_NAME != null) a.LAB_NAME = lAB_NAME; if (lAB_ACCRED_IND != null) a.LAB_ACCRED_IND = lAB_ACCRED_IND; if (lAB_ACCRED_AUTHORITY != null) a.LAB_ACCRED_AUTHORITY = lAB_ACCRED_AUTHORITY; if (oRG_ID != null) a.ORG_ID = oRG_ID; a.ACT_IND = aCT_IND; a.UPDATE_DT = System.DateTime.Now; if (insInd) //insert case { a.CREATE_DT = System.DateTime.Now; ctx.AddToT_WQX_REF_LAB(a); } ctx.SaveChanges(); return a.LAB_IDX; } catch (Exception ex) { return 0; } } }