public bool Update <T>(List <T> entities) { bool returnValue = false; foreach (T entity in entities) { if ((entity as TOOL_ISSUES).IsNotNullOrEmpty()) { TOOL_ISSUES obj = null; TOOL_ISSUES activeEntity = (entity as TOOL_ISSUES); obj = (from row in DB.TOOL_ISSUES where row.TOOL_CD == activeEntity.TOOL_CD && row.ISSUE_NO == activeEntity.ISSUE_NO select row).SingleOrDefault <TOOL_ISSUES>(); if (obj.IsNotNullOrEmpty()) { try { obj.TOOL_CD = activeEntity.TOOL_CD; obj.ISSUE_NO = activeEntity.ISSUE_NO; obj.ISSUE_DATE = activeEntity.ISSUE_DATE; obj.ALTERATIONS = activeEntity.ALTERATIONS; obj.INTL = activeEntity.INTL; DB.SubmitChanges(); System.Data.Linq.ChangeSet cs = DB.GetChangeSet(); returnValue = cs.Updates.Count > 0 ? true : false; returnValue = true; } catch (System.Data.Linq.ChangeConflictException) { foreach (System.Data.Linq.ObjectChangeConflict conflict in DB.ChangeConflicts) { conflict.Resolve(System.Data.Linq.RefreshMode.KeepChanges); } } catch (Exception ex) { ex.LogException(); DB.TOOL_ISSUES.Context.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, obj); } } else { returnValue = Delete <TOOL_ISSUES>(new List <TOOL_ISSUES> { activeEntity }); returnValue = Insert <TOOL_ISSUES>(new List <TOOL_ISSUES> { activeEntity }); } } } returnValue = true; return(returnValue); }
public bool Insert <T>(List <T> entities) { bool returnValue = false; foreach (T entity in entities) { if ((entity as TOOL_ISSUES).IsNotNullOrEmpty()) { TOOL_ISSUES obj = entity as TOOL_ISSUES; try { if (!obj.TOOL_CD.IsNotNullOrEmpty()) { obj.TOOL_CD = GenerateNextNumber("TOOL_ISSUES", "TOOL_CD"); } DB.TOOL_ISSUES.InsertOnSubmit(obj); DB.SubmitChanges(); System.Data.Linq.ChangeSet cs = DB.GetChangeSet(); returnValue = cs.Inserts.Count > 0 ? true : false; } catch (System.Data.Linq.ChangeConflictException) { foreach (System.Data.Linq.ObjectChangeConflict conflict in DB.ChangeConflicts) { conflict.Resolve(System.Data.Linq.RefreshMode.KeepChanges); } } catch (Exception ex) { ex.LogException(); DB.TOOL_ISSUES.DeleteOnSubmit(obj); } } } returnValue = true; return(returnValue); }