Explorar el Código

доделали удаление пользователя

fly9024 hace 11 meses
padre
commit
003a465edc

+ 8 - 0
AvaloniaApplication5/ViewModels/MainWindowViewModel.cs

@@ -66,6 +66,14 @@ namespace AvaloniaApplication5.ViewModels
             PageUCabinetVM = id == 0 ? new PageUserCabinetViewModel(DBConnect) : new PageUserCabinetViewModel(DBConnect, id);
             UCAdmin = new PageUserCabinet();
         }
+
+        public void DeleteUser(int id)
+        {
+            Logintable? delUser = DBConnect.Logintables.FirstOrDefault(x => x.Id == id);
+            DBConnect.Logintables.Remove(delUser);
+            DBConnect.SaveChanges();
+            UC = new PageUserList();//для обновления списка на странице
+        }
         #endregion
 
 

+ 1 - 1
AvaloniaApplication5/ViewModels/PageUserListViewModel.cs

@@ -15,7 +15,7 @@ namespace AvaloniaApplication5.ViewModels
                 
         public PageUserListViewModel(_1234Context dBConnect)
         {
-            this.DBConnect = dBConnect;
+            DBConnect = dBConnect;
             userList = DBConnect.Logintables.Include(x => x.IdRoleNavigation).Include(x => x.User.IdGenderNavigation).ToList();
         }
         List<Logintable> userList;

+ 1 - 0
AvaloniaApplication5/Views/PageUserList.axaml

@@ -43,6 +43,7 @@
 						<TextBlock Text="Дата рождения"/>
 						<TextBlock Text="{Binding User.BirthDate}"/>
 						<Button  Content="Редактировать" Command="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).EditUser}" CommandParameter="{Binding Id}"/>
+						<Button  Content="Удалить" Command="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).DeleteUser}" CommandParameter="{Binding Id}"/>
 					</StackPanel>
 				</DataTemplate>
 			</ListBox.ItemTemplate>