Exemplo n.º 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();
        }
Exemplo n.º 2
0
 public EntityManagementDialogViewModel(EntityManagementDialog <E> dialog, ILibrary libVM, string title,
                                        Func <string, E> add,
                                        Func <IEnumerable <E> > readAll,
                                        Func <Guid, E> readBy,
                                        Action <E> update,
                                        Action <Guid> remove,
                                        Action <E, E> integrate)
 {
     _parent    = dialog;
     _libVM     = libVM;
     Title      = title;
     _add       = add;
     _readAll   = readAll;
     _readBy    = readBy;
     _update    = update;
     _remove    = remove;
     _integrate = integrate;
 }
Exemplo n.º 3
0
        private void OpenTagManagementDialog()
        {
            EntityManagementDialog <TagViewModel>          dialog          = new EntityManagementDialog <TagViewModel>();
            EntityManagementDialogViewModel <TagViewModel> dialogViewModel = new EntityManagementDialogViewModel <TagViewModel>(dialog, LibraryVM, "タグの管理",
                                                                                                                                new Func <string, TagViewModel>((name) =>
            {
                var tag           = new TagViewModel();
                tag.ID            = Guid.NewGuid();
                tag.UnescapedName = name;
                TagFacade.Insert(tag);
                return(tag);
            }),
                                                                                                                                new Func <IEnumerable <TagViewModel> >(() =>
            {
                return(TagFacade.OrderByNaturalString());
            }),
                                                                                                                                new Func <Guid, TagViewModel>((id) =>
            {
                return(TagFacade.FindBy(id));
            }),
                                                                                                                                null,
                                                                                                                                new Action <Guid>((id) =>
            {
                TagFacade.Delete(id);
                var willDelete = TagManager.Chains.Where(t => t.TagID == id).ToList();
                foreach (var del in willDelete)
                {
                    TagManager.Chains.Remove(del);
                }
            }),
                                                                                                                                null);

            dialog.EntityMngVM = dialogViewModel;
            dialogViewModel.Initialize();
            dialog.Show();
        }
        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);
        }