我有一个结果验证应用。将候选结果与某些API结果进行匹配,然后将数据填充到名为result的表中,并将候选数据插入具有状态列的候选表中。
因此,如果候选人的所有科目都等于“匹配”,则updateStatusOfCandidate(d.Candidate.CandidateNo,“ VERIFIED”);
enter code here
否则updateStatusOfCandidate(d.Candidate.CandidateNo,“未验证”);
private void Process()
{
//read the data from csv
List<CsvData> dataFromCsv = ReadCsvFile();
//if we dont get any data, lets return and sleep...
//if(dataFromCsv.Count < 1)
//{
// return;
//}
//lets save the data to the db
SaveCandidateData(dataFromCsv);
//now lets get the data, from the db, we are doing this because we will need the id of the students
List<Candidate> listFromDb = dbCtxt.Candidates.Where(c => c.Status == null).ToList();
List<CsvData> nonMatchedData = new List<CsvData>();
foreach(var l in listFromDb)
{
CsvData csvData = new CsvData();
csvData.Candidate = l;
csvData.Result = dbCtxt.Results.Where(c => c.CandidateNo.Trim() == l.CandidateNo.Trim()).ToList();
nonMatchedData.Add(csvData);
}
//loop through the data we have
foreach(var d in nonMatchedData)
{
//lets make the api call
var result = makeApiCall(d.Candidate.CandidateNo, Convert.ToInt32(d.Candidate.ExamDate), d.Candidate.ReferenceNo).Result;
if(result == null)
{
continue;
}
//lets convert the response to an object...
APIResults apiResults = JsonConvert.DeserializeObject<APIResults>(result);
//lets check the status of the result, 001 means its successful
if(apiResults.StatusCode != "001")
{
updateStatusOfCandidate(d.Candidate.CandidateNo, "NOT FOUND");
continue;
}
//lets do the compare it self
foreach(var s in apiResults.Result.SubjectCol)
{
//lets get the subject id, then use link to obtain the results...
int subId = getSubjectId(s.Subject);
if(subId == 0)
{
continue;
}
//since we have the subject id, lets check the data we have from the csv to be sure its there
var resultCsv = d.Result.Where(c => c.SubjectID == subId).FirstOrDefault();
//if the data is not there, we continue
if (resultCsv == null) continue;
//if the data exist, lets now match it with the data we have from the csv to be sure the correct grade is there
if (resultCsv.Grade.Trim().ToLower() != s.GradeScore.Trim().ToLower())
{
updateStatusOfResult(resultCsv.ResultID, "UNMATCHED");
//if the result do not match, lets now set the status of the result column to be unmatched...
}
else
{
updateStatusOfResult(resultCsv.ResultID, "MATCHED");
}
}
updateStatusOfCandidate(d.Candidate.CandidateNo, "COMPLETED");
}
}
答案 0 :(得分:0)
因此,如果我正确理解,您希望Candidate
表(由Result
标识)中的任何CandidateNo
的状态为Status
"Verified"
。而且,不在Candidate
表中的任何Result
的{{1}}为Status
吗?
您可以在"Unverified"
和Candidate
之间使用左联接来查找Result
中但不是Candidate
中的记录。
您可以在'候选'和'结果'之间使用内部联接来查找同时在Result
和Candidate
中的记录。
我假设Result
是dbCtxt
Entity Framework
,例如...
DbContext