private void AssignDocumentControlNumber(List <LoadFileRecord> records) { long numericPartOfDcn = 0; #region Delegate - logic to get complete DCN readily, given the numeric value as input Func <string, string> getDcn = delegate(string newLastDcnNumericPart) { var padString = string.Empty; // pad zeros if (newLastDcnNumericPart.Length < m_Dataset.DCNStartWidth.Length) { var numberOfZerosTobePadded = m_Dataset.DCNStartWidth.Length - newLastDcnNumericPart.Length; for (var i = 0; i < numberOfZerosTobePadded; i++) { padString += "0"; } } return(m_Dataset.DCNPrefix + padString + newLastDcnNumericPart); }; #endregion Delegate - logic to get complete DCN readily, given the numeric value as input using (var lowerTransScope = new EVTransactionScope(TransactionScopeOption.Suppress)) { m_CurrentDcn = DataSetBO.GetLastDocumentControlNumber(m_Dataset.FolderID); // If DCN is not obtained, no documents are imported for the dataset till now. // So set current DCN to first DCN value. if (string.IsNullOrWhiteSpace(m_CurrentDcn)) { m_CurrentDcn = m_Dataset.DCNPrefix + Constants.StringZero; } else { if (!m_CurrentDcn.Contains(m_Dataset.DCNPrefix)) { var currentNumber = Convert.ToInt32(m_CurrentDcn); currentNumber = currentNumber - 1; m_CurrentDcn = currentNumber.ToString(); m_CurrentDcn = m_Dataset.DCNPrefix + m_CurrentDcn; } } // 1) Get Last DCN from EVMaster DB and 2) Pick Numeric part of it // throws exception if numeric part couldn't be retrieved, throw Exception. if (IsNumeric(m_CurrentDcn.Substring(m_Dataset.DCNPrefix.Length), out numericPartOfDcn)) { // Update new DCN after bulk add, assuming bulk add would be successful. // The delegate, GetNewLastDCNAfterBulkAdd gets DCN to be updated back to DB. // Delegates takes numeric part of WOULD BE DCN value as input, returns complete DCN - so that it can readily be updated back to Dataset table. m_NewDcn = getDcn((numericPartOfDcn + records.Count()).ToString(CultureInfo.InvariantCulture)); DataSetBO.UpdateLastDocumentControlNumber(m_Dataset.FolderID, m_NewDcn); lowerTransScope.Complete(); } else { throw new Exception(ErrorCodes.InvalidDCNValueObtainedForDataset); } } #region Assign DCN to all documents var dCNIncrementalCounter = numericPartOfDcn; records.ForEach(p => { dCNIncrementalCounter += 1; p.DocumentControlNumber = getDcn(dCNIncrementalCounter.ToString(CultureInfo.InvariantCulture)); }); #endregion }