public string[] ParseLine(string line, int lineIndex) { string[] dataArray = line.Split(",", StringSplitOptions.RemoveEmptyEntries); if (dataArray == null || dataArray.Length < 3) { string problemString = String.Format(ProblemTextPrefix, lineIndex + 1); FailedImportsInfo.Add(problemString + "Malformed data input"); return(null); } return(dataArray); }
public StudentSubject ParseLineData(string[] dataArray, int lineIndex) { if (Api == null) { throw new Exception("Api must be set"); } long studentId = long.Parse(dataArray[0].Trim()); long subjectId = long.Parse(dataArray[1].Trim()); int score = Int32.Parse(dataArray[2].Trim()); bool isValidStudentId = Api.StudentExists(studentId); bool isValidSubjectId = Api.SubjectExists(subjectId); StudentSubject existingStudentSubject = Api.GetStudentSubject(studentId, subjectId); string problemString = String.Format(ProblemTextPrefix, lineIndex + 1); if (!isValidStudentId || !isValidSubjectId) { if (!isValidStudentId) { problemString += "No student with id " + studentId + "."; } if (!isValidSubjectId) { problemString += "No subject with id " + subjectId + "."; } FailedImportsInfo.Add(problemString); } else { if (existingStudentSubject == null) { problemString += "Student with id " + studentId + " is not enrolled in class with id " + subjectId; FailedImportsInfo.Add(problemString); } else { existingStudentSubject = Api.SaveStudentSubjectScore(studentId, subjectId, score); SuccessfulImportsCount++; } } return(existingStudentSubject); }