///
/// Retrieves Key Information for Students data from the KIS Data Service
/// and stores it in a local database.
/// Uses the Simple.OData.Client library to connect to the service
/// this library requires asynchronous calls.
///
/// A message describing the result of the process
private static async Task UpdateKeyInformationData()
{
try
{
//Set up the client to connect to the KIS Data Service url
var client = new ODataClient(" https://info4learners.tec.govt.nz /");
//Call the service with an OData query - in this case,
//all qualifications for a particular provider
var qualifications = await client
.FindEntriesAsync("KeyInformation?$filter=ProviderCode eq '6006'");
var repository = new KeyInformationRepository();
//Save all qualification data to the database
foreach (var qualification in qualifications)
{
var kis = new KeyInformationData
{
CourseCompletion = qualification["CourseCompletion"].ToString(),
Duration = qualification["Duration"].ToString(),
MinimumEntryRequirements = qualification["MinimumEntryRequirements"].ToString(),
GovernmentSubsidy = qualification["GovernmentSubsidy"].ToString(),
GraduatesInEmployment = qualification["GraduatesInEmployment"].ToString(),
GraduatesInStudy = qualification["GraduatesInStudy"].ToString(),
AnnualStudentFees = qualification["AnnualStudentFees"].ToString(),
AnnualGovernmentTuitionSubsidy = qualification["AnnualGovernmentTuitionSubsidy"].ToString(),
Total_Annual = qualification["Total_Annual"].ToString(),
Total_TotalQualification = qualification["Total_ TotalQualification"].ToString(),
GraduatesOnBenefit = qualification["GraduatesOnBenefit"].ToString(),
MedianEarnings = qualification["MedianEarnings"].ToString(),
UpperQuartileEarnings = qualification["UpperQuartileEarnings"].ToString(),
LowerQuartileEarnings = qualification["LowerQuartileEarnings"].ToString(),
QualificationCode = qualification["QualificationCode"].ToString(),
StudentFees = qualification["StudentFees"].ToString(),
};
repository.AddOrUpdateKis(kis);
}
return "All Key Information for Students successfully updated.";
}
catch(Exception ex)
{
//In a real implementation we would log the error here
var message = "An error occurred while updating Key Information Data: " + ex.Message;
if (ex.InnerException != null)
{
message = message + ex.InnerException.Message;
}
return message;
}
}