public UpdatePersonPage(int id)
     : this()
 {
     using (var service = new PhoneBookCRUDService())
     {
         _Person = service.GetPersonById(id);
     }
 }
 public void UpdatePerson(Person person)
 {
     if(person != null)
     {
         if (!_PersonValidator.IsValid(person))
         {
             throw new DuplicatePersonNameException();
         }
         _PhonesUnitOfWork.PeopleRepository.Update(_PersonConverter.Convert(person));
         _PhonesUnitOfWork.SaveChanges();
     }
 }
        private void bSave_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrWhiteSpace(tbFirstName.Text))
            {
                MessageBox.Show("Поле 'Имя' должно быть заполнено!");
                return;
            }

            if (_PhoneNumberItems.FirstOrDefault(x => String.IsNullOrWhiteSpace(x.Number)) != null)
            {
                MessageBox.Show("Поле 'Телефон' должно быть заполнено!");
                return;
            }

            var fullPath = iPersonImage.Source.ToString().Remove(0, 8);
            var name = fullPath.Split('/').Last();
            var projectPath = Environment.CurrentDirectory;
            var newFilePath = "PeopleImages/" + name;

            if (!File.Exists(newFilePath))
            {
                File.Copy(fullPath, projectPath + '/' + newFilePath);
            }

            var person = new Person(
                tbFirstName.Text,
                tbLastName.Text,
                tbPatronymic.Text,
                newFilePath);

            person.AddPhones(_PhoneNumberItems
                .Where(x => !String.IsNullOrWhiteSpace(x.Number))
                .Select(x => _PhoneNumberConverter.Convert(x))
                .ToList());

            try
            {
                using (var service = new PhoneBookCRUDService())
                {
                    service.AddPerson(person);
                }
            }
            catch (DuplicatePersonNameException ex)
            {
                MessageBox.Show("Контакт с таким именем уже существует!");
                return;
            }

            PageSwitcher.Switch(new PeopleListPage());
        }
 public SuitablePhoneNumber(Person person, PhoneNumber phoneNumber)
 {
     this.Person = person;
     this.PhoneNumber = phoneNumber;
 }