private async void btnCreateTemplate_Click(object sender, RoutedEventArgs e) { // Open the NewTemplate Dialog and get the TemplateModel made in there NewTemplateDialog dialog = new NewTemplateDialog(); await dialog.ShowAsync(); //Navigate to the MainPage NavigationService.Navigate(typeof(Views.MainPage)); }
/// <summary> /// Create a new Template by displaying the NewTemplateDialog and add it to the list if the user saves it /// </summary> private async void NewTemplate() { // Open the NewTemplate Dialog and get the TemplateModel made in there NewTemplateDialog dialog = new NewTemplateDialog(); await dialog.ShowAsync(); // Add this model back to the Templates List for use if the dialog wasn't cancelled TemplateModel model = dialog.SavedTemplate; if (model != null) { Templates.Add(model); } }
/// <summary> /// Import from .ics /// </summary> private async void ImportTemplate() { // Get the user to select an .ics-file to import the information from StorageFile ics = null; ImportModel import = null; // Get the ICS to import: try { ics = await GetIcsFile(); } catch { Debug.WriteLine("MainViewModel - ImportTemplate - Failed to obtain .ics-file"); } // Get the info from the .ics import = await GetIcsDetails(ics); // Create a new TemplateModel infused with the imported data if (import != null) { TemplateModel template = new TemplateModel(); template.AppointmentSubject = import.ImportSubject; template.AppointmentDetails = import.ImportDetails; template.AppointmentLocation = import.ImportLocation; // Set the ID to 0 so it'll recognise it and handle it as a Import model template.TemplateId = -1; // Open it in a TemplateEditor Dialog NewTemplateDialog dialog = new NewTemplateDialog(template); await dialog.ShowAsync(); // Add this model back to the Templates List for use if the dialog wasn't cancelled TemplateModel model = dialog.SavedTemplate; if (model != null) { Templates.Add(model); } } else { // #TODO Import unsuccessful, exit the method and display an error to the user } }
/// <summary> /// Edit Template /// </summary> private async void EditTemplate() { TemplateModel originalTemplate = SelectedTemplate; TemplateModel updatedTemplate; // Open the NewTemplate Dialog and get the TemplateModel made in there NewTemplateDialog dialog = new NewTemplateDialog(originalTemplate); await dialog.ShowAsync(); updatedTemplate = dialog.SavedTemplate; // Make sure the template has been updated if (updatedTemplate != null) { // Remove the old template from the list Templates.Remove(originalTemplate); // Add this model back to the Templates List for use Templates.Add(updatedTemplate); } }