Exemple #1
0
        private void EditPerson(object obj)
        {
            var viewmodel = new PersonViewModel
            {
                Name       = SelectedPerson.Name,
                DayOfBirth = DateTime.Parse(SelectedPerson.BirthDate),
                DayOfDeath = DateTime.Parse(SelectedPerson.DeathDate),
                Gender     = (Gender)Enum.Parse(typeof(Gender), SelectedPerson.Gender)
            };
            EditList view = new EditList {
                DataContext = viewmodel
            };

            view.ShowDialog();
            if (viewmodel.IsConfirm)
            {
                var birthDate = viewmodel.DayOfBirth.Date;
                var deathDate = viewmodel.DayOfDeath.Date;
                viewmodel.BirthDate = birthDate.ToString("d");
                viewmodel.DeathDate = deathDate.ToString("d");
                var gender = viewmodel.Gender.ToString();

                if (SelectedPerson.Children.Any())
                {
                    Person newPerson = new Person
                    {
                        BirthDate = birthDate.ToString("d"),
                        DeathDate = deathDate.ToString("d"),
                        Gender    = gender
                    };

                    foreach (var child in SelectedPerson.Children)
                    {
                        if (!CheckIfValid(newPerson, child, false))
                        {
                            return;
                        }
                    }
                }
                var result = db.EditPerson(SelectedPerson, viewmodel.Name, viewmodel.BirthDate, viewmodel.DeathDate, gender);
                if (result == false)
                {
                    MessageBox.Show("Wystąpił błąd przy edycji jednostki");
                }
                Refresh();
            }
        }