private void SaveButton_Click(object sender, RoutedEventArgs e) { nameTextBox.GetBindingExpression(TextBox.TextProperty).UpdateSource(); birthdayDatePicker.GetBindingExpression(DatePicker.SelectedDateProperty).UpdateSource(); if (Validation.GetHasError(nameTextBox) || Validation.GetHasError(birthdayDatePicker)) { MessageBox.Show("Please provide correct data"); } else { if (IsEdited) { CurrentPerson.Image = TemporaryPerson.Image; CurrentPerson.Name = TemporaryPerson.Name; CurrentPerson.Birthday = TemporaryPerson.Birthday; PeopleRepository.Save(); } else { var defaultOccasions = new ObservableCollection <Occasion>() { OccasionsRepository.GetAll().SingleOrDefault(x => x.Name == "New Year"), new Occasion { Date = TemporaryPerson.Birthday, Image = ImageHelper.BitmapSourceToByteArray(@"..\..\Images\DefaultOccasionImages\gift.png"), Name = TemporaryPerson.Name + "'s Birthday", } }; TemporaryPerson.Occasions = defaultOccasions; PeopleRepository.Add(TemporaryPerson); } this.Close(); } }
private void PlusButtonClicked(object sender, RoutedEventArgs e) { var groupName = (((sender as Button).TemplatedParent as GroupItem).Content as CollectionViewGroup).Name.ToString(); // what is written next to a plus button that was clicked if (CurrentPerson != null) { var currentOccasion = OccasionsRepository.GetAll().SingleOrDefault(x => x.Name == groupName && x.People.Contains(CurrentPerson)); new AddOrEditGiftWindow(Context, currentOccasion, CurrentPerson).ShowDialog(); } else if (CurrentOccasion != null) { var currentPerson = PeopleRepository.GetAll().SingleOrDefault(x => x.Name == groupName && x.Occasions.Contains(CurrentOccasion)); new AddOrEditGiftWindow(Context, CurrentOccasion, currentPerson).ShowDialog(); } }