public void WriteHeader(PrismCustomerInfoContext context, TypeCustomerInfoFile file) { var line = string.Format("HDR|MTCRCustomerInformation|{0}|{1}", file.FileNumber, file.CrDuns); context.AppendLine(line); }
public void When_Parsing_Customer_Info_Error_With_Field_Zero_Equal_To_ER1_Then_Record_Type_Id_Is_Set_To_One() { // arrange const int expected = 1; var context = new PrismCustomerInfoContext(); var fileModel = new TypeCustomerInfoFile(); context.PushModel(fileModel); var fields = new[] { "ER1", "", "PREMNO", "" }; // act concern.ParseError(context, fields); context.ResolveToFile(); // assert var results = context.Results; var collection = results.TypeHeaders; var model = collection.First(); var errors = model.ErrorRecords; Assert.AreEqual(1, errors.Length); var error = errors[0]; Assert.AreEqual(expected, error.RecordTypeId); Assert.IsNull(error.FieldName); }
public void SaveHeader(TypeCustomerInfoFile file) { logger.Trace("Start inserting customer info file."); var fileKey = clientDataAccess.InsertFile(file); logger.DebugFormat("Inserted Customer Billing File \"{0}\".", fileKey); foreach (var errorRecord in file.ErrorRecords) { errorRecord.FileId = fileKey; var errorKey = clientDataAccess.InsertErrorRecord(errorRecord); logger.DebugFormat("Inserted Error Record \"{0}\" for Customer Billing File \"{1}\".", errorKey, fileKey); } logger.Trace("Completed inserting customer info file."); }
public TypeCustomerInfoFile[] ListCustomerInfoReadyForTransmission() { using (var connection = new SqlConnection(connectionString)) using (var command = connection.CreateCommand("esp_CustomerBillingFileListByStatus")) { // Status Id 3 => Ready For Transmission command.AddWithValue("@StatusID", 3); if (connection.State != ConnectionState.Open) { connection.Open(); } var collection = new List <TypeCustomerInfoFile>(); using (var reader = command.ExecuteReader()) { while (reader.Read()) { var item = new TypeCustomerInfoFile { Direction = false, CrDuns = reader.GetString("CRDuns"), CspDunsId = reader.GetInt32("CSPDUNSID"), FileId = reader.GetInt32("CustomerBillingFileID"), FileTypeId = reader.GetInt32("TypeID"), Status = (CustomerInfoFileStatusOptions)reader.GetInt32("StatusID"), ErrorCount = reader.GetInt32("ErrorCount"), RecordCount = reader.GetInt32("RecordCount"), }; reader.TryGetString("CustomerBillingFileNumber", x => item.FileNumber = x); reader.TryGetString("CustomerBillingFileReferenceNumber", x => item.ReferenceNumber = x); reader.TryGetString("FileName", x => item.FileName = x); reader.TryGetDateTime("StatusDate", x => item.StatusDate = x); reader.TryGetDateTime("CreateDate", x => item.CreateDate = x); reader.TryGetInt32("UserID", x => item.UserId = x); collection.Add(item); } return(collection.ToArray()); } } }
public TypeCustomerInfoFile LoadCustomerInfoFile(int fileId) { using (var connection = new SqlConnection(connectionString)) using (var command = connection.CreateCommand("esp_CustomerBillingFileLoad")) { command.AddWithValue("@CustomerBillingFileID", fileId); if (connection.State != ConnectionState.Open) { connection.Open(); } using (var reader = command.ExecuteReader()) { if (!reader.Read()) { return(null); } var item = new TypeCustomerInfoFile { Direction = false, CrDuns = reader.GetString("CRDuns"), CspDunsId = reader.GetInt32("CSPDUNSID"), FileId = reader.GetInt32("CustomerBillingFileID"), FileTypeId = reader.GetInt32("TypeID"), Status = (CustomerInfoFileStatusOptions)reader.GetInt32("StatusID"), ErrorCount = reader.GetInt32("ErrorCount"), RecordCount = reader.GetInt32("RecordCount"), }; reader.TryGetString("CustomerBillingFileNumber", x => item.FileNumber = x); reader.TryGetString("CustomerBillingFileReferenceNumber", x => item.ReferenceNumber = x); reader.TryGetString("FileName", x => item.FileName = x); reader.TryGetDateTime("StatusDate", x => item.StatusDate = x); reader.TryGetDateTime("CreateDate", x => item.CreateDate = x); reader.TryGetInt32("UserID", x => item.UserId = x); return(item); } } }
public int InsertFile(TypeCustomerInfoFile model) { using (var connection = new SqlConnection(connectionString)) using (var command = connection.CreateCommand("esp_CustomerBillingFileInsert")) { SqlParameter keyParameter; command .AddWithValue("@CustomerBillingFileNumber", model.FileNumber) .AddIfNotEmptyOrDbNull("@CustomerBillingFileReferenceNumber", model.ReferenceNumber) .AddWithValue("@FileName", model.FileName) .AddWithValue("@CSPDUNSID", model.CspDunsId) .AddWithValue("@StatusID", (int)model.Status) .AddWithValue("@TypeID", model.FileTypeId) .AddWithValue("@DirectionFlag", true) .AddWithValue("@CreateDate", DateTime.Now) .AddWithValue("@StatusDate", model.StatusDate) .AddWithValue("@UserID", model.UserId) .AddOutParameter("@CustomerBillingFileID", SqlDbType.Int, out keyParameter); if (connection.State != ConnectionState.Open) { connection.Open(); } command.ExecuteNonQuery(); if (keyParameter.Value == null) { throw new Exception(); } var fileId = (int)keyParameter.Value; model.FileId = fileId; return(fileId); } }
public void WriteRecord(PrismCustomerInfoContext context, TypeCustomerInfoFile file) { var records = exportDataAccess.ListRecords(file.FileId); foreach (var record in records) { var email = (emailMatch.IsMatch(record.Email)) ? record.Email : string.Empty; var line = string.Format( "DET|{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}|{10}|{11}|{12}|{13}|{14}|{15}|{16}|{17}|{18}|{19}", record.SequenceId, record.CrDuns, record.PremNo, record.CustNo, alphaNumericExp.Replace(record.FirstName, string.Empty), alphaNumericExp.Replace(record.LastName, string.Empty), alphaNumericExp.Replace(record.CompanyName, string.Empty), alphaNumericExp.Replace(record.ContactName, string.Empty), alphaNumericExp.Replace(record.BillingCareOfName, string.Empty), alphaNumericExp.Replace(record.BillingAddress1, string.Empty), alphaNumericExp.Replace(record.BillingAddress2, string.Empty), alphaNumericExp.Replace(record.BillingCity, string.Empty), record.BillingState, alphaNumericExp.Replace(record.BillingPostalCode, string.Empty), record.BillingCountryCode.Trim().Substring(0, 2), numericExp.Replace(record.PrimaryTelephone, string.Empty), alphaNumericExp.Replace(record.PrimaryTelephoneExt, string.Empty), alphaNumericExp.Replace(record.SecondaryTelephone, string.Empty), numericExp.Replace(record.SecondaryTelephoneExt, string.Empty), email); context.AppendLine(line); } context.AppendLine(string.Format("SUM|{0}|0|0", records.Length)); }
public void ParseHeader(PrismCustomerInfoContext context, string[] fields) { var typeId = 3; var typeIndicator = fields.AtIndex(1); if (typeIndicator.Equals("MTCRCUSTOMERINFORMATIONERCOTRESPONSE", StringComparison.OrdinalIgnoreCase)) { typeId = 2; } var model = new TypeCustomerInfoFile { FileTypeId = typeId, ReferenceNumber = fields.AtIndex(2), CrDuns = fields.AtIndex(3), Status = CustomerInfoFileStatusOptions.Imported, }; var cspDunsId = clientDataAccess.IdentifyCspDunsId(model.CrDuns); model.CspDunsId = cspDunsId; context.PushModel(model); }
public void AddHeader(TypeCustomerInfoFile item) { headers.Add(item); }