public bool InsertEmpAndPhone(EmployeeEntity employee, ICollection <EMPLOYEE_PHONE> list, string UPDATEDATA) { string sql = @"sp_employee_INSERT"; string sql_phone = @"sp_empAndPhone_INSERT"; string retID = ""; if (UPDATEDATA.Equals("INSERT")) { using (TransactionScope ts = new TransactionScope()) { retID = Db.InsertReturnID(sql, Take(employee)); if (retID != null) { if (list.Count() == 0) { object[] obj = { "@PhoneNumber", "XXXXXXXXXX" }; Db.Insert(sql_phone, obj); } else { foreach (var ls in list) { object[] obj = { "@EmpID", retID, "@PhoneNumber", ls.Phone }; try { Db.Insert(sql_phone, obj); } catch { return(false); } } } ts.Complete(); return(true); } else { return(false); } } } else if (UPDATEDATA.Equals("UPDATE")) { string sql_emp = @"sp_employee_UPDATE"; string sql_upd = @"sp_empAndPhone_UPDATE"; string sql_del = @"sp_empAndPhone_DELETE"; using (TransactionScope ts = new TransactionScope()) {// UPDATE พนักงาน Db.Update(sql_emp, Take2(employee)); // ลบ และ สร้าง เบอร์ใหม่ เพื่อ อัพเดท object[] del = { "@EmpID", employee.EmpID }; Db.Delete(sql_del, del); { foreach (var ls in list) { object[] obj = { "@EmpID", employee.EmpID, "@Phone", ls.Phone }; try { Db.Insert(sql_upd, obj); } catch { return(false); } } ts.Complete(); return(true); } } } return(false); }