public void AddNewReadBook(IAddNewReadBookView inForm, IReadRepository readRepository) { if (inForm.ShowViewModal() == true) { try { string title = inForm.Title; string author = inForm.Author; string publisher = inForm.Publisher; DateTime datePub = inForm.DatePublished; int numPages = inForm.NumberOfPages; string genre = inForm.Genre; DateTime dateRead = inForm.DateRead; int rating = inForm.Rating; BookRead newRead = BookFactory.CreateBookRead(title, author, publisher, datePub, numPages, genre, dateRead, rating); readRepository.AddBookRead(newRead); } catch (Exception ex) { MessageBox.Show("EXCEPTION: " + ex.Message); throw; } } }
private void InitialiseEditBook() { if (_mainModel.BooksRead.Count > 0) { _existingBook = _mainModel.BooksRead.Last(); } }
private void SelectImageForBook(BookRead book) { _log.Debug("Getting Book information for " + book.Title); // https://books.google.co.uk/ string searchTerm = GetImageSearchTerm(book); ImageSelectionViewModel selectionViewModel = new ImageSelectionViewModel(_log, book.Title, searchTerm); ImageSelectionWindow imageSelectDialog = new ImageSelectionWindow { DataContext = selectionViewModel }; var success = imageSelectDialog.ShowDialog(); if (success.HasValue && success.Value) { _log.Debug("Success Getting image information for " + book.Title + "\n Img = " + selectionViewModel.SelectedImageAddress); book.ImageUrl = selectionViewModel.SelectedImageAddress; // Update in the DB. string errorMsg; if (!_mainModel.UpdateBook(book, out errorMsg)) { MessageBox.Show(errorMsg); return; } OnPropertyChanged(() => ExistingBookImageSource); } else { _log.Debug("Failed Getting Book information for " + book.Title); } }
private bool IsBookValid(BookRead newBook, out string errorMsg) { errorMsg = ""; if (string.IsNullOrEmpty(newBook.Author)) { errorMsg = "Must provide an Author"; return(false); } if (string.IsNullOrEmpty(newBook.Title)) { errorMsg = "Must provide the Books's Title"; return(false); } if (string.IsNullOrEmpty(newBook.Nationality)) { errorMsg = "Must provide the Author's Home Country"; return(false); } if (string.IsNullOrEmpty(newBook.OriginalLanguage)) { errorMsg = "Must provide the Books's Original Language"; return(false); } if (_newBook.Pages < 1 && newBook.Format == BookFormat.Book) { errorMsg = "Must provide the number of pages for the books"; return(false); } return(true); }
public void UpdBook(Book book, BookRead bookRead) { Conexao conexao = new Conexao(); conexao.Conectar(); ExecutaSP executa = new ExecutaSP("BOOK_SP_UPD_BOOK", conexao.VoltaConexaoAberta()); try { executa.addParam("@ID", book.Id); executa.addParam("@NAME", book.Name); executa.addParam("@INDICATION", book.Indication); executa.addParam("@SAGA", book.Saga); executa.addParam("@RESUME", bookRead.Resume); executa.addParam("@DATESTART", bookRead.DateStart); executa.addParam("@DATEEND", bookRead.DateEnd); executa.Executa(); executa.Confirma(); } catch (Exception ex) { } }
private void UpdateList() { for (int i = 0; i < _listBooks.Count(); i++) { BookRead book = _listBooks[i]; string bookAuthor = book.Author; string bookPublisher = book.Publisher; string bookDatePublished = book.DatePublished.ToString(); string bookGenre = book.Genre; string bookPages = book.NumPages.ToString(); string bookFinished = book.DateRead.ToString(); string bookRating = book.Rating.ToString(); ListViewItem lvt = new ListViewItem(book.Title); lvt.SubItems.Add(bookAuthor); lvt.SubItems.Add(bookPublisher); lvt.SubItems.Add(bookDatePublished); lvt.SubItems.Add(bookPages); lvt.SubItems.Add(bookGenre); lvt.SubItems.Add(bookFinished); lvt.SubItems.Add(bookRating); listRead.Items.Add(lvt); } }
/// <summary> /// The command action to add a new book from the email to the database. /// </summary> public void SelectImageForBookCommandAction(object parameter) { BookRead book = _newBook; if (book != null) { _log.Debug("Getting Book information for " + book.Title); // https://books.google.co.uk/ string searchTerm = DataUpdaterViewModel.GetImageSearchTerm(book); ImageSelectionViewModel selectionViewModel = new ImageSelectionViewModel(_log, book.Title, searchTerm); ImageSelectionWindow imageSelectDialog = new ImageSelectionWindow { DataContext = selectionViewModel }; var success = imageSelectDialog.ShowDialog(); if (success.HasValue && success.Value) { _log.Debug("Success Getting image information for " + book.Title + "\n Img = " + selectionViewModel.SelectedImageAddress); book.ImageUrl = selectionViewModel.SelectedImageAddress; OnPropertyChanged(() => NewBookImageSource); } else { _log.Debug("Failed Getting Book information for " + book.Title); } } }
private void UpdateSelectedBook() { if (_selectedBook == null) { return; } // Create a new book for the db populated with the info rom the selection BookRead newBook = new BookRead { DateString = _selectedBook.DateString, Date = _selectedBook.Date, Author = _selectedBook.Author, Title = _selectedBook.Title, Format = _selectedBook.Format, Pages = _selectedBook.Pages, }; NewBook = newBook; NewBookAuthorText = _selectedBook.Author; OnPropertyChanged(() => NewBookAuthorText); NewBookFormat = _selectedBook.Format; _newBook.Audio = _selectedBook.Format == BookFormat.Audio ? "x" : ""; _newBook.Book = _selectedBook.Format == BookFormat.Book ? "x" : ""; _newBook.Comic = _selectedBook.Format == BookFormat.Comic ? "x" : ""; OnPropertyChanged(() => NewBookFormat); OnPropertyChanged(() => NewBookFormatIsAudio); OnPropertyChanged(() => NewBookFormatIsBook); OnPropertyChanged(() => NewBookFormatIsComic); OnPropertyChanged(() => NewBookImageSource); }
private BlockUIContainer GetBookBlockContainer(int itemIndex, BookRead bookRead) { BlockUIContainer bookBlockContainer = new BlockUIContainer(); ContentControl contentControl = new ContentControl { Margin = new Thickness(10), MinHeight = 100 }; string itemPath = "SelectedMonthBooksRead[" + itemIndex + "]"; Binding itemSourceBinding = new Binding { Source = this, Path = new PropertyPath(itemPath), Mode = BindingMode.OneWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; BindingOperations.SetBinding(contentControl, ContentControl.ContentProperty, itemSourceBinding); contentControl.ContentTemplate = CreateDataTemplate(!string.IsNullOrEmpty(bookRead.Note)); bookBlockContainer.Child = contentControl; return(bookBlockContainer); }
public void AddBookRead(BookRead bookRead) { bookRead._bookId = ++_lastId; _listBooks.Add(bookRead); NotifyObservers(); }
/// <summary> /// Adds a new user book read. /// </summary> /// <param name="bookReadAddRequest">The new book read to try to add.</param> /// <returns>The action result.</returns> public BookReadAddResponse AddNewBookRead(BookReadAddRequest bookReadAddRequest) { BookReadAddResponse response = new BookReadAddResponse { ErrorCode = (int)BookReadAddResponseCode.Success, FailReason = "", UserId = bookReadAddRequest.UserId }; // First check that the user exists User userLogin = _userDatabase.LoadedItems.FirstOrDefault(x => x.Id.ToString() == bookReadAddRequest.UserId); if (userLogin == null) { response.ErrorCode = (int)BookReadAddResponseCode.UnknownUser; response.FailReason = "Could not find this user."; return(response); } // Check the book data is valid BookRead newBook; if (!GetBookRead(bookReadAddRequest, out newBook)) { response.ErrorCode = (int)BookReadAddResponseCode.InvalidItem; response.FailReason = "Invalid book data please try again."; return(response); } // Check if this is duplicate GeographyProvider geographyProvider; BooksReadProvider booksReadProvider; _books = new ObservableCollection <Book>(); if (GetProviders(out geographyProvider, out booksReadProvider)) { BookRead match = booksReadProvider.BooksRead.FirstOrDefault( x => x.Author == newBook.Author && x.Title == newBook.Title && x.DateString == newBook.DateString); if (match != null) { response.ErrorCode = (int)BookReadAddResponseCode.Duplicate; response.FailReason = "This book has already been added."; return(response); } } newBook.User = userLogin.Name; _booksReadDatabase.AddNewItemToDatabase(newBook); response.NewItem = new Book(newBook); return(response); }
private WorldCountry GetCountryForBook(BookRead book) { if (_worldCountryLookup == null || _worldCountryLookup.Count == 0 || !_worldCountryLookup.ContainsKey(book.Nationality)) { return(null); } return(_worldCountryLookup[book.Nationality]); }
/// <summary> /// The command action to add a new book from the email to the database. /// </summary> public void SelectImageForBookCommandAction(object parameter) { BookRead book = parameter as BookRead; if (book != null) { SelectImageForBook(book); } }
public void Test_AddBookRead() { ReadRepository readRep = ReadRepository.getInstance(); BookRead readBook = new BookRead("Carrie", "Stephen King", "Hodder", DateTime.Now, 242, "horror", DateTime.Now, 2); readRep.AddBookRead(readBook); Assert.AreEqual(4, readRep.getReadBooksNum()); }
/// <summary> /// Gets if there is a valid new book read based on the request. /// </summary> /// <param name="addRequest">The request to add a book read.</param> /// <param name="newBook">The new book to add on exit.</param> /// <returns>True if a valid new book, false otherwise.</returns> private bool GetBookRead(BookReadAddRequest addRequest, out BookRead newBook) { newBook = new BookRead { Author = addRequest.Author, Title = addRequest.Title, Pages = addRequest.Pages, Note = addRequest.Note, Nationality = addRequest.Nationality, OriginalLanguage = addRequest.OriginalLanguage, ImageUrl = addRequest.ImageUrl, Tags = addRequest.Tags.ToList() }; // Check the required strings are ok. if (string.IsNullOrWhiteSpace(newBook.Author) || string.IsNullOrWhiteSpace(newBook.Title) || string.IsNullOrWhiteSpace(newBook.Nationality) || string.IsNullOrWhiteSpace(newBook.OriginalLanguage)) { return(false); } // Check the format is valid switch (addRequest.Format) { case "Book": newBook.Format = BookFormat.Book; break; case "Comic": newBook.Format = BookFormat.Comic; break; case "Audio": newBook.Format = BookFormat.Audio; break; default: return(false); } // Check the date if (DateTime.Now < addRequest.Date || addRequest.Date < EarliestDate) { return(false); } // Set the date string newBook.Date = addRequest.Date; newBook.DateString = SuffixedDaysOfMonths[newBook.Date.Day] + newBook.Date.ToString(" MMMM yyyy"); return(true); }
private void AddBookImageTableCell(HtmlTextWriter writer, BookRead book) { writer.AddStyleAttribute("width", ForBlog ? "30%" : "20%"); writer.AddAttribute(HtmlTextWriterAttribute.Rowspan, "7"); writer.RenderBeginTag(HtmlTextWriterTag.Td); { writer.AddAttribute(HtmlTextWriterAttribute.Src, book.ImageUrl); writer.AddAttribute(HtmlTextWriterAttribute.Alt, "No Image Provided"); writer.AddAttribute(HtmlTextWriterAttribute.Height, "200"); writer.RenderBeginTag(HtmlTextWriterTag.Img); writer.RenderEndTag(); } writer.RenderEndTag(); }
private void SelectImageForBook(BookRead book) { ImageSelectionWindowViewModel selectionViewModel = new ImageSelectionWindowViewModel { SearchTerm = $"{book.Author} {book.Title} amazon" }; ImageSelectionWindowView imageSelectDialog = new ImageSelectionWindowView(selectionViewModel); imageSelectDialog.ShowDialog(); if (selectionViewModel.DialogResult.HasValue && selectionViewModel.DialogResult.Value) { book.ImageUrl = selectionViewModel.SelectedImageAddress; OnPropertyChanged(() => BookImageSource); } }
private void InitialiseNewBook() { NewBookAuthorText = NewBookNationalityText = NewBookOriginalLanguageText = ""; DateTime newDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); _newBook = new BookRead() { Date = newDate, Format = BookFormat.Book, Book = "x", Comic = "", Audio = "", Note = "" }; }
public static string GetImageSearchTerm(BookRead book) { string nameAndTitle = book.Author + " " + book.Title + " amazon"; string[] words = nameAndTitle.Split(' '); string term = "http://www.google.co.uk/search?q=" + words[0]; for (int i = 1; i < words.Length; i++) { if (words[i] == "&") { continue; } term += "+"; term += words[i]; } return(term); }
public Book(BookRead book) { Id = book.Id.ToString(); DateString = book.DateString; Date = book.Date; Author = book.Author; Title = book.Title; Pages = book.Pages; Note = book.Note; Nationality = book.Nationality; OriginalLanguage = book.OriginalLanguage; ImageUrl = book.ImageUrl; User = book.User; Format = book.Format.ToString(); Tags = new string[book.Tags.Count]; for (int i = 0; i < book.Tags.Count; i++) { Tags[i] = book.Tags[i]; } }
private static void AddBookNotesToTableCells(HtmlTextWriter writer, BookRead book) { writer.RenderBeginTag(HtmlTextWriterTag.Th); { writer.RenderBeginTag(HtmlTextWriterTag.B); writer.Write("Notes: "); writer.RenderEndTag(); } writer.RenderEndTag(); writer.WriteLine(); writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "2"); writer.RenderBeginTag(HtmlTextWriterTag.Td); { writer.Write(book.Note); } writer.RenderEndTag(); writer.WriteLine(); }
public ActionResult UpdBook(int id, string name, string indication, string saga, string resume, DateTime start, DateTime end) { BookBLL bookBLL = new BookBLL(); Book book = new Book() { Id = id, Name = name, Indication = indication, Saga = saga }; BookRead bookRead = new BookRead() { IdBK = id, Resume = resume, DateStart = start, DateEnd = end }; bookBLL.UpdBook(book, bookRead); return(RedirectToAction("./View/BookRead/Index")); }
/// <summary> /// Reads the data for this import from the file specified. /// </summary> /// <param name="filename">The file to read from.</param> /// <param name="errorMessage">The error message if unsuccessful.</param> /// <returns>True if read successfully, false otherwise.</returns> public bool ReadFromFile(string filename, out string errorMessage) { errorMessage = string.Empty; // Check the file exists. if (!File.Exists(filename)) { errorMessage = $"File {filename} does not exist"; return(false); } // Try to deserialize the books file. try { using (StreamReader sr = new StreamReader(filename, Encoding.Default)) { CsvReader csv = new CsvReader(sr); ImportedItems.Clear(); // Date,DD/MM/YYYY,Author,Title,Pages,Note,Nationality,Original Language,Book,Comic,Audio,Image,Tags while (csv.Read()) { string stringFieldDate = csv.GetField <string>(0); string stringFieldDdmmyyyy = csv.GetField <string>(1); string stringFieldAuthor = csv.GetField <string>(2); string stringFieldTitle = csv.GetField <string>(3); string stringFieldPages = csv.GetField <string>(4); string stringFieldNote = csv.GetField <string>(5); string stringFieldNationality = csv.GetField <string>(6); string stringFieldOriginalLanguage = csv.GetField <string>(7); string stringFieldBook = csv.GetField <string>(8); string stringFieldComic = csv.GetField <string>(9); string stringFieldAudio = csv.GetField <string>(10); string stringFieldImage = csv.GetField <string>(11); string stringFieldTags = csv.GetField <string>(12); DateTime dateForBook; if (DateTime.TryParseExact(stringFieldDdmmyyyy, "d/M/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateForBook)) { ushort pages; ushort.TryParse(stringFieldPages, out pages); List <string> tags = new List <string>(); if (stringFieldTags.Length > 0) { tags = stringFieldTags.Split(',').ToList(); } BookRead book = new BookRead { DateString = stringFieldDate, Date = dateForBook, Author = stringFieldAuthor, Title = stringFieldTitle, Pages = pages, Note = stringFieldNote, Nationality = stringFieldNationality, OriginalLanguage = stringFieldOriginalLanguage, Audio = stringFieldAudio, Book = stringFieldBook, Comic = stringFieldComic, ImageUrl = stringFieldImage, Tags = tags }; ImportedItems.Add(book); } } } } catch (Exception e) { errorMessage = e.ToString(); return(false); } return(true); }
private void WriteIndividualBookTable(HtmlTextWriter writer, BookRead book) { writer.WriteLine(); writer.AddStyleAttribute("font-size", "12pt"); writer.AddStyleAttribute("width", ForBlog ? "90%" : "75%"); writer.AddAttribute(HtmlTextWriterAttribute.Align, "center"); writer.RenderBeginTag(HtmlTextWriterTag.Table); { writer.RenderBeginTag(HtmlTextWriterTag.Tr); { AddBookImageTableCell(writer, book); AddBookValueTableCell(writer, "Title: ", book.Title); } writer.RenderEndTag(); writer.RenderBeginTag(HtmlTextWriterTag.Tr); { AddBookValueTableCell(writer, "Author: ", book.Author); } writer.RenderEndTag(); writer.WriteLine(); writer.RenderBeginTag(HtmlTextWriterTag.Tr); { AddBookValueTableCell(writer, "Pages: ", book.Pages.ToString()); } writer.RenderEndTag(); writer.WriteLine(); writer.RenderBeginTag(HtmlTextWriterTag.Tr); { AddBookValueTableCell(writer, "Nationality: ", book.Nationality); } writer.RenderEndTag(); writer.WriteLine(); writer.RenderBeginTag(HtmlTextWriterTag.Tr); { AddBookValueTableCell(writer, "Original Language: ", book.OriginalLanguage); } writer.RenderEndTag(); writer.WriteLine(); writer.RenderBeginTag(HtmlTextWriterTag.Tr); { AddBookValueTableCell(writer, "Date: ", book.DateString); } writer.RenderEndTag(); writer.WriteLine(); writer.RenderBeginTag(HtmlTextWriterTag.Tr); { AddBookValueTableCell(writer, "Format: ", book.Format.ToString()); } writer.RenderEndTag(); writer.WriteLine(); if (!string.IsNullOrEmpty(book.Note)) { AddBookNotesToTableCells(writer, book); } } writer.RenderEndTag(); writer.WriteLine(); writer.RenderBeginTag(HtmlTextWriterTag.Br); writer.RenderEndTag(); writer.WriteLine(); }
public BookReadAddResponse UpdateExistingBook(Book existingBook) { // set up the successful response BookReadAddResponse response = new BookReadAddResponse { ErrorCode = (int)UserResponseCode.Success, NewItem = new Book(existingBook), FailReason = "", UserId = "" }; // First check that the user exists User userLogin = _userDatabase.LoadedItems.FirstOrDefault(x => x.Id.ToString() == existingBook.User); if (userLogin == null) { response.ErrorCode = (int)BookReadAddResponseCode.UnknownUser; response.FailReason = "Could not find this user."; return(response); } // Check the book data is valid BookRead newBook; if (!GetBookRead(existingBook, out newBook)) { response.ErrorCode = (int)BookReadAddResponseCode.InvalidItem; response.FailReason = "Invalid book data please try again."; return(response); } // Find the item GeographyProvider geographyProvider; BooksReadProvider booksReadProvider; _books = new ObservableCollection <Book>(); if (GetProviders(out geographyProvider, out booksReadProvider)) { BookRead itemToUpdate = _booksReadDatabase.LoadedItems.FirstOrDefault(x => x.Id.ToString() == existingBook.Id); if (itemToUpdate == null) { response.ErrorCode = (int)BookReadAddResponseCode.UnknownItem; response.FailReason = "Could not find item"; } else { itemToUpdate.DateString = newBook.DateString; itemToUpdate.Date = newBook.Date; itemToUpdate.Author = newBook.Author; itemToUpdate.Title = newBook.Title; itemToUpdate.Pages = newBook.Pages; itemToUpdate.Note = newBook.Note; itemToUpdate.Nationality = newBook.Nationality; itemToUpdate.OriginalLanguage = newBook.OriginalLanguage; itemToUpdate.ImageUrl = newBook.ImageUrl; itemToUpdate.Tags = newBook.Tags.ToList(); itemToUpdate.Format = newBook.Format; _booksReadDatabase.UpdateDatabaseItem(itemToUpdate); } } return(response); }