public int? AddRecordsToStagingMailList(int? fileUploadId, MailListImportModel importModel, string ClientConnectionString) { int recordId = 0; try { using (var connection = SqlHelperFactory.SqlHelper.GetConnection(ClientConnectionString)) { using (SqlCommand command = new SqlCommand("Etl.spStagingMailListAdd", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@FileID", fileUploadId); command.Parameters.AddWithValue("@TacticID", NullableInt(importModel.TacticID)); command.Parameters.AddWithValue("@IndividualID", NullableInt(importModel.IndividualID)); command.Parameters.AddWithValue("@FamilyID", NullableInt(importModel.FamilyID)); command.Parameters.AddWithValue("@PersonID", NullableInt(importModel.PersonID)); command.Parameters.AddWithValue("@FirstName", importModel.FirstName); command.Parameters.AddWithValue("@MiddleInitial", importModel.MiddleInitial); command.Parameters.AddWithValue("@LastName", importModel.LastName); command.Parameters.AddWithValue("@Company", importModel.Company); command.Parameters.AddWithValue("@Address", importModel.Address); command.Parameters.AddWithValue("@Adress2", importModel.Adress2); command.Parameters.AddWithValue("@City", importModel.City); command.Parameters.AddWithValue("@State", importModel.State); command.Parameters.AddWithValue("@ZipCode", importModel.ZipCode); command.Parameters.AddWithValue("@ZipFour", importModel.ZipFour); command.Parameters.AddWithValue("@AudienceStatus", importModel.AudienceStatus); using (var reader = command.ExecuteReader()) { while (reader.Read()) { recordId = reader.FieldToInt("RecordId"); } } } } } catch (Exception e) { recordId = -1; this.ErrorMsg = e.Message; } return recordId; }
private void UpdateStagingMailListTable() { var importModel = new MailListImportModel(); using (var reader = new StreamReader(this.importData)) { var oneRow = reader.ReadLine(); while ((oneRow = reader.ReadLine()) != null) { var rowArray = oneRow.Split('|'); try { importModel.TacticID = int.Parse(rowArray[0]); importModel.IndividualID = GetIntValue(rowArray[1]); importModel.FamilyID = GetIntValue(rowArray[2]); importModel.PersonID = GetIntValue(rowArray[3]); importModel.FirstName = rowArray[4]; importModel.MiddleInitial = rowArray[5]; importModel.LastName = rowArray[6]; importModel.Company = rowArray[7]; importModel.Address = rowArray[8]; importModel.Adress2 = rowArray[9]; importModel.City = rowArray[10]; importModel.State = rowArray[11]; importModel.ZipCode = rowArray[12]; importModel.ZipFour = rowArray[13]; importModel.AudienceStatus = rowArray[14]; this.dataProvider.AddRecordsToStagingMailList(this.fileId, importModel, this.ConnectionString); this.RecordsImported++; } catch (Exception e) { this.ErrorMsg = string.Format("Import error on line {0}: {1}", this.RecordsImported++, e.Message); this.RecordsImported = -1; throw; } } } }