private void DeleteBtnCLick(object sender, RoutedEventArgs e) { var db = new TrainingDBContext(); var CourseIdDel = 0; // Getting the studentId of selected object var confirmation = MessageBox.Show("Do You Really want to delete? ", "Deletion Confirmation", MessageBoxButton.YesNo); if (confirmation == MessageBoxResult.Yes) { if (DeleteCourseCombo.SelectedItem != null) { var titleFromCombo = DeleteCourseCombo.SelectedValue.ToString(); var getCourseId = from cour in db.Courses where cour.Title == titleFromCombo select new { cour.Code }; foreach (var crId in getCourseId) { CourseIdDel = crId.Code; } var queryStudentCourses = from stdCour in db.StudentCourses where stdCour.CourseId == CourseIdDel select stdCour; foreach (var del in queryStudentCourses) { db.StudentCourses.Remove(del); } db.SaveChanges(); var queryCourses = from course in db.Courses where course.Title == titleFromCombo select course; foreach (var del in queryCourses) { db.Courses.Remove(del); } db.SaveChanges(); MessageBox.Show("Deleted! Refresh list"); DeleteCourseCombo.Text = "Select Record to delete"; } } }
private void DeleteBtn_OnClick(object sender, RoutedEventArgs e) { var db = new TrainingDBContext(); var studentIdDel = 0; // Getting the studentId of selected object var confirmation = MessageBox.Show("Do You Really want to delete? ", "Deletion Confirmation", MessageBoxButton.YesNo); if (confirmation == MessageBoxResult.Yes) { if (DeleteStdCombo.SelectedItem != null) { var firstNameFromCombo = DeleteStdCombo.SelectedValue.ToString(); var getStudentId = from std in db.Students where std.FirstName == firstNameFromCombo select new { std.StudentId }; foreach (var stdId in getStudentId) { studentIdDel = stdId.StudentId; } var queryStudentCourses = from stdCour in db.StudentCourses where stdCour.StudentId == studentIdDel select stdCour; foreach (var del in queryStudentCourses) { db.StudentCourses.Remove(del); } db.SaveChanges(); var queryStudents = from std in db.Students where std.StudentId == studentIdDel select std; foreach (var del in queryStudents) { db.Students.Remove(del); } db.SaveChanges(); MessageBox.Show("Deleted! Refresh list"); DeleteStdCombo.Text = "Select Record to delete"; } } }
private void Assignment_CourseToTrainer(object sender, RoutedEventArgs e) { // Assigning Course to Trainer var db = new TrainingDBContext(); string assignedName = AssignTrainerCombo.SelectedValue.ToString(); string assignedCourse = AssignCourseCombo.SelectedValue.ToString(); int trainerId = 0; var queryTrainer = from trainer in db.Trainers where trainer.FirstName == assignedName select new { TrainerID = trainer.TrainerId }; foreach (var query in queryTrainer) { trainerId = query.TrainerID; } // // UPDATION var queryCourses = from cour in db.Courses where cour.Title == assignedCourse select cour; foreach (var course in queryCourses) { course.TrainerId = trainerId; } db.SaveChanges(); MessageBox.Show("Assigned! Please Refresh"); }
private void UpdateOnClick(object sender, RoutedEventArgs e) { var db = new TrainingDBContext(); var selectedData = (CoursesRecord)ListCourses.SelectedValue; if (selectedData != null) { var courseTitle = selectedData.Title; var courseId = (from cour in db.Courses where cour.Title == courseTitle select cour.Code).ToList(); int courseID = courseId[0]; var queryCourses = from cour in db.Courses where cour.Code == courseID select cour; foreach (var cour in queryCourses) { cour.Title = UpTitle.Text; cour.Description = UpDescription.Text; } db.SaveChanges(); MessageBox.Show("Updated! Refresh to see changes"); } UpTitle.Text = ""; UpCode.Text = ""; UpDescription.Text = ""; }
private void AddBtnCourse(object sender, RoutedEventArgs e) { var context = new TrainingDBContext(); if (CodeTextBox.Text == "" || TitleTextBox.Text == "" || DescriptionTextBox.Text == "") { MessageBox.Show("All fields are required"); } else { var courseObj = new Course() { Code = int.Parse(CodeTextBox.Text), Title = TitleTextBox.Text, Description = DescriptionTextBox.Text }; context.Courses.Add(courseObj); context.SaveChanges(); MessageBox.Show("Added: Refresh to see changes"); CodeTextBox.Text = ""; TitleTextBox.Text = ""; DescriptionTextBox.Text = ""; } }
private void Update_OnClick(object sender, RoutedEventArgs e) { var db = new TrainingDBContext(); var selectedData = (TrainerRecord)ListTrainers.SelectedValue; if (selectedData != null) { var trainerName = selectedData.FirstName; var tranId = (from trainer in db.Trainers where trainer.FirstName == trainerName select trainer.TrainerId).ToList(); int trainerID = tranId[0]; var queryTrainers = from trainer in db.Trainers where trainer.TrainerId == trainerID select trainer; foreach (var tran in queryTrainers) { tran.FirstName = UpFirstName.Text; tran.LastName = UpLastName.Text; tran.Designation = UpDesignation.Text; tran.Email = UpEmail.Text; tran.Address = UpAddress.Text; tran.Department = UpDepartment.Text; tran.Salary = UpSalary.Text; tran.DateOfBirth = UpDateOfBirth.Text; tran.PhotoSrc = PhotoUpdate.Source.ToString(); } MessageBox.Show(queryTrainers.ToString()); db.SaveChanges(); MessageBox.Show("Updated! Refresh to see changes"); } UpFirstName.Text = ""; UpLastName.Text = ""; UpAddress.Text = ""; UpDateOfBirth.Text = ""; UpEmail.Text = ""; UpDepartment.Text = ""; UpDesignation.Text = ""; UpSalary.Text = ""; PhotoUpdate.Source = null; }
private void Update_OnClick(object sender, RoutedEventArgs e) { var db = new TrainingDBContext(); var selectedData = (StudentRecords)ListStudents.SelectedValue; if (selectedData != null) { var stdName = selectedData.FirstName; var stdId = (from std in db.Students where std.FirstName == stdName select std.StudentId).ToList(); int studentId = stdId[0]; var queryStudents = from std in db.Students where std.StudentId == studentId select std; foreach (var stds in queryStudents) { stds.FirstName = UpFirstName.Text; stds.LastName = UpLastName.Text; stds.RegNo = UpRegNo.Text; stds.Email = UpEmail.Text; stds.Address = UpAddress.Text; stds.PhoneNo = UpPhoneNo.Text; stds.DateOfBirth = UpDateOfBirth.Text; stds.PhotoSrc = PhotoUpdate.Source.ToString(); } MessageBox.Show(queryStudents.ToString()); db.SaveChanges(); MessageBox.Show("Updated! Refresh to see changes"); } UpFirstName.Text = ""; UpLastName.Text = ""; UpAddress.Text = ""; UpDateOfBirth.Text = ""; UpEmail.Text = ""; UpPhoneNo.Text = ""; UpRegNo.Text = ""; PhotoUpdate.Source = null; }
private void Assignment_CourseToStd(object sender, RoutedEventArgs e) { // Assigning Course to student var context = new TrainingDBContext(); string assignedName = AssignStdCombo.SelectedValue.ToString(); string assignCourseTitle = AssignCourseCombo.SelectedValue.ToString(); int studentId = 0; int courseCode = 0; var queryStd = from std in context.Students where std.FirstName == assignedName select new { StudentID = std.StudentId }; var queryCourse = from cour in context.Courses where cour.Title == assignCourseTitle select new { CourseCode = cour.Code }; foreach (var query in queryStd) { studentId = query.StudentID; } foreach (var query in queryCourse) { courseCode = query.CourseCode; } StudentCourse iStudentCourses = new StudentCourse { StudentId = studentId, CourseId = courseCode }; context.StudentCourses.Add(iStudentCourses); context.SaveChanges(); MessageBox.Show("Assigned"); AssignStdCombo.Text = ""; AssignCourseCombo.Text = ""; }
private void BtnAdd_OnClick(object sender, RoutedEventArgs e) { var context = new TrainingDBContext(); if (FirstNameTextBox.Text == "" || LastNameTextBox.Text == "" || AddressTextBox.Text == "" || DateOfBirthPicker.Text == "" || EmailTextBox.Text == "" || DesignationTextBox.Text == "" || DepartmentTextBox.Text == "" || DepartmentTextBox.Text == "" || Photo.Source == null) { MessageBox.Show("All fields are required"); } else { var trainerObj = new Trainer() { FirstName = FirstNameTextBox.Text, LastName = LastNameTextBox.Text, Address = AddressTextBox.Text, DateOfBirth = DateOfBirthPicker.Text, Email = EmailTextBox.Text, Designation = DesignationTextBox.Text, Department = DepartmentTextBox.Text, Salary = SalaryTextBox.Text, PhotoSrc = Photo.Source.ToString() }; context.Trainers.Add(trainerObj); context.SaveChanges(); MessageBox.Show("Added: Refresh to see changes"); FirstNameTextBox.Text = ""; LastNameTextBox.Text = ""; AddressTextBox.Text = ""; DateOfBirthPicker.Text = ""; EmailTextBox.Text = ""; DesignationTextBox.Text = ""; DepartmentTextBox.Text = ""; SalaryTextBox.Text = ""; Photo.Source = null; } }
private void BtnAdd_OnClick(object sender, RoutedEventArgs e) { var context = new TrainingDBContext(); if (FirstNameTextBox.Text == "" || LastNameTextBox.Text == "" || AddressTextBox.Text == "" || DateOfBirthPicker.Text == "" || EmailTextBox.Text == "" || PhoneNumberTextBox.Text == "" || RegTextBox.Text == "" || Photo.Source == null) { MessageBox.Show("All fields are required"); } else { var studentObj = new Student() { FirstName = FirstNameTextBox.Text, LastName = LastNameTextBox.Text, Address = AddressTextBox.Text, DateOfBirth = DateOfBirthPicker.Text, Email = EmailTextBox.Text, PhoneNo = PhoneNumberTextBox.Text, RegNo = RegTextBox.Text, PhotoSrc = Photo.Source.ToString() }; context.Students.Add(studentObj); context.SaveChanges(); MessageBox.Show("Added: Refresh to see changes"); FirstNameTextBox.Text = ""; LastNameTextBox.Text = ""; AddressTextBox.Text = ""; DateOfBirthPicker.Text = ""; EmailTextBox.Text = ""; PhoneNumberTextBox.Text = ""; RegTextBox.Text = ""; Photo.Source = null; } }