Example #1
0
        private void DropFileInCategory(object sender, DragEventArgs e)
        {
            ImageService imgService = new ImageService();
            string[] fileList = e.Data.GetData(DataFormats.FileDrop) as string[];
            string fileextension = Path.GetExtension(fileList[0]);
            if (fileextension != ".pdf")
            {
                MessageBox.Show("Not allowed Drag'n'Drop for this file type");
            }
            else
            {
                string filename = Path.GetFileNameWithoutExtension(fileList[0]);
                string pathtofile = Path.GetFullPath(fileList[0]);
               
                string pathtobookimage = imgService.GenerateImage(pathtofile);
                FileInfo fileToAdd = new FileInfo(pathtofile);
                int size = (int)fileToAdd.Length;

                var book = new Book()
                {
                    Name = filename,
                    FileType = fileextension,
                    Path = pathtofile,
                    PathToBookImg = pathtobookimage,
                    Author = "Unknown Author",
                    Size = size
                };
                Debug.WriteLine(book.Name);
                _categoriesRepository = IoCManager.Kernel.Get<IRepository<Category>>();
                var concreteCategory = _categoriesRepository.GetByQery(q => q.Name == "Foreign Literature");
                concreteCategory.FirstOrDefault().Books.Add(book);
                _categoriesRepository.SaveChanges();
                MessageBox.Show("Book was added");
            }
        }
 private void GetBooks()
 {
     _bookRepository = IoCManager.Kernel.Get<IRepository<Book>>();
     var favoriteBooks = _bookRepository.GetByQery(q => q.IsFavorite);
     Books = new ObservableCollection<Book>(favoriteBooks);
 }
 private void GetBooks()
 {
     _bookRepository = IoCManager.Kernel.Get<IRepository<Book>>();
     var readBooks = _bookRepository.GetByQery(q => q.IsRead);
     Books = new ObservableCollection<Book>(readBooks);
 }