private void ButtonAddEditGroup_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (this.IsDataCorrcet() == true)
         {
             using (WFAEntity.API.MyDBContext objectMyDBContext =
                        new WFAEntity.API.MyDBContext())
             {
                 WFAEntity.API.Group objectGroup = new WFAEntity.API.Group();
                 objectGroup.Name = textBlockAddEditGroup.Text;
                 if (this.add_edit == true)
                 {
                     objectMyDBContext.Groups.Add(objectGroup);
                 }
                 else
                 {
                     WFAEntity.API.Group objectGroupFromDataBase = new WFAEntity.API.Group();
                     objectGroupFromDataBase = WFAEntity.API.DatabaseRequest.GetGroupById(objectMyDBContext, this.id);
                     objectMyDBContext.Entry(objectGroupFromDataBase).CurrentValues.SetValues(objectGroup);
                 }
                 objectMyDBContext.SaveChanges();
                 this.DialogResult = true;
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "ОШИБКА (Группа)", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
 private void deleteGroupButton_Click(object sender, RoutedEventArgs e)
 {
     if (gropiesGrid.SelectedItems.Count > 0)
     {
         for (int i = 0; i < gropiesGrid.SelectedItems.Count; i++)
         {
             WFAEntity.API.Group objectGroup = gropiesGrid.SelectedItems[i] as WFAEntity.API.Group;
             if (objectGroup != null)
             {
                 try
                 {
                     using (WFAEntity.API.MyDBContext objectMyDBContext =
                                new WFAEntity.API.MyDBContext())
                     {
                         WFAEntity.API.Group group = WFAEntity.API.DatabaseRequest.GetGroupById(objectMyDBContext, objectGroup.Id);
                         objectMyDBContext.Groups.Attach(group);
                         objectMyDBContext.Groups.Remove(group);
                         objectMyDBContext.SaveChanges();
                     }
                     this.ShowAll(SELECTED_TAB.GROUP);
                 }
                 catch (Exception ex)
                 {
                     MessageBox.Show(ex.Message, "ОШИБКА", MessageBoxButton.OK, MessageBoxImage.Error);
                 }
             }
         }
     }
 }
 private void ButtonAddEditGroup_Click(object sender, RoutedEventArgs e)
 {
     WFAEntity.API.Group objectGroup = new WFAEntity.API.Group();
     if (this.add_edit == true)
     {
         objectGroup.Name = textBlockAddEditGroup.Text;
         try
         {
             if (this.IsDataCorrcet() == true)
             {
                 using (WFAEntity.API.MyDBContext objectMyDBContext =
                            new WFAEntity.API.MyDBContext())
                 {
                     objectMyDBContext.Groups.Add(objectGroup);
                     objectMyDBContext.SaveChanges();
                 }
                 MessageBox.Show("Группа добавлена");
                 this.DialogResult = true;
             }
             else
             {
                 MessageBox.Show("Ввод данных", "ОШИБКА", MessageBoxButton.OK, MessageBoxImage.Error);
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "ОШИБКА", MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
     else
     {
         try
         {
             if (this.IsDataCorrcet())
             {
                 using (WFAEntity.API.MyDBContext objectMyDBContext =
                            new WFAEntity.API.MyDBContext())
                 {
                     WFAEntity.API.Group group = new WFAEntity.API.Group();
                     group      = WFAEntity.API.DatabaseRequest.GetGroupById(objectMyDBContext, this.id);
                     group.Name = textBlockAddEditGroup.Text;
                     objectMyDBContext.Entry(group).State = System.Data.Entity.EntityState.Modified;
                     objectMyDBContext.SaveChanges();
                 }
                 MessageBox.Show("Группа изменена");
                 this.DialogResult = true;
             }
             else
             {
                 MessageBox.Show("Ввод данных", "ОШИБКА", MessageBoxButton.OK, MessageBoxImage.Error);
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "ОШИБКА", MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
 }
 public GroupWindow(bool add_edit, int id = 0)
 {
     InitializeComponent();
     this.add_edit = add_edit;
     this.id       = id;
     if (this.add_edit == false)
     {
         using (WFAEntity.API.MyDBContext objectMyDBContext =
                    new WFAEntity.API.MyDBContext())
         {
             WFAEntity.API.Group group = WFAEntity.API.DatabaseRequest.GetGroupById(objectMyDBContext, this.id);
             textBlockAddEditGroup.Text = group.Name;
         }
         ButtonAddEditGroup.Content = "Изменить";
     }
 }
 private void editGroupButton_Click(object sender, RoutedEventArgs e)
 {
     if (gropiesGrid.SelectedItems.Count > 0)
     {
         for (int i = 0; i < gropiesGrid.SelectedItems.Count; i++)
         {
             WFAEntity.API.Group objectGroup = gropiesGrid.SelectedItems[i] as WFAEntity.API.Group;
             if (objectGroup != null)
             //if (gropiesGrid.SelectedItems[i] is WFAEntity.API.Group students)
             {
                 Forms.GroupWindow g = new Forms.GroupWindow(false, objectGroup.Id);
                 if (g.ShowDialog() == true)
                 {
                     this.ShowAll(SELECTED_TAB.GROUP);
                 }
             }
         }
     }
     else
     {
         MessageBox.Show("Выберите строку");
     }
 }