Exemplo n.º 1
0
        public static BookmarkModel ToBookmarkModel(this Bookmark global)
        {
            BookmarkModel bookmark = new BookmarkModel
            {
                Id = global.Id,
                Name = global.Name,
                ReaderPage = global.ReaderPage,
                ThumbImage = global.ThumbImage,
                CreationDate = global.CreationDate
            };

            return bookmark;
        }
Exemplo n.º 2
0
        protected override void CommandsInitialization()
        {
            OpenAddBookCommand = new ProxyCommand<MainViewModel>((_) =>
                {
                    var viewModel = new BookViewModel(
                                new BookModel(),
                                "Créer un livre",
                                this._navigationServiceFacade, false);//TODO:mettre la chaîne "Créer un lvire" dans une ressource
                    viewModel.Book.BeginEdit();
                    _windowServices
                                .OpenSaveOrCancelWindow<BookViewModel>(
                                        viewModel, this._navigationServiceFacade, (bookVM) =>
                                    {
                                        bookVM.Book.EndEdit();

                                        var srvBook = ServiceLocator.Instance.Retrieve<IBookService>();

                                        // on évalue l'identifiant du prochain livre
                                        string nextBookId = (srvBook.GetLastCreatedId() + 1).ToString().PadLeft(4,'0');

                                        // création du chemin d'accès au fichier image qui contiendra
                                        // la photo de la couverture du livre
                                        string coverPath = "Librometer/images/cover" + nextBookId + ".jpg";

                                        // on sauvegarde le nouveau livre
                                        bookVM.Book.IdCategory = bookVM.SelectedCategory.Id;
                                        bookVM.Book.IdAuthor = bookVM.SelectedAuthor.Id;
                                        bookVM.Book.Cover = coverPath;
                                        bool ok = srvBook.Create(bookVM.Book);

                                        // on crée le nouveau Bookmark
                                        var srvBookmark = ServiceLocator.Instance.Retrieve<IBookmarkService>();
                                        BookmarkModel bookmark = new BookmarkModel()
                                        {
                                            CreationDate= DateTime.Now.ToShortDateString(),
                                            IdBook = 0,
                                            ThumbImage = coverPath,
                                            Name=bookVM.Book.Title,
                                            ReaderPage=0
                                        };
                                        srvBookmark.Create(bookmark);

                                        srvBook.ApplyChanges();
                                        srvBookmark.ApplyChanges();

                                        if (IsolatedStorageHelper.FileExist("Librometer/images/draft/cover.jpg") == true)
                                        {
                                            IsolatedStorageHelper.CopyFile("Librometer/images/draft/cover.jpg", coverPath);
                                            // on supprime l'image contenu dans le répertoire draft
                                            IsolatedStorageHelper.DeleteFile("Librometer/images/draft/cover.jpg");
                                        }

                                        return ok;

                                    }, null);
                });

            DisplayParametersCommand = new ProxyCommand<MainViewModel>((_) =>
                {
                    _windowServices.OpenNewPage(
                                new Uri("/Librometer.Views;component/SettingsPage.xaml", UriKind.Relative),
                                this._navigationServiceFacade);
                });
        }