protected override void Track(TrackingRecord record, TimeSpan timeout) { // get the custom record CustomTrackingRecord customRecord = (CustomTrackingRecord)record; string hiringRequestId = customRecord.Data["HiringRequestId"].ToString(); // create the request history record historyRecord = new RequestHistoryRecord(); historyRecord.RequestId = hiringRequestId; historyRecord.RecordNumber = record.RecordNumber; historyRecord.Action = GetStringFromTrackingRecord("Action", customRecord.Data); historyRecord.SourceState = GetStringFromTrackingRecord("State", customRecord.Data); historyRecord.Comment = GetStringFromTrackingRecord("Comment", customRecord.Data); historyRecord.EmployeeId = GetStringFromTrackingRecord("EmployeeId", customRecord.Data); historyRecord.EmployeeName = GetStringFromTrackingRecord("EmployeeName", customRecord.Data); historyRecord.Date = GetDateFromTrackingRecord(customRecord.Data); }
// Save history for a HiringRequest public static void Save(RequestHistoryRecord requestHistory) { string connectionString = ConfigurationManager.ConnectionStrings["ContosoHR"].ConnectionString; using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand command = connection.CreateCommand(); command.CommandType = CommandType.StoredProcedure; command.CommandText = "SaveRequestHistory"; command.Parameters.Add(new SqlParameter("@requestId", requestHistory.RequestId)); command.Parameters.Add(new SqlParameter("@sourceState", requestHistory.SourceState)); command.Parameters.Add(new SqlParameter("@actionName", requestHistory.Action)); command.Parameters.Add(new SqlParameter("@comment", requestHistory.Comment)); command.Parameters.Add(new SqlParameter("@employeeId", requestHistory.EmployeeId)); command.Parameters.Add(new SqlParameter("@employeeName", requestHistory.EmployeeName)); command.ExecuteNonQuery(); } }