static JobPage() { SystemNavigationManager.GetForCurrentView().BackRequested += (s, e) => { ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings; localSettings.Values.Remove(Settings.JOBNAME); localSettings.Values.Remove(Settings.JOBCRON); using (var context = new TaskSchedulerDbContext()) { Func <Models.Action, bool> predicate = x => x.JobId == null; context.Actions.RemoveRange(context.ActionsForActionPredicate(predicate)); context.UriActions.RemoveRange(context.UriActionsForActionPredicate(predicate)); context.NotificationActions.RemoveRange(context.NotificationActionsForActionPredicate(predicate)); context.ApplicationActions.RemoveRange(context.ApplicationActionsForActionPredicate(predicate)); context.SaveChanges(); } }; }
private void AppBarButton_Delete(object sender, RoutedEventArgs e) { if ((int)localSettings.Values[Settings.JOBACTION] == Settings.Actions.CREATE) { return; } using (var context = new TaskSchedulerDbContext()) { Job job = context.Jobs.Where(x => x.Id == (int)localSettings.Values[Settings.JOBID]).First(); context.Actions.RemoveRange(context.ActionsForActionPredicate(predicate)); context.UriActions.RemoveRange(context.UriActionsForActionPredicate(predicate)); context.NotificationActions.RemoveRange(context.NotificationActionsForActionPredicate(predicate)); context.ApplicationActions.RemoveRange(context.ApplicationActionsForActionPredicate(predicate)); context.Jobs.Remove(job); context.SaveChanges(); } Frame.GoBack(); }
private void AppBarButton_Save(object sender, RoutedEventArgs e) { SolidColorBrush redBrush = new SolidColorBrush(Colors.Red); SolidColorBrush defaultBrush = new SolidColorBrush(); NameBox.BorderBrush = (String.IsNullOrEmpty(JobName) ? redBrush : defaultBrush); CronBox.BorderBrush = (String.IsNullOrEmpty(JobCron) ? redBrush : defaultBrush); ListView.BorderBrush = (ListView.Items.Count == 0 ? redBrush : defaultBrush); ListView.BorderThickness = (ListView.Items.Count == 0 ? CronBox.BorderThickness : new Thickness()); if (String.IsNullOrEmpty(JobName) || String.IsNullOrEmpty(JobCron) || ListView.Items.Count == 0) { return; } using (var context = new TaskSchedulerDbContext()) { try { Cron.CronStructure cs = Cron.ParseString(JobCron); } catch (Exception exc) { Debug.WriteLine("SHOW ERROR"); Debug.WriteLine(exc.Message); return; } Job job = null; if ((int)localSettings.Values[Settings.JOBACTION] == Settings.Actions.CREATE) { job = new Job(); context.Add(job); context.SaveChanges(); } else { job = context.Jobs.Where(x => x.Id == (int)localSettings.Values[Settings.JOBID]).First(); if (job.Cron != JobCron) { manager.RemoveJob(job); } } Models.Action[] actions = context.ActionsForActionPredicate(predicate); foreach (var action in actions) { action.JobId = job.Id; } job.Name = JobName; job.Cron = JobCron; context.SaveChanges(); manager.AddJob(job); } Frame.GoBack(); }