Ejemplo n.º 1
0
 // Constructeur de copie
 public BookViewModel(BookViewModel bvm)
 {
     this._authors = bvm._authors;
     this._authorService = bvm._authorService;
     this._book = bvm.Book;
     this._categories = bvm._categories;
     this._categoryService = bvm._categoryService;
     this._isNewPhoto = bvm._isNewPhoto;
     this._navigationServiceFacade = bvm._navigationServiceFacade;
     this._pageTitle = bvm._pageTitle;
     this._rates = bvm._rates;
     this._selectedAuthor = bvm._selectedAuthor;
     this._selectedCategory = bvm._selectedCategory;
     this._state = bvm._state;
     this._windowServices = bvm._windowServices;
 }
Ejemplo n.º 2
0
 protected override void CommandsInitialization()
 {
     DisplayCameraCommand = new ProxyCommand<BookViewModel>((_)=>
         {
             BookViewModel updatedDataContext = new BookViewModel(this);
             _windowServices.LaunchCameraCaptureTask<BookViewModel>(this, updatedDataContext, this._navigationServiceFacade);
         });
 }
Ejemplo n.º 3
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);
                });
        }