private void BtnDelete_Click(object sender, RoutedEventArgs e) { COURSEREGISTRATION deleteCoruseregistration = (COURSEREGISTRATION)dbView.SelectedItem; dbContext.db.COURSEREGISTRATION.Remove(deleteCoruseregistration); dbContext.db.SaveChanges(); Page_Loaded(null, null); }
private void btnAdd_Click(object sender, RoutedEventArgs e) { COURSEREGISTRATION newCourseregistration = new COURSEREGISTRATION(); var a = dbContext.db.TRAINER.FirstOrDefault(item => item.Name == cmbTrainer.Text); var b = dbContext.db.COURSE.FirstOrDefault(item => item.Title == cmbCourse.Text); newCourseregistration.CreatedDate = Convert.ToDateTime(dpCreatedDate.SelectedDate); newCourseregistration.IsDone = txbIsDone.Text; newCourseregistration.TotalPoint = Convert.ToInt32(txbTotalPoint.Text); newCourseregistration.Comment = txbComment.Text; newCourseregistration.Trainerid = a.Id; newCourseregistration.Courseid = b.Id; MessageBox.Show("Данные добавлены", "Уведомление", MessageBoxButton.OK, MessageBoxImage.Information); dbContext.db.COURSEREGISTRATION.Add(newCourseregistration); dbContext.db.SaveChanges(); }