protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); AudioBox.ItemsSource = AudioList; if ((int)localSettings.Values[Settings.ACTIONACTION] == Settings.Actions.CREATE) { return; } using (var context = new TaskSchedulerDbContext()) { Models.Action action = context.Actions.Where(x => x.Id == (int)localSettings.Values[Settings.ACTIONID]).First(); switch (action.Type) { case ActionType.URI: { UriAction uriAction = context.UriActions.Where(x => x.Id == action.ActionId).First(); Uri = uriAction.Uri; Index = 0; }; break; case ActionType.NOTIFICATION: { NotificationAction notificationAction = context.NotificationActions.Where(x => x.Id == action.ActionId).First(); Text = notificationAction.Text; Image = notificationAction.Image; Audio = notificationAction.Audio.GetValueOrDefault(0); if (notificationAction.Timeout.HasValue) { Timeout = notificationAction.Timeout.Value.ToString(); } Index = 1; }; break; case ActionType.APPLICATION: { ApplicationAction applicationAction = context.ApplicationActions.Where(x => x.Id == action.ActionId).First(); appListProvider.IsDoneTask.ContinueWith(async(result) => { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { bool ok = appListProvider.AppList.Where(x => x.Package.Id.FullName == applicationAction.ApplicationName).Any(); if (ok) { AppEntry entry = appListProvider.AppList.Where(x => x.Package.Id.FullName == applicationAction.ApplicationName).First(); LoadedContent.SelectedItem = entry; LoadedContent.ScrollIntoView(entry); } }); }); Index = 2; }; break; } } }
private void DeleteInitAction() { if ((int)localSettings.Values[Settings.ACTIONACTION] == Settings.Actions.CREATE) { return; } using (var context = new TaskSchedulerDbContext()) { int deleted_action_id = (int)localSettings.Values[Settings.ACTIONID]; Models.Action action = context.Actions.Where(x => x.Id == deleted_action_id).First(); switch (action.Type) { case ActionType.URI: { UriAction uriAction = context.UriActions.Where(x => x.Id == action.ActionId).First(); context.UriActions.Remove(uriAction); }; break; case ActionType.NOTIFICATION: { NotificationAction notificationAction = context.NotificationActions.Where(x => x.Id == action.ActionId).First(); context.NotificationActions.Remove(notificationAction); }; break; case ActionType.APPLICATION: { ApplicationAction applicationActions = context.ApplicationActions.Where(x => x.Id == action.ActionId).First(); context.ApplicationActions.Remove(applicationActions); }; break; } context.Actions.Remove(action); context.SaveChanges(); } }
private void AppBarButton_Save(object sender, RoutedEventArgs e) { SolidColorBrush redBrush = new SolidColorBrush(Colors.Red); SolidColorBrush defaultBrush = new SolidColorBrush(); switch (Index) { case 0: { URIBox.BorderBrush = (String.IsNullOrEmpty(Uri) ? redBrush : defaultBrush); }; break; case 1: { TextBox.BorderBrush = (String.IsNullOrEmpty(Text) ? redBrush : defaultBrush); }; break; case 2: { LoadedContent.BorderBrush = (LoadedContent.SelectedItems.Count == 0 ? redBrush : defaultBrush); LoadedContent.BorderThickness = (LoadedContent.SelectedItems.Count == 0 ? URIBox.BorderThickness : new Thickness()); }; break; } if (Index == 0 && String.IsNullOrEmpty(Uri) || Index == 1 && String.IsNullOrEmpty(Text) || Index == 2 && LoadedContent.SelectedItems.Count == 0) { return; } using (var context = new TaskSchedulerDbContext()) { int actionId = 0; ActionType actionType = ActionType.URI; switch (Index) { case 0: { UriAction act = new UriAction() { Uri = Uri }; context.UriActions.Add(act); context.SaveChanges(); actionId = act.Id; actionType = ActionType.URI; }; break; case 1: { NotificationAction act = new NotificationAction() { Text = Text, Image = Image, Audio = Audio }; if (!String.IsNullOrEmpty(Timeout)) { act.Timeout = int.Parse(Timeout); } context.NotificationActions.Add(act); context.SaveChanges(); actionId = act.Id; actionType = ActionType.NOTIFICATION; }; break; case 2: { AppEntry appEntry = (AppEntry)LoadedContent.SelectedItem; ApplicationAction act = new ApplicationAction() { ApplicationName = appEntry.Package.Id.FullName }; context.ApplicationActions.Add(act); context.SaveChanges(); actionId = act.Id; actionType = ActionType.APPLICATION; }; break; } Models.Action action = new Models.Action() { ActionId = actionId, Type = actionType }; if ((int)localSettings.Values[Settings.JOBACTION] == Settings.Actions.EDIT) { Job job = context.Jobs.Where(x => x.Id == (int)localSettings.Values[Settings.JOBID]).First(); action.JobId = job.Id; } context.Actions.Add(action); context.SaveChanges(); DeleteInitAction(); } Frame rootFrame = Window.Current.Content as Frame; rootFrame.GoBack(); }