public int InsertRecords(List<string> blacklistedSerials, LojackImportFileRecord importRecord, int counter) { using (var db = new LojackContext()) { DateTime date; var rep = new LojackEntryRepository(db); var lojack = new LojackEntry { computracefile = importRecord.CompuTraceFile, AgencyName = importRecord.AgencyName, DateReportedToABT = DateTime.TryParse(importRecord.DateReportedToAbt, out date) ? date : (DateTime?)null, Make = importRecord.Make.Length > 30 ? importRecord.Make.Remove(30) : importRecord.Make, Model = importRecord.Model.Length > 30 ? importRecord.Model.Remove(30) : importRecord.Model, StolenDate = DateTime.TryParse(importRecord.StolenDate, out date) ? date : (DateTime?)null }; if (importRecord.SerialNumber2 == importRecord.SerialNumber1 || importRecord.SerialNumber2 == importRecord.SerialNumber3) importRecord.SerialNumber2 = String.Empty; if (importRecord.SerialNumber3 == importRecord.SerialNumber1 || importRecord.SerialNumber3 == importRecord.SerialNumber2) importRecord.SerialNumber3 = String.Empty; int success = 0; for (int i = 1; i < 4; i++) { string serialNo = String.Empty; if (i == 1) serialNo = importRecord.SerialNumber1; if (i == 2) serialNo = importRecord.SerialNumber2; if (i == 3) serialNo = importRecord.SerialNumber3; if (!String.IsNullOrEmpty(serialNo) && !blacklistedSerials.Contains(serialNo)) { lojack.ReportedSerialNumber = serialNo; try { rep.Insert(lojack); ConsoleInsertSuccessMessage(counter + 1, lojack.computracefile, lojack.ReportedSerialNumber); success++; } catch (Exception) { ConsoleInsertFailureMessage(counter, lojack.computracefile, lojack.ReportedSerialNumber); } } } return success; } }
private LojackImportFileRecord LojackImportFileRecord(string[] line) { var importRecord = new LojackImportFileRecord(); importRecord.CompuTraceFile = line[0].Trim() ?? ""; importRecord.SerialNumber1 = line[1].Trim() ?? ""; importRecord.SerialNumber2 = line[2].Trim() ?? ""; importRecord.SerialNumber3 = line[3].Trim() ?? ""; importRecord.StolenDate = line[4].Trim() ?? ""; importRecord.DateReportedToAbt = line[5].Trim() ?? ""; importRecord.TheFtIncidentNumber = line[6].Trim() ?? ""; importRecord.AgencyName = line[7].Trim() ?? ""; importRecord.Make = line[8].Trim() ?? ""; importRecord.Model = line[9].Trim() ?? ""; return importRecord; }