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 AddBook() { BookServices bookServices = new BookServices(); OpenFileDialog openFileDialog = new OpenFileDialog { Filter = Searchfilter }; openFileDialog.ShowDialog(); _pathToFile = bookServices.MoveBookToBookShelfFolder(Path.GetFullPath(openFileDialog.FileName)); FileInfo fileToAdd = new FileInfo(_pathToFile); int size = (int)fileToAdd.Length; string fileType = Path.GetExtension(openFileDialog.FileName); if (fileType == ".pdf") { //TODO Convert this in separete method to avoid code duplication //Implementation of template Method ImageService imageService = new ImageService(); _pathtobookimage = imageService.GenerateImage(_pathToFile); } var book = new Book() { Name = Path.GetFileNameWithoutExtension(openFileDialog.FileName), FileType = fileType, Path = _pathToFile, PathToBookImg = _pathtobookimage, Author = "Unknown Author", Size = size }; _bookRepository.Add(book); _bookRepository.SaveChanges(); var allbooks = _bookRepository.GetAll(); Books = new ObservableCollection<Book>(allbooks); }
private void DeleteBookCover() { ImageService service = new ImageService(); service.DeleteBookPicture(_selectedBook.PathToBookImg); }