public IEnumerable <RetName> Regis_Step_Three(insert_Step_Three item) { List <RetName> results = new List <RetName>(); try { using (Hr_RegisterDataContext bx = new Hr_RegisterDataContext()) { var str = (from xx in bx.STEP_THREE_DETAILs where xx.USERNO == item.USERNO select xx).FirstOrDefault(); int Status; if (str == null) { InsertData_Three(item); Status = 1; } else { UpdateData_Three(item); InsertData_Three(item); Status = 2; } RetName res = new RetName(); res.status = "S"; if (Status == 1) { res.message = "Insert success"; } else if (Status == 2) { res.message = "Update success"; } res.USERNO = item.USERNO; results.Add(res); } } catch (Exception ex) { RetName res = new RetName(); res.status = "F"; res.message = ex.Message; results.Add(res); } return(results.ToArray()); }
private string UpdateData_Three(insert_Step_Three item) { string USERNO; using (Hr_RegisterDataContext bx = new Hr_RegisterDataContext()) { try { var value_Eduction = (from xx in bx.STEP_THREE_EDUCTIONs where xx.USERNO == item.USERNO select xx); foreach (var ux in value_Eduction) { bx.STEP_THREE_EDUCTIONs.DeleteOnSubmit(ux); } bx.SubmitChanges(); //---------------------------------------------------------------------------------- var value_Training = (from xx in bx.STEP_THREE_TRAININGs where xx.USERNO == item.USERNO select xx); foreach (var ux in value_Training) { bx.STEP_THREE_TRAININGs.DeleteOnSubmit(ux); } bx.SubmitChanges(); //---------------------------------------------------------------------------------- //STEP_THREE_DETAIL value_Detail = new STEP_THREE_DETAIL(); var value_Detail = (from xx in bx.STEP_THREE_DETAILs where xx.USERNO == item.USERNO select xx).FirstOrDefault(); bx.STEP_THREE_DETAILs.DeleteOnSubmit(value_Detail); bx.SubmitChanges(); //---------------------------------------------------------------------------------- //List<Step_Three_LANGUAGE> Language = new List<Step_Three_LANGUAGE>(); var value_Language = (from xx in bx.STEP_THREE_LANGUAGEs where xx.USERNO == item.USERNO select xx); foreach (var ux in value_Language) { bx.STEP_THREE_LANGUAGEs.DeleteOnSubmit(ux); } bx.SubmitChanges(); //---------------------------------------------------------------------------------- //List<Step_Three_EMPLOYMENT> Employment = new List<Step_Three_EMPLOYMENT>(); var value_Employment = (from xx in bx.STEP_THREE_EMPLOYMENTs where xx.USERNO == item.USERNO select xx); foreach (var ux in value_Employment) { bx.STEP_THREE_EMPLOYMENTs.DeleteOnSubmit(ux); } bx.SubmitChanges(); } catch (Exception ex) { throw new ArgumentException( $"{ex.Message} "); } } //} return(USERNO = item.USERNO); }
private string InsertData_Three(insert_Step_Three item) { string USERNO; using (TransactionScope ts = new TransactionScope()) { using (Hr_RegisterDataContext bx = new Hr_RegisterDataContext()) { try { USERNO = item.USERNO; var Step_Three_Training = new STEP_THREE_TRAINING(); var Step_Three_Language = new STEP_THREE_LANGUAGE(); var Step_Three_Employment = new STEP_THREE_EMPLOYMENT(); var Step_Three_Detail = new STEP_THREE_DETAIL(); //---------------------------------------------------------------------------------- //List<Step_Three_EDUCTION> Eduction = new List<Step_Three_EDUCTION>(); foreach (var ux in item.Eduction) { STEP_THREE_EDUCTION value_Eduction = new STEP_THREE_EDUCTION(); value_Eduction.USERNO = item.USERNO; value_Eduction.EDUCATION_LV = ux.EDUCATION_LV; value_Eduction.EDUCATION_NAME = ux.EDUCATION_NAME; value_Eduction.DEGREE = ux.DEGREE; value_Eduction.S_YEAR = ux.S_YEAR; value_Eduction.E_YEAR = ux.E_YEAR; value_Eduction.GPA = ux.GPA; value_Eduction.MAJOR = ux.MAJOR; value_Eduction.FLAG = 0; bx.STEP_THREE_EDUCTIONs.InsertOnSubmit(value_Eduction); bx.SubmitChanges(); } //---------------------------------------------------------------------------------- //List<Step_Three_TRAINING> Training = new List<Step_Three_TRAINING>(); foreach (var ux in item.Training) { STEP_THREE_TRAINING value_Training = new STEP_THREE_TRAINING(); value_Training.USERNO = item.USERNO; value_Training.DATE = ux.DATE.AddYears(543); value_Training.COURSE = ux.COURSE; value_Training.INSTITUTION = ux.INSTITUTION; value_Training.S_DATE = ux.S_DATE.AddYears(543); value_Training.E_DATE = ux.E_DATE.AddYears(543); value_Training.FLAG = 0; bx.STEP_THREE_TRAININGs.InsertOnSubmit(value_Training); bx.SubmitChanges(); } //---------------------------------------------------------------------------------- STEP_THREE_DETAIL value_Detail = new STEP_THREE_DETAIL(); value_Detail.USERNO = item.USERNO; value_Detail.STUDY_NAME = item.Detail.STUDY_NAME; value_Detail.STUDY_MAJOR = item.Detail.STUDY_MAJOR; value_Detail.HOBBY_ROW1 = item.Detail.HOBBY_ROW1; value_Detail.HOBBY_ROW2 = item.Detail.HOBBY_ROW2; value_Detail.HOBBY_ROW3 = item.Detail.HOBBY_ROW3; value_Detail.HOBBY_ROW4 = item.Detail.HOBBY_ROW4; value_Detail.FLAG = 0; bx.STEP_THREE_DETAILs.InsertOnSubmit(value_Detail); bx.SubmitChanges(); //---------------------------------------------------------------------------------- //List<Step_Three_LANGUAGE> Language = new List<Step_Three_LANGUAGE>(); foreach (var ux in item.Language) { STEP_THREE_LANGUAGE value_Language = new STEP_THREE_LANGUAGE(); value_Language.USERNO = item.USERNO; value_Language.LANGUAGE = ux.LANGUAGE; value_Language.SPEAKING = ux.SPEAKING; value_Language.READING = ux.READING; value_Language.WRITING = ux.WRITING; value_Language.FLAG = 0; bx.STEP_THREE_LANGUAGEs.InsertOnSubmit(value_Language); bx.SubmitChanges(); } //---------------------------------------------------------------------------------- //List<Step_Three_EMPLOYMENT> Employment = new List<Step_Three_EMPLOYMENT>(); foreach (var ux in item.Employment) { STEP_THREE_EMPLOYMENT value_Employment = new STEP_THREE_EMPLOYMENT(); value_Employment.USERNO = item.USERNO; value_Employment.COMPANY_NAME = ux.COMPANY_NAME; value_Employment.S_DATE = ux.S_DATE; value_Employment.E_DATE = ux.E_DATE; value_Employment.POSITION = ux.POSITION; value_Employment.DETAIL = ux.DETAIL; value_Employment.LEAVING = ux.LEAVING; value_Employment.FLAG = 0; bx.STEP_THREE_EMPLOYMENTs.InsertOnSubmit(value_Employment); bx.SubmitChanges(); } ts.Complete(); } catch (Exception ex) { throw new ArgumentException( $"{ex.Message} "); } } } return(USERNO); }