public bool SaveInterviewResult() { bool result = true; if (ImportObjects.ContainsKey(UserID)) { using (var context = new VnrHrmDataContext()) { IUnitOfWork unitOfWork = new UnitOfWork(context); var dtImportObject = ImportObjects[UserID]; var dtInterview = new DataTable("Rec_Interview"); dtInterview.Columns.Add("ID", typeof(Guid)); dtInterview.Columns.Add("CandidateID", typeof(Guid)); dtInterview.Columns.Add("JobVacancyID", typeof(Guid)); dtInterview.Columns.Add("LanguageID", typeof(Guid)); dtInterview.Columns.Add("GroupConditionID", typeof(Guid)); dtInterview.Columns.Add("RecruitmentHistoryID", typeof(Guid)); dtInterview.Columns.Add("Score", typeof(double)); dtInterview.Columns.Add("Score1", typeof(double)); dtInterview.Columns.Add("Score2", typeof(double)); dtInterview.Columns.Add("ResultInterview", typeof(string)); dtInterview.Columns.Add("LevelInterview", typeof(int)); var dtCandidate = new DataTable("Rec_Candidate"); dtCandidate.Columns.Add("ID", typeof(Guid)); dtCandidate.Columns.Add("Status", typeof(string)); var dtHisstorry = new DataTable("Rec_RecruitmentHistory"); dtHisstorry.Columns.Add("ID", typeof(Guid)); dtHisstorry.Columns.Add("Status", typeof(string)); foreach (DataRow importRow in dtImportObject.Rows) { var candidateStatus = EnumDropDown.CandidateStatus.E_PASS; var candidateID = importRow["CandidateID"]; object groupResult = null; if (!importRow.IsNull(FieldMappings["GroupResult1"])) { groupResult = importRow[FieldMappings["GroupResult1"]]; DataRow interviewRow1 = dtInterview.NewRow(); dtInterview.Rows.Add(interviewRow1); interviewRow1.SetField("ID", Guid.NewGuid()); var interviewID = importRow["InterviewID1"]; if (interviewID != null && interviewID.IsTypeOf(typeof(Guid))) { if (interviewID.GetString() != Guid.Empty.ToString()) { interviewRow1.SetField("ID", interviewID); interviewRow1.AcceptChanges();//update mode } } interviewRow1.SetField("CandidateID", candidateID); interviewRow1.SetField("GroupConditionID", importRow["GroupConditionID1"]); interviewRow1.SetField("RecruitmentHistoryID", importRow["RecruitmentHistoryID"]); interviewRow1.SetField("Score", importRow[FieldMappings["Group1Score1"]]); interviewRow1.SetField("Score1", importRow[FieldMappings["Group1Score2"]]); interviewRow1.SetField("Score2", importRow[FieldMappings["Group1Score3"]]); interviewRow1.SetField("ResultInterview", groupResult); interviewRow1.SetField("LevelInterview", 1); if (!importRow.IsNull("JobVacancyID")) { interviewRow1.SetField("JobVacancyID", importRow["JobVacancyID"]); } if (!importRow.IsNull("LanguageID")) { interviewRow1.SetField("LanguageID", importRow["LanguageID"]); } if (groupResult.GetString() == EnumDropDown.CandidateStatus.E_FAIL.ToString()) { candidateStatus = EnumDropDown.CandidateStatus.E_FAIL; } } if (!importRow.IsNull(FieldMappings["GroupResult2"])) { groupResult = importRow[FieldMappings["GroupResult2"]]; DataRow interviewRow2 = dtInterview.NewRow(); dtInterview.Rows.Add(interviewRow2); interviewRow2.SetField("ID", Guid.NewGuid()); var interviewID = importRow["InterviewID2"]; if (interviewID != null && interviewID.IsTypeOf(typeof(Guid))) { if (interviewID.GetString() != Guid.Empty.ToString()) { interviewRow2.SetField("ID", interviewID); interviewRow2.AcceptChanges();//update mode } } interviewRow2.SetField("CandidateID", candidateID); interviewRow2.SetField("GroupConditionID", importRow["GroupConditionID2"]); interviewRow2.SetField("RecruitmentHistoryID", importRow["RecruitmentHistoryID"]); interviewRow2.SetField("Score", importRow[FieldMappings["Group2Score1"]]); interviewRow2.SetField("Score1", importRow[FieldMappings["Group2Score2"]]); interviewRow2.SetField("Score2", importRow[FieldMappings["Group2Score3"]]); interviewRow2.SetField("ResultInterview", groupResult); interviewRow2.SetField("LevelInterview", 2); if (!importRow.IsNull("JobVacancyID")) { interviewRow2.SetField("JobVacancyID", importRow["JobVacancyID"]); } if (!importRow.IsNull("LanguageID")) { interviewRow2.SetField("LanguageID", importRow["LanguageID"]); } if (groupResult.GetString() == EnumDropDown.CandidateStatus.E_FAIL.ToString()) { candidateStatus = EnumDropDown.CandidateStatus.E_FAIL; } } if (!importRow.IsNull(FieldMappings["GroupResult3"])) { groupResult = importRow[FieldMappings["GroupResult3"]]; DataRow interviewRow3 = dtInterview.NewRow(); dtInterview.Rows.Add(interviewRow3); interviewRow3.SetField("ID", Guid.NewGuid()); var interviewID = importRow["InterviewID3"]; if (interviewID != null && interviewID.IsTypeOf(typeof(Guid))) { if (interviewID.GetString() != Guid.Empty.ToString()) { interviewRow3.SetField("ID", interviewID); interviewRow3.AcceptChanges();//update mode } } interviewRow3.SetField("CandidateID", candidateID); interviewRow3.SetField("GroupConditionID", importRow["GroupConditionID3"]); interviewRow3.SetField("RecruitmentHistoryID", importRow["RecruitmentHistoryID"]); interviewRow3.SetField("Score", importRow[FieldMappings["Group3Score1"]]); interviewRow3.SetField("Score1", importRow[FieldMappings["Group3Score2"]]); interviewRow3.SetField("Score2", importRow[FieldMappings["Group3Score3"]]); interviewRow3.SetField("ResultInterview", groupResult); interviewRow3.SetField("LevelInterview", 3); if (!importRow.IsNull("JobVacancyID")) { interviewRow3.SetField("JobVacancyID", importRow["JobVacancyID"]); } if (!importRow.IsNull("LanguageID")) { interviewRow3.SetField("LanguageID", importRow["LanguageID"]); } if (groupResult.GetString() == EnumDropDown.CandidateStatus.E_FAIL.ToString()) { candidateStatus = EnumDropDown.CandidateStatus.E_FAIL; } } if (!importRow.IsNull(FieldMappings["GroupResult4"])) { groupResult = importRow[FieldMappings["GroupResult4"]]; DataRow interviewRow4 = dtInterview.NewRow(); dtInterview.Rows.Add(interviewRow4); interviewRow4.SetField("ID", Guid.NewGuid()); var interviewID = importRow["InterviewID4"]; if (interviewID != null && interviewID.IsTypeOf(typeof(Guid))) { if (interviewID.GetString() != Guid.Empty.ToString()) { interviewRow4.SetField("ID", interviewID); interviewRow4.AcceptChanges();//update mode } } interviewRow4.SetField("CandidateID", candidateID); interviewRow4.SetField("GroupConditionID", importRow["GroupConditionID4"]); interviewRow4.SetField("RecruitmentHistoryID", importRow["RecruitmentHistoryID"]); interviewRow4.SetField("Score", importRow[FieldMappings["Group4Score1"]]); interviewRow4.SetField("Score1", importRow[FieldMappings["Group4Score2"]]); interviewRow4.SetField("Score2", importRow[FieldMappings["Group4Score3"]]); interviewRow4.SetField("ResultInterview", groupResult); interviewRow4.SetField("LevelInterview", 4); if (!importRow.IsNull("JobVacancyID")) { interviewRow4.SetField("JobVacancyID", importRow["JobVacancyID"]); } if (!importRow.IsNull("LanguageID")) { interviewRow4.SetField("LanguageID", importRow["LanguageID"]); } if (groupResult.GetString() == EnumDropDown.CandidateStatus.E_FAIL.ToString()) { candidateStatus = EnumDropDown.CandidateStatus.E_FAIL; } } if (!importRow.IsNull(FieldMappings["GroupResult5"])) { groupResult = importRow[FieldMappings["GroupResult5"]]; DataRow interviewRow5 = dtInterview.NewRow(); dtInterview.Rows.Add(interviewRow5); interviewRow5.SetField("ID", Guid.NewGuid()); var interviewID = importRow["InterviewID5"]; if (interviewID != null && interviewID.IsTypeOf(typeof(Guid))) { if (interviewID.GetString() != Guid.Empty.ToString()) { interviewRow5.SetField("ID", interviewID); interviewRow5.AcceptChanges();//update mode } } interviewRow5.SetField("CandidateID", candidateID); interviewRow5.SetField("GroupConditionID", importRow["GroupConditionID5"]); interviewRow5.SetField("RecruitmentHistoryID", importRow["RecruitmentHistoryID"]); interviewRow5.SetField("Score", importRow[FieldMappings["Group5Score1"]]); interviewRow5.SetField("Score1", importRow[FieldMappings["Group5Score2"]]); interviewRow5.SetField("Score2", importRow[FieldMappings["Group5Score3"]]); interviewRow5.SetField("ResultInterview", groupResult); interviewRow5.SetField("LevelInterview", 5); if (!importRow.IsNull("JobVacancyID")) { interviewRow5.SetField("JobVacancyID", importRow["JobVacancyID"]); } if (!importRow.IsNull("LanguageID")) { interviewRow5.SetField("LanguageID", importRow["LanguageID"]); } if (groupResult.GetString() == EnumDropDown.CandidateStatus.E_FAIL.ToString()) { candidateStatus = EnumDropDown.CandidateStatus.E_FAIL; } } if (!importRow.IsNull(FieldMappings["GroupResult6"])) { groupResult = importRow[FieldMappings["GroupResult6"]]; DataRow interviewRow6 = dtInterview.NewRow(); dtInterview.Rows.Add(interviewRow6); interviewRow6.SetField("ID", Guid.NewGuid()); var interviewID = importRow["InterviewID6"]; if (interviewID != null && interviewID.IsTypeOf(typeof(Guid))) { if (interviewID.GetString() != Guid.Empty.ToString()) { interviewRow6.SetField("ID", interviewID); interviewRow6.AcceptChanges();//update mode } } interviewRow6.SetField("CandidateID", candidateID); interviewRow6.SetField("GroupConditionID", importRow["GroupConditionID6"]); interviewRow6.SetField("RecruitmentHistoryID", importRow["RecruitmentHistoryID"]); interviewRow6.SetField("Score", importRow[FieldMappings["Group6Score1"]]); interviewRow6.SetField("Score1", importRow[FieldMappings["Group6Score2"]]); interviewRow6.SetField("Score2", importRow[FieldMappings["Group6Score3"]]); interviewRow6.SetField("ResultInterview", groupResult); interviewRow6.SetField("LevelInterview", 6); if (!importRow.IsNull("JobVacancyID")) { interviewRow6.SetField("JobVacancyID", importRow["JobVacancyID"]); } if (!importRow.IsNull("LanguageID")) { interviewRow6.SetField("LanguageID", importRow["LanguageID"]); } if (groupResult.GetString() == EnumDropDown.CandidateStatus.E_FAIL.ToString()) { candidateStatus = EnumDropDown.CandidateStatus.E_FAIL; } } if (!importRow.IsNull(FieldMappings["GroupResult7"])) { groupResult = importRow[FieldMappings["GroupResult7"]]; DataRow interviewRow7 = dtInterview.NewRow(); dtInterview.Rows.Add(interviewRow7); interviewRow7.SetField("ID", Guid.NewGuid()); var interviewID = importRow["InterviewID7"]; if (interviewID != null && interviewID.IsTypeOf(typeof(Guid))) { if (interviewID.GetString() != Guid.Empty.ToString()) { interviewRow7.SetField("ID", interviewID); interviewRow7.AcceptChanges();//update mode } } interviewRow7.SetField("CandidateID", candidateID); interviewRow7.SetField("GroupConditionID", importRow["GroupConditionID7"]); interviewRow7.SetField("RecruitmentHistoryID", importRow["RecruitmentHistoryID"]); interviewRow7.SetField("Score", importRow[FieldMappings["Group7Score1"]]); interviewRow7.SetField("Score1", importRow[FieldMappings["Group7Score2"]]); interviewRow7.SetField("Score2", importRow[FieldMappings["Group7Score3"]]); interviewRow7.SetField("ResultInterview", groupResult); interviewRow7.SetField("LevelInterview", 7); if (!importRow.IsNull("JobVacancyID")) { interviewRow7.SetField("JobVacancyID", importRow["JobVacancyID"]); } if (!importRow.IsNull("LanguageID")) { interviewRow7.SetField("LanguageID", importRow["LanguageID"]); } if (groupResult.GetString() == EnumDropDown.CandidateStatus.E_FAIL.ToString()) { candidateStatus = EnumDropDown.CandidateStatus.E_FAIL; } } if (groupResult != null) { DataRow candidateRow = dtCandidate.NewRow(); dtCandidate.Rows.Add(candidateRow); candidateRow.AcceptChanges();//Chuyển qua update candidateRow.SetField("ID", candidateID); candidateRow.SetField("Status", candidateStatus.ToString()); var historyID = importRow["RecruitmentHistoryID"]; if (historyID != null && historyID.IsTypeOf(typeof(Guid))) { if (historyID.GetString() != Guid.Empty.ToString()) { DataRow hisstorryRow = dtHisstorry.NewRow(); dtHisstorry.Rows.Add(hisstorryRow); hisstorryRow.AcceptChanges();//Chuyển qua update hisstorryRow.SetField("ID", historyID); hisstorryRow.SetField("Status", candidateStatus.ToString()); } } } } using (DbCommander commander = new DbCommander(context.Database.Connection)) { var transaction = commander.BeginTransaction(); try { var resultCount = commander.ExecuteBatch(transaction, dtInterview); resultCount = commander.UpdateTable(transaction, dtCandidate); resultCount = commander.UpdateTable(transaction, dtHisstorry); transaction.Commit(); } catch (Exception) { result = false; transaction.Rollback(); throw; } } } } if (result) { if (ImportObjects.ContainsKey(UserID)) { ImportObjects[UserID] = null; ImportObjects.Remove(UserID); } if (InvalidObjects.ContainsKey(UserID)) { InvalidObjects[UserID] = null; InvalidObjects.Remove(UserID); } } return result; }