private void AddChild(object obj) { ChildViewModel viewModel = new ChildViewModel { Count = "1", IsAdd = true, Persons = ListsOfPersons, SelectedPerson = ListsOfPersons.FirstOrDefault() }; AddChildView view = new AddChildView { DataContext = viewModel }; Child newChild = new Child(); view.ShowDialog(); if (viewModel.IsConfirm) { newChild.child = viewModel.SelectedPerson; newChild.Count = Convert.ToDecimal(viewModel.Count); if (CheckIfValid(SelectedPerson, newChild)) { var res = db.AddChild(SelectedPerson, newChild); if (res == false) { MessageBox.Show("Wystąpił błąd przy dodawaniu!"); } Refresh(); } } }
public void GetAncesotor(List <string> listofAncestors, Person person) { if (person.Father != null) { listofAncestors.Add(person.Father); person = ListsOfPersons.Where(x => x.Name == person.Father).FirstOrDefault(); GetAncesotor(listofAncestors, person); } if (person.Mother != null) { listofAncestors.Add(person.Mother); person = ListsOfPersons.Where(x => x.Name == person.Mother).FirstOrDefault(); GetAncesotor(listofAncestors, person); } }
private void Refresh() { CountPerson = db.GetPerson <Person>().Count; CountChild = db.GetPerson <Child>().Count; string name = SelectedChild?.child.Name; string listName = SelectedPerson?.Name; Clear(); ListsOfPersons.AddRange(db.GetPerson <Person>()); SelectedPerson = ListsOfPersons.FirstOrDefault(x => x.Name == listName) ?? ListsOfPersons.FirstOrDefault(); SelectedChild = SelectedPerson?.Children.FirstOrDefault(x => x.child.Name == name); if (SelectedChild != null) { return; } SelectedChild = SelectedPerson?.Children.FirstOrDefault(); }
private void Clear() { ListsOfPersons.Clear(); SelectedChild = null; SelectedPerson = null; }