PIbd-42_Kashin_M.I_CPO_Cour.../EmployeeManagmentView/PhysicalPerson/DeletePhysicalPersonWindow.xaml.cs

41 lines
1.4 KiB
C#

using EmployeeManagmentContracts.BusinessLogicContracts;
using EmployeeManagmentContracts.ViewModels;
using System.Windows;
namespace EmployeeManagmentView.PhysicalPerson
{
public partial class DeletePhysicalPersonWindow : Window
{
private readonly IPhisicalPersonLogic _phisicalPersonLogic;
public DeletePhysicalPersonWindow(IPhisicalPersonLogic phisicalPersonLogic)
{
_phisicalPersonLogic = phisicalPersonLogic;
InitializeComponent();
LoadPhysicalPersons();
}
private void LoadPhysicalPersons()
{
PhysicalPersonsDataGrid.ItemsSource = _phisicalPersonLogic.GetFullList();
}
private void DeleteButton_Click(object sender, RoutedEventArgs e)
{
if (PhysicalPersonsDataGrid.SelectedItem != null)
{
var selectedPerson = PhysicalPersonsDataGrid.SelectedItem as PhisicalPersonViewModel;
if (selectedPerson != null)
{
_phisicalPersonLogic.Delete(selectedPerson.Id); // Используем Id для удаления
LoadPhysicalPersons(); // Перезагружаем список
}
}
else
{
MessageBox.Show("Пожалуйста, выберите физическое лицо для удаления.");
}
}
}
}