private void Page_Loaded(object sender, RoutedEventArgs e) { using (UposlenikDbContext db = new UposlenikDbContext()) { uposleniciLView.ItemsSource = db.Uposlenici.OrderBy(o => o.Prezime).ToList(); } }
/// <summary> /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// </summary> public App() { Microsoft.ApplicationInsights.WindowsAppInitializer.InitializeAsync( Microsoft.ApplicationInsights.WindowsCollectors.Metadata | Microsoft.ApplicationInsights.WindowsCollectors.Session); this.InitializeComponent(); this.Suspending += OnSuspending; using (var db = new UposlenikDbContext()) { db.Database.ApplyMigrations(); DefaultPodaci.Initialize(db); } }
private void buttonDodaj_Click(object sender, RoutedEventArgs e) { using (UposlenikDbContext db = new UposlenikDbContext()) { Uposlenik zaposleni = new Uposlenik { Ime = imeTextBox.Text, Prezime = prezimeTextBox.Text }; db.Uposlenici.Add(zaposleni); db.SaveChanges(); imeTextBox.Text = ""; prezimeTextBox.Text = ""; uposleniciLView.ItemsSource = db.Uposlenici.OrderBy(o => o.Prezime).ToList(); } }
private void buttonDelete_Click(object sender, RoutedEventArgs e) { DependencyObject dep = (DependencyObject)e.OriginalSource; while ((dep != null) && !(dep is ListViewItem)) { dep = VisualTreeHelper.GetParent(dep); } if (dep == null) { return; } using (UposlenikDbContext db = new UposlenikDbContext()) { db.Uposlenici.Remove((Uposlenik)uposleniciLView.ItemFromContainer(dep)); db.SaveChanges(); uposleniciLView.ItemsSource = db.Uposlenici.OrderBy(o => o.Prezime).ToList(); } }