public static void AddWorker() { var workers = new List <Worker> { new Worker { Id = 1, Age = 10, Name = "ssss" }, new Worker { Id = 4, Age = 10, Name = "qwe" }, new Worker { Id = 5, Age = 10, Name = "Krzyszqwetof" }, new Worker { Id = 6, Age = 10, Name = "qwe" }, new Worker { Id = 2, Age = 15, Name = "Tom" }, new Worker { Id = 3, Age = 12, Name = "Andrzej" }, }; using (var context = new employeesCrudAppContext()) { context.Workers.AddRange(workers); context.SaveChanges(); } }
private void DeleteBnt_Click(object sender, RoutedEventArgs e) { int Id = Convert.ToInt16((MyDataGrid.SelectedItem as Worker).Id); var deletedMeber = _db.Workers.Where(m => m.Id == Id).Single(); _db.Workers.Remove(deletedMeber); _db.SaveChanges(); MyDataGrid.ItemsSource = _db.Workers.ToList(); }
private void Update_Click(object sender, RoutedEventArgs e) { try { Worker updateMember = (from m in _db.Workers where m.Id == id select m).Single(); updateMember.Age = Convert.ToInt16(ageBox.Text); updateMember.Name = nameTextBox.Text; _db.SaveChanges(); MainWindow.datagrid.ItemsSource = _db.Workers.ToList(); this.Hide(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void InsertBtn_Click(object sender, RoutedEventArgs e) { try { Worker worker = new Worker() { Name = nameTextBox.Text, Age = Convert.ToInt16(ageBox.Text), }; _db.Workers.Add(worker); _db.SaveChanges(); MainWindow.datagrid.ItemsSource = _db.Workers.ToList(); this.Hide(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }