protected override void StageData(ImportBasicPayCmd request) { // read the csv (file, data, stream) then return the mapped converted data var result = ReadCsv(request); int recordCount = result.Count(); int errorCount = 0; // try to convert each result to staging entity data foreach (var entry in result) { var each = new StagingBasicPay(); if (entry.Result != null) { each = p_Mapper.Map <StagingBasicPay>(entry.Result); } each.ProcessInstanceID = ProcessTracker.ProcessInstanceID; each.ImportIsValid = entry.IsValid; each.RowIndex = entry.RowIndex; if (!entry.IsValid) { each.Err_ColumnIndex = entry.Error.ColumnIndex; each.Err_UnmappedRow = entry.Error.UnmappedRow; each.Err_Value = entry.Error.Value; each.ValidationIsValid = false; } else { each.ValidationIsValid = true; List <ValidationFailureBO> validationFailures = new List <ValidationFailureBO>(); // validate the staging entity before saving to database if (!Validate(entry.Result, entry.RowIndex, ref validationFailures)) { errorsPerRow[entry.RowIndex] = validationFailures; each.ValidationIsValid = false; validationFailures.Select(er => p_Mapper.Map <ValidationFailure>(er)) .ToList() .ForEach(error => { errorCount++; DbContext.ValidationFailures.Add(error); }); } } DbContext.StagingBasicPays.Add(each); } ProcessTracker.LogMessage("Records Count: {0}", recordCount); ProcessTracker.LogMessage("Errors Count: {0}", errorCount); try { DbContext.BulkSaveChanges(); } catch (Exception ex) { ProcessTracker.LogError(ex); ProcessTracker.Abort(); } }