IEnumerable
//Model:
public class CvFile
{
public int ApplicationId { get; set; }
public int CustomerId { get; set; }
public string CvFilename { get; set; }
}
//method to retrieve list of cv information
private IEnumerable<CvFile> RetrieveCvs()
{
SqlCommand com = new SqlCommand();
DataSet dataSet = new DataSet();
com.Connection = new SqlConnection(this.connectionString);
com.CommandType = CommandType.StoredProcedure;
com.CommandText = "mdConvertExistingCv";
SqlDataAdapter adapter = new SqlDataAdapter(com);
adapter.Fill(dataSet);
var cvFiles = new List<CvFile>(); // create a list of model cv list
foreach (DataRow item in dataSet.Tables[0].Rows)
{
try
{
var cvFile = new CvFile() // create an object of the class CvFile
{
ApplicationId = Convert.ToInt32(item["ApplicationsID"]),
CustomerId = Convert.ToInt32(item["CustomerID"]),
CvFilename = item["CVFilename"].ToString()
};
cvFiles.Add(cvFile); // every loop add the cvfile object in the list
}
catch (Exception)
{
}
}
return cvFiles; // return the list
}
//accept and IEnumerable as arguments
this.ConvertToPdf(this.RetrieveCvs()); // method found above
private void ConvertToPdf(IEnumerable<CvFile> cvFiles)
{
ComponentInfo.SetLicense(gemboxLicenseKey);
DocumentModel document = null;
string pdfExtension = ".pdf";
string existingFilePath = String.Empty;
string newFilePath = String.Empty;
string CvFolder = "\\CVS\\";
foreach (var item in cvFiles) //useing the IEnumerable passed as parameter in this method
{
try
{
existingFilePath = string.Concat(cvBasePath, item.CustomerId, CvFolder, item.CvFilename);
if (!File.Exists(existingFilePath))
continue;
newFilePath = Path.ChangeExtension(existingFilePath, pdfExtension);
document = DocumentModel.Load(existingFilePath);
document.Save(newFilePath);
this.UpdateApplication(item.ApplicationId, string.Concat(item.ApplicationId, pdfExtension));
this.ArchiveFile(existingFilePath, item, CvFolder);
}
catch (Exception)
{
}
}
}