PIbd-42_Kashin_M.I_CPO_Cour.../ViewModel/DataManageViewModel.cs

65 lines
2.2 KiB
C#

using EmployeeManager.Model;
using EmployeeManager.View.PhysicalPerson;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace EmployeeManager.ViewModel
{
public class DataManageViewModel : INotifyPropertyChanged
{
private readonly IPhysicalPersonService _physicalPersonService;
public DataManageViewModel(IPhysicalPersonService physicalPersonService)
{
_physicalPersonService = physicalPersonService;
AllPhysicalPeoples = _physicalPersonService.GetAllPhysicalPersons();
}
private List<PhysicalPerson> allPhysicalPeoples;
public List<PhysicalPerson> AllPhysicalPeoples
{
get => allPhysicalPeoples;
set
{
allPhysicalPeoples = value;
NotifyPropertyChanged(nameof(AllPhysicalPeoples));
}
}
public string NamePhysicalPersons { get; set; }
public string SurnamePhysicalPersons { get; set; }
public string PatronomicPhysicalPersons { get; set; }
public DateTime Birthday { get; set; }
public string Gender { get; set; }
public string Address { get; set; }
public string Telephone { get; set; }
public RelayCommand AddNewPhysicalPersonCommand => new RelayCommand(obj =>
{
var newPerson = new PhysicalPersonDto
{
Name = NamePhysicalPersons,
Surname = SurnamePhysicalPersons,
Patronomic = PatronomicPhysicalPersons,
Birthday = Birthday,
Gender = Gender,
Address = Address,
Telephone = Telephone
};
string result = _physicalPersonService.CreatePhysicalPerson(newPerson);
// Обновить список
AllPhysicalPeoples = _physicalPersonService.GetAllPhysicalPersons();
});
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string propertyName) =>
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}