private void SearchData(object sender, RoutedEventArgs e) { if (LearningName.Text.Length == 0) { return; } using (BasicLadaContext b = new BasicLadaContext()) { var learnings = b.Learnings .Include(s => s.Achivments) .ToList() .Where(l => l.Family.ToLower().Contains(LearningName.Text.ToLower()) || l.Name.ToLower().Contains(LearningName.Text.ToLower())); LearningData.ItemsSource = learnings; LearningData.Visibility = Visibility.Visible; ScrollReport.Visibility = Visibility.Collapsed; } }
private void QuerySectionInput(object sender, TextChangedEventArgs e) { var s = QuerySection.Text; using (BasicLadaContext c = new BasicLadaContext()) { var l = Task.Factory.StartNew(() => { var r = c.Sections.Where(g => g.Name.ToLower().Contains(s.ToLower())).ToList(); return(r); }); l.Wait(); Sections.ItemsSource = l.Result; if (s == "") { Sections.ItemsSource = c.Sections.ToList(); } } }
private void DeleteSection(object sender, MouseButtonEventArgs e) { int id = Convert.ToInt32(((Image)sender).Tag); using (BasicLadaContext c = new BasicLadaContext()) { var t = c.Sections.Include(b => b.Learnings).FirstOrDefault(g => g.SectionId == id); c.Sections.Remove(t); c.SaveChanges(); Sections.ItemsSource = c.Sections.ToList(); } if (context.Sections.FirstOrDefault() != null) { Body.Content = new Learnings(context.Sections.FirstOrDefault().SectionId); } else { Body.Content = new Startup(); } }
private void AddSection(object sender, RoutedEventArgs e) { BasicLadaContext c = new BasicLadaContext(); s.Name = NewName.Text; if (NewName.Text.Length == 0) { return; } var task = Task <int> .Factory.StartNew(() => { c.Sections.Add(s); return(c.SaveChanges()); }); task.Wait(); // MessageBox.Show(task.IsCompleted == true ? "Выполнено" : "Ошибка создания"); var w = Application.Current.Windows.OfType <MainWindow>().FirstOrDefault(); w.Sections.ItemsSource = c.Sections.ToList(); Close(); }