Beispiel #1
0
        private void OpenAuthorManagementDialog()
        {
            EntityManagementDialog <AuthorViewModel>          dialog          = new EntityManagementDialog <AuthorViewModel>();
            EntityManagementDialogViewModel <AuthorViewModel> dialogViewModel = new EntityManagementDialogViewModel <AuthorViewModel>(dialog, LibraryVM, "Authorの管理",
                                                                                                                                      new Func <string, AuthorViewModel>((name) =>
            {
                var author           = new AuthorViewModel();
                author.ID            = Guid.NewGuid();
                author.UnescapedName = name;
                AuthorFacade.Create(author);
                return(author);
            }),
                                                                                                                                      new Func <IEnumerable <AuthorViewModel> >(() =>
            {
                return(AuthorFacade.OrderByNaturalString());
            }),
                                                                                                                                      new Func <Guid, AuthorViewModel>((id) =>
            {
                return(AuthorFacade.FindBy(id));
            }),
                                                                                                                                      new Action <AuthorViewModel>((target) =>
            {
                AuthorFacade.Update(target);
                var willUpdate = LibraryVM.BookSource.Where(b => b.AuthorID == target.ID);
                foreach (var x in willUpdate)
                {
                    x.Author = target.Clone() as AuthorViewModel;
                }
            }),
                                                                                                                                      new Action <Guid>((id) =>
            {
                AuthorFacade.Delete(id);
                var willUpdate = LibraryVM.BookSource.Where(b => b.AuthorID == id);
                foreach (var x in willUpdate)
                {
                    x.Author = null;
                }
            }),
                                                                                                                                      new Action <AuthorViewModel, AuthorViewModel>((willDiscard, into) =>
            {
                AuthorFacade.Delete(willDiscard.ID);
                var willUpdate = LibraryVM.BookSource.Where(b => b.AuthorID == willDiscard.ID);
                foreach (var x in willUpdate)
                {
                    x.Author = into.Clone() as AuthorViewModel;
                    BookFacade.Update(x);
                }
            }));

            dialog.EntityMngVM = dialogViewModel;
            dialogViewModel.Initialize();
            dialog.Show();
        }
Beispiel #2
0
        public void UpdateAuthorsTest()
        {
            var changeList = new AuthorViewModel[]
            {
                new AuthorViewModel(new Guid(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1), "村杉 周治"),
                new AuthorViewModel(new Guid(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2), "角屋 譲司"),
                new AuthorViewModel(new Guid(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3), "松嵜 紀昭"),
                new AuthorViewModel(new Guid(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4), "司馬 悠"),
                new AuthorViewModel(new Guid(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5), "今藤 勝一"),
                new AuthorViewModel(new Guid(0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1), "Duy Owen Lovell"),
                new AuthorViewModel(new Guid(0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2), "Cool Hong Rajesh"),
                new AuthorViewModel(new Guid(0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3), "Rafi Nath Post"),
                new AuthorViewModel(new Guid(0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 4), "Raven Jude Heard"),
                new AuthorViewModel(new Guid(0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 5), "Jeric Kelvin Yeager")
            };

            AuthorFacade.Update(changeList[0]);
            AuthorFacade.Update(changeList[1]);
            AuthorFacade.Update(changeList[2]);
            AuthorFacade.Update(changeList[3]);
            AuthorFacade.Update(changeList[4]);
            AuthorFacade.Update(changeList[5]);
            AuthorFacade.Update(changeList[6]);
            AuthorFacade.Update(changeList[7]);
            AuthorFacade.Update(changeList[8]);
            AuthorFacade.Update(changeList[9]);

            var items = AuthorFacade.FindAll();

            Assert.That(items.Count, Is.EqualTo(20));
            Assert.That(items.ElementAt(0), Is.EqualTo(changeList[0]));
            Assert.That(items.ElementAt(1), Is.EqualTo(changeList[1]));
            Assert.That(items.ElementAt(2), Is.EqualTo(changeList[2]));
            Assert.That(items.ElementAt(3), Is.EqualTo(changeList[3]));
            Assert.That(items.ElementAt(4), Is.EqualTo(changeList[4]));
            Assert.That(items.ElementAt(5), Is.EqualTo(_authors[5]));
            Assert.That(items.ElementAt(6), Is.EqualTo(_authors[6]));
            Assert.That(items.ElementAt(7), Is.EqualTo(_authors[7]));
            Assert.That(items.ElementAt(8), Is.EqualTo(_authors[8]));
            Assert.That(items.ElementAt(9), Is.EqualTo(_authors[9]));
            Assert.That(items.ElementAt(10), Is.EqualTo(changeList[5]));
            Assert.That(items.ElementAt(11), Is.EqualTo(changeList[6]));
            Assert.That(items.ElementAt(12), Is.EqualTo(changeList[7]));
            Assert.That(items.ElementAt(13), Is.EqualTo(changeList[8]));
            Assert.That(items.ElementAt(14), Is.EqualTo(changeList[9]));
            Assert.That(items.ElementAt(15), Is.EqualTo(_authors[15]));
            Assert.That(items.ElementAt(16), Is.EqualTo(_authors[16]));
            Assert.That(items.ElementAt(17), Is.EqualTo(_authors[17]));
            Assert.That(items.ElementAt(18), Is.EqualTo(_authors[18]));
            Assert.That(items.ElementAt(19), Is.EqualTo(_authors[19]));
        }
        private void RegisterCommands()
        {
            OkCommand
            .Subscribe(dialog =>
            {
                UpdateBook();
                RequestClose.Invoke(new DialogResult(ButtonResult.OK));
            })
            .AddTo(disposables);
            CancelCommand
            .Subscribe(dialog =>
            {
                RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
            })
            .AddTo(disposables);
            SelectNextBookCommand
            .Subscribe(() => SelectNextBook())
            .AddTo(disposables);
            SelectPreviousBookCommand
            .Subscribe(() => SelectPreviousBook())
            .AddTo(disposables);
            OpenSaveDirCommand
            .Subscribe(() => OpenDir())
            .AddTo(disposables);
            OpenAuthorManagementDialogCommand
            .Subscribe(() =>
            {
                var dialog          = new EntityManagementDialog <AuthorViewModel>();
                var dialogViewModel = new EntityManagementDialogViewModel <AuthorViewModel>(dialog, LibraryManager, "Authorの管理",
                                                                                            new Func <string, AuthorViewModel>((name) =>
                {
                    var author           = new AuthorViewModel();
                    author.ID            = Guid.NewGuid();
                    author.UnescapedName = name;
                    AuthorFacade.Create(author);
                    return(author);
                }),
                                                                                            new Func <IEnumerable <AuthorViewModel> >(() =>
                {
                    return(AuthorFacade.OrderByNaturalString());
                }),
                                                                                            new Func <Guid, AuthorViewModel>((id) =>
                {
                    return(AuthorFacade.FindBy(id));
                }),
                                                                                            new Action <AuthorViewModel>((target) =>
                {
                    AuthorFacade.Update(target);
                    var willUpdate = LibraryManager.BookSource.Where(b => b.AuthorID == target.ID);
                    foreach (var x in willUpdate)
                    {
                        x.Author = target.Clone() as AuthorViewModel;
                    }
                }),
                                                                                            new Action <Guid>((id) =>
                {
                    AuthorFacade.Delete(id);
                    var willUpdate = LibraryManager.BookSource.Where(b => b.AuthorID == id);
                    foreach (var x in willUpdate)
                    {
                        x.Author = null;
                    }
                }),
                                                                                            new Action <AuthorViewModel, AuthorViewModel>((willDiscard, into) =>
                {
                    AuthorFacade.Delete(willDiscard.ID);
                    var willUpdate = LibraryManager.BookSource.Where(b => b.AuthorID == willDiscard.ID);
                    foreach (var x in willUpdate)
                    {
                        x.Author = into.Clone() as AuthorViewModel;
                        BookFacade.Update(x);
                    }
                }));
                dialog.EntityMngVM = dialogViewModel;
                dialogViewModel.Initialize();
                dialog.Show();
            })
            .AddTo(disposables);
            TitleTextBoxKeyDownCommand = new ReactiveCommand <KeyEventArgs>();
            TitleTextBoxKeyDownCommand.Subscribe(e =>
            {
                switch (e.Key)
                {
                case Key.Enter:
                    UpdateBook();
                    RequestClose.Invoke(new DialogResult(ButtonResult.OK));
                    break;

                case Key.Escape:
                    RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
                    break;

                default:
                    break;
                }
            })
            .AddTo(disposables);
        }