Ejemplo n.º 1
0
        public ActionResult StudentSearchBooks(int id, string searchString)
        {
            booktrackingdbEntities db = new booktrackingdbEntities();

            var model = new BookInfoViewModel();

            model.stu_id = id;

            if (!String.IsNullOrEmpty(searchString))
            {
                model.BookListing = db.Books.Where(x => x.BookName.Contains(searchString)).ToList();
                if (model.BookListing.Count == 0)
                {
                    model.BookListing = db.Books.Where(x => x.Author.Contains(searchString)).ToList();
                }
                if (model.BookListing.Count == 0)
                {
                    model.BookListing = db.Books.Where(x => x.ISBN.Contains(searchString)).ToList();
                }
            }
            else
            {
                model.BookListing = db.Books.ToList();
            }

            model.thisStuOrderListing = db.Orders.Where(x => x.OStudentID == id).ToList();
            model.thisStuOrderListing = model.thisStuOrderListing.Where(x => x.Status == "Pending" || x.Status == "Approved" || x.Status == "Declined" || x.Status == "Checked Out").ToList();

            model.display = true;

            return(View(model));
        }
Ejemplo n.º 2
0
 public BookInfo(bool isExist, int id = -1)
 {
     InitializeComponent();
     this.isExist = isExist;
     book         = new BookInfoViewModel(isExist, id);
     DataContext  = book;
 }
Ejemplo n.º 3
0
        public IActionResult Info(int id)
        {
            Book book = _iBookRepository.GetByIdWithBookHistory(id);

            if (book == null)
            {
                return(RedirectToAction("List"));
            }

            Author author = _iAuthorRepository.GetById(book.AuthorId);

            BookInfoViewModel bookInfoViewModel = new BookInfoViewModel();

            bookInfoViewModel.Book   = book;
            bookInfoViewModel.Author = author;

            foreach (BookHistory history in book.BooksHistory)
            {
                BookHistoryModel model = new BookHistoryModel();
                model.ReaderId     = history.ReaderId;
                model.ReaderName   = history.Reader.Name;
                model.BorrowedDate = history.BorrowedDate;
                model.ReturnDate   = history.ReturnDate;

                bookInfoViewModel.BookHistoryModel.Add(model);
            }

            return(View(bookInfoViewModel));
        }
Ejemplo n.º 4
0
        public ViewResult BookInfo(int bookId = 6)
        {
            ViewBag.IsAuth = IsAuth();
            BookInfoViewModel book = new BookInfoViewModel(repository.Books.Include(b => b.Bookings).Include(b => b.Comments).FirstOrDefault(b => b.BookID == bookId));

            return(View(book));
        }
        /// <summary>
        /// This method opens a book when the book's cover image is clicked.
        /// </summary>
        /// <param name="bookInfo">The book info view model.</param>
        private async void OnClickBookCoverImage(BookInfoViewModel bookInfo)
        {
            if (bookInfo == null)
            {
                await DisplayAlert("Attention",
                                   "Something went wrong. I can't open this book. Please check does it exist yet?", "Cancel");

                throw new ArgumentNullException(nameof(bookInfo));
            }
            else
            {
                if (string.IsNullOrEmpty(bookInfo.FilePath))
                {
                    await DisplayAlert("Attention",
                                       "Something went wrong. The path to the book file is empty or it is invalid.", "Cancel");

                    throw new ArgumentException(nameof(bookInfo.FilePath));
                }
                else
                {
                    EpubBook epubBook = await EpubReader.EpubReader.ReadBookAsync(bookInfo.FilePath).ConfigureAwait(false);

                    SettingsEntity        settings = this.settingsRepository.GetById(bookInfo.Id);
                    BookTextPageViewModel page     = new BookTextPageViewModel(epubBook, settings, this.settingsRepository)
                    {
                        Title = "Go to Main page"
                    };

                    Xamarin.Forms.Device.BeginInvokeOnMainThread(() => this.Navigation.PushAsync(page));
                }
            }
        }
Ejemplo n.º 6
0
        private async void Info_Click(object sender, RoutedEventArgs e)
        {
            BookInfoViewModel bookinfo = new BookInfoViewModel();
            await bookinfo.LoadData(((HotPushItem)((FrameworkElement)((FrameworkElement)e.Source).Parent).DataContext).NovelID.ToString());

            BookInfoPage page = new BookInfoPage(bookinfo.BookInfo);

            NavigationService.Navigate(page);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Returns the view
        /// </summary>
        /// <returns></returns>
        public IActionResult UpdateProgress()
        {
            IEnumerable <BookInfoDTO> bookinfoDTO = libService.GetBooks(connectionString);
            PageInfo          pageinfo            = new PageInfo(bookinfoDTO.Count(), 0, 5);
            BookInfoViewModel bvm = new BookInfoViewModel {
                PageInfo = pageinfo, Books = bookinfoDTO
            };

            return(View(bvm));
        }
Ejemplo n.º 8
0
        public ActionResult addBooks(int id)
        {
            booktrackingdbEntities db = new booktrackingdbEntities();

            var model = new BookInfoViewModel();

            model.adm_id = id;

            return(View(model));
        }
Ejemplo n.º 9
0
        public ActionResult bookInventory(int admid)
        {
            booktrackingdbEntities db = new booktrackingdbEntities();

            var model = new BookInfoViewModel();

            model.BookListing = db.Books.ToList();

            return(View(model));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Returns the view
        /// </summary>
        /// <returns></returns>
        public IActionResult DeleteAnAuthor()
        {
            IEnumerable <AuthorDTO> authorinfoDTO = libService.GetAuthors(connectionString);
            PageInfo          pageinfo            = new PageInfo(authorinfoDTO.Count(), 0, 5);
            BookInfoViewModel bvm = new BookInfoViewModel {
                PageInfo = pageinfo, Authors = authorinfoDTO
            };

            return(View(bvm));
        }
        /// <summary>
        /// Convert book entity to the book info view model.
        /// </summary>
        /// <param name="entity">The book entity.</param>
        /// <returns>Book info view model.</returns>
        public static BookInfoViewModel ToBookInfoModelMapper(this BookEntity entity)
        {
            if (entity == null)
            {
                return(null);
            }

            BookInfoViewModel model = new BookInfoViewModel(entity.Id, entity.Title, entity.Author, entity.Cover, entity.FilePath);

            return(model);
        }
Ejemplo n.º 12
0
        public void BookInfoViewModel_CreateAnObject()
        {
            // arrange
            string expected = "BookInfoViewModel";
            // act
            BookInfoViewModel book = new BookInfoViewModel();

            //assert
            Assert.IsNotNull(book);
            Assert.AreEqual(expected, book.GetType().Name);
        }
Ejemplo n.º 13
0
        public ActionResult BookInfo(int id = -1)
        {
            var book  = _bookService.GetBook(id);
            var book1 = Mapper.Map <Book, BookViewModel>(book);
            var model = new BookInfoViewModel()
            {
                Book      = book1,
                Page      = 0,
                PageCount = 0//TODO: pages
            };

            if (book1 != null)
            {
                return(View(model));
            }
            return(HttpNotFound());
        }
        /// <summary>
        /// Converts a collection of book entities to a collection of book info view models.
        /// </summary>
        /// <param name="booksEntities">A collection of book entities.</param>
        /// <returns>A collection of book info view models.</returns>
        public static List <BookInfoViewModel> ToListOfBookInfoViewModel(this IEnumerable <BookEntity> booksEntities)
        {
            if (booksEntities == null)
            {
                return(null);
            }

            List <BookInfoViewModel> models = new List <BookInfoViewModel>();

            foreach (BookEntity entity in booksEntities)
            {
                BookInfoViewModel model = entity.ToBookInfoModelMapper();
                models.Add(model);
            }

            return(models);
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Returns the view with list of books
 /// </summary>
 /// <returns></returns>
 public IActionResult Index(int page = 1)
 {
     try
     {
         int pagesize = 10;
         IEnumerable <BookInfoDTO> bookinfoDTO = libService.GetBooks(connectionString);
         int               totalpages          = bookinfoDTO.Count();
         PageInfo          pageinfo            = new PageInfo(totalpages, page, pagesize);
         BookInfoViewModel bvm = new BookInfoViewModel {
             PageInfo = pageinfo, Books = bookinfoDTO.Skip((page - 1) * pagesize).Take(pagesize)
         };
         return(View(bvm));
     }
     catch (ValidationException ex)
     {
         return(Content(ex.Message.ToString()));
     }
 }
        /// <summary>
        /// This method represents a handle for the long press action.
        /// </summary>
        /// <param name="bookInfo">The book info view model.</param>
        private async void OnLongPressBookCoverImage(BookInfoViewModel bookInfo)
        {
            string action = await DisplayActionSheet(null, "Cancel", null, "Open", "Open in Hybrid", "Delete");

            switch (action)
            {
            case ("Open"):
                this.OnClickBookCoverImage(bookInfo);
                break;

            case ("Open in Hybrid"):
                await DisplayAlert("Alert", "This part was deleted.", "Cancel");

                break;

            case ("Delete"):
                SQLiteResult result = this.bookRepository.DeleteById(bookInfo.Id);
                // is statusCode == 1 OK
                this.books.Remove(bookInfo);
                this.UpdateBookLibrary(this.books);
                break;
            }
        }
Ejemplo n.º 17
0
        private async void TextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                if (Regex.IsMatch(CommandBox.Text, @"(?<=GOTO )\S*", RegexOptions.IgnoreCase))
                {
                    BookInfoViewModel bookinfo = new BookInfoViewModel();
                    await bookinfo.LoadData(Regex.Match(CommandBox.Text, @"(?<=GOTO )\S*", RegexOptions.IgnoreCase).Value);

                    BookInfoPage page = new BookInfoPage(bookinfo.BookInfo);
                    NavigationService.Navigate(page);
                }
                if (Regex.IsMatch(CommandBox.Text, @"(?<=SearchNovel )\S*", RegexOptions.IgnoreCase))
                {
                    BookListPage page = new BookListPage("Novel", Regex.Match(CommandBox.Text, @"(?<=SearchNovel )\S*", RegexOptions.IgnoreCase).Value);
                    NavigationService.Navigate(page);
                }
                if (Regex.IsMatch(CommandBox.Text, @"(?<=SearchChatNovel )\S*", RegexOptions.IgnoreCase))
                {
                    BookListPage page = new BookListPage("ChatNovel", Regex.Match(CommandBox.Text, @"(?<=SearchChatNovel )\S*", RegexOptions.IgnoreCase).Value);
                    NavigationService.Navigate(page);
                }
            }
        }
        /// <summary>
        /// This method is looking for a books, adds books to the main page if they are not contains in the database,
        /// deletes books if they don't exist on the user's device. It helps to hold actual data.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="args">An object that contains the event data.</param>
        private async void OnClickSearchBooksButton(object sender, EventArgs args)
        {
            IFiler filer = DependencyService.Get <IFiler>();
            IEnumerable <string> pathsOfFoundFiles = await filer.GetFilesPathsAsync(FileExtension.EPUB).ConfigureAwait(false);

            List <EpubBook> epubBooks = new List <EpubBook>();

            foreach (var path in pathsOfFoundFiles)
            {
                EpubBook book = await EpubReader.EpubReader.ReadBookAsync(path).ConfigureAwait(false);

                epubBooks.Add(book);
            }

            List <string> pathsOfExistingFiles = this.bookEntities.Select(entity => entity.FilePath).ToList();

            // Try to read not all book information.
            // I need to read only a necessary information e.g. Title, Author, Cover.
            foreach (EpubBook epubBook in epubBooks)
            {
                // If the book entity does not exist.
                // Add a new book info to the main page.
                if (pathsOfExistingFiles.Contains(epubBook.FilePath) == false)
                {
                    BookEntity bookEntity = new BookEntity
                    {
                        Id     = Guid.NewGuid().ToNonDashedString(),
                        Title  = epubBook.Title,
                        Author = epubBook.Author,
                        // It should be changed.
                        // An image might be missed.
                        Cover    = epubBook.Content.Images.FirstOrDefault().Value.Content,
                        FilePath = epubBook.FilePath
                    };

                    SettingsEntity settingsEntity = new SettingsEntity
                    {
                        BookId   = bookEntity.Id,
                        LastPage = 1,
                        FontSize = 14
                    };

                    SQLiteResult result = this.bookRepository.Add(bookEntity);
                    SQLiteResult settingsInsertResult = this.settingsRepository.Add(settingsEntity);

                    // 0 is SQLITE_OK
                    // But returns 1 and entity is successfully saved into database.
                    //if (bookInsertStatusCode == 1)
                    //{
                    this.bookEntities.Add(bookEntity);
                    BookInfoViewModel model = bookEntity.ToBookInfoModelMapper();
                    this.books.Add(model);
                    //}
                }
            }

            // Delete book info models and book entities which do not exist yet.
            foreach (var pathOfExistingFile in pathsOfExistingFiles)
            {
                if (pathsOfFoundFiles.Contains(pathOfExistingFile) == false)
                {
                    // Delete entity.
                    BookEntity deletedBookEntity = this.bookEntities.FirstOrDefault(e => e.FilePath == pathOfExistingFile);
                    this.bookRepository.DeleteById(deletedBookEntity.Id);
                    this.bookEntities.Remove(deletedBookEntity);

                    // Delete book info view model.
                    BookInfoViewModel deletedBookInfoViewModel = this.books.FirstOrDefault(m => m.FilePath == pathOfExistingFile);
                    this.books.Remove(deletedBookInfoViewModel);
                }
            }

            Xamarin.Forms.Device.BeginInvokeOnMainThread(() => this.UpdateBookLibrary(this.books));
        }