Exemple #1
0
 private void DeleteStudentButton_Click(object sender, RoutedEventArgs e)
 {
     if (studentsList.SelectedItem != null)
     {
         DTOStudent   student = (DTOStudent)studentsList.SelectedItem;
         ComboBoxItem gnItem  = new ComboBoxItem()
         {
             Content = GroupsComboBox.Text
         };;
         string answer = client.DeleteStudentFromGroup(student.StudentId);
         if (answer == "successfully")
         {
             AddItemsToComboBox();
             DTOGroup          group    = groups.FirstOrDefault(g => g.GroupName == gnItem.Content.ToString());
             List <DTOStudent> students = client.GetGroupStudents(group.StudentsId.ToList <int>());
             studentsList.ItemsSource = students;
         }
         else
         {
             MessageBox.Show("Something wrong!");
         }
     }
     else
     {
         MessageBox.Show("Pleaіe select student!");
     }
 }
        private void DeleteStudentFromGroup_Click(object sender, RoutedEventArgs e)
        {
            var dg = sender as DataGrid;

            for (var vis = sender as Visual; vis != null; vis = VisualTreeHelper.GetParent(vis) as Visual)
            {
                if (vis is DataGridRow)
                {
                    if (((System.Windows.FrameworkElement)vis).DataContext is DTOStudent)
                    {
                        var studentId = ((DTO.DTOStudent)((System.Windows.FrameworkElement)vis).DataContext).StudentId;
                        if (studentId != -1)
                        {
                            string answer = client.DeleteStudentFromGroup(studentId);
                            if (answer == "successfully")
                            {
                                SetListOfStudents();
                            }
                        }
                    }
                }
            }
        }