/// <summary> /// Add book review /// </summary> /// <param name="sender"></param> public void AddBookLogReview(object sender = null) { var bookLogBookItem = (sender as Button).DataContext as BookLogBookItem; var dialog = new BookLogReviewDialog(); dialog.Closing += (sender, args) => { if (dialog.DataContext is BookLogReviewViewModel vm && vm.BookLogReviewItem.BookLogReview.Id > 0) { if (vm.BookLogReviewItem != null && !BookLogReviewItems.Any(x => x == vm.BookLogReviewItem)) { BookLogReviewItems.Insert(0, vm.BookLogReviewItem); } else { for (int i = 0; i < BookLogReviewItems.Count; i++) { if (BookLogReviewItems[i].BookLogReview.Id == vm.BookLogReviewItem.BookLogReview.Id) { BookLogReviewItems[i] = vm.BookLogReviewItem; break; } } } } }; dialog.ShowDialogWindow(new BookLogReviewViewModel(dialog, null, bookLogBookItem)); }
/// <summary> /// Edit book review /// </summary> /// <param name="sender"></param> public void EditBookLogReview(object sender) { var bookLogReviewItem = (sender as Button).DataContext as BookLogReviewItem; var dialog = new BookLogReviewDialog(); dialog.Closing += (sender, args) => { if (dialog.DataContext is BookLogReviewViewModel vm) { bookLogReviewItem = vm.BookLogReviewItem; } }; dialog.ShowDialogWindow(new BookLogReviewViewModel(dialog, bookLogReviewItem)); }