private async void btnSubmit_Click(object sender, RoutedEventArgs e) { Record r; if (!await CheckFormInput()) { MessageDialog dialog = new MessageDialog("Please Ensure All Fields Are Filled"); await dialog.ShowAsync(); return; } r = await CreateRecord(); if (r == null) { Debug.WriteLine("An Error occurred while creating the record"); return; } if (!await ReadRecordData() || records == null) { Debug.WriteLine("No records found"); records = RecordList.GetInstance(); } records.AddRecord(r); if (!await WriteRecordData(records)) { Debug.WriteLine("An Error occurred while writing records"); } MessageDialog riskDialog = new MessageDialog("Your Risk Level is: " + r.RiskLevel.ToString()); await riskDialog.ShowAsync(); Frame.GoBack(); }
private async Task <bool> ReadRecordData() { try { StorageFolder folder = ApplicationData.Current.LocalFolder; Stream stream = await folder.OpenStreamForReadAsync("records.dat"); if (stream.Length > 0) { using (StreamReader reader = new StreamReader(stream)) { DataContractJsonSerializerSettings settings = new DataContractJsonSerializerSettings(); settings.RootName = "root"; DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(RecordList), settings); records = (RecordList)serializer.ReadObject(stream); } } return(true); } catch (FileNotFoundException ex) { StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync("records.dat"); records = RecordList.GetInstance(); return(true); } return(false); }