protected override void Edit() { int id = _ui.ReadInt("Book ID", 0); Book book = _bookDao.Get(id); if (book == null) { _ui.PrintLn("Book not found"); return; } _ui.PrintLn(book); _ui.PrintLn("Authors:"); foreach (var a in _authorDao.GetAll()) { _ui.PrintLn(a); } int authorId = _ui.ReadInt("Author ID", book.Author.Id); string title = _ui.ReadString("Title", book.Title); Author author = _authorDao.Get(authorId); if (author == null) { _ui.PrintLn("Author not found"); return; } book.Author = author; book.Title = title; _bookDao.Update(book); }
public void Update(Book book) { if (book.isCorrectState()) { bookDao.Update(book); } else { throw new ArgumentException("Error, updated book in incorrec state (empty fields)"); } }
public bool Update(Book book) => _bookDao.Update(book);
public IActionResult Update([FromForm] Book p) { _bookDao.Update(p); return(Ok()); }
public void Test_BookDao() { var nonCachedInstanceFetch = new Stopwatch(); var cachedInstanceFetch = new Stopwatch(); // Test cache efficiency nonCachedInstanceFetch.Start(); Book nonCachedBookInstance = BookDao.FindById(1); nonCachedInstanceFetch.Stop(); cachedInstanceFetch.Start(); Book cachedBookInstance = BookDao.FindById(1); cachedInstanceFetch.Stop(); Assert.IsTrue(cachedInstanceFetch.ElapsedTicks < nonCachedInstanceFetch.ElapsedTicks); /* ***************************** */ // Check if returned by findById() method instances // are BookProxy' instance Assert.IsTrue(cachedBookInstance is BookProxy); Assert.IsTrue(nonCachedBookInstance is BookProxy); // *find* methods tests IList <Book> allBooks = BookDao.FindAll(); IList <Book> foundByTitle = BookDao.FindByTitle("Fast Recipes"); IList <Book> foundByTitle2 = BookDao.FindByTitle("Fake Your Death"); IList <Book> foundByTitle3 = BookDao.FindByTitle("True"); IList <Book> foundByRating = BookDao.FindByRating(7.8f); IList <Book> foundBySection = BookDao.FindBySection(BookSection.FICTION); Assert.AreEqual(1, foundByTitle.Count); Assert.AreEqual(1, foundByTitle2.Count); Assert.AreEqual(2, foundByTitle3.Count); Assert.AreEqual(3, foundByRating.Count); Assert.AreEqual(5, foundBySection.Count); Book temp = BookDao.FindById(1); string tempTitle = temp.Title; // test refresh method temp.Title = "New Title"; BookDao.Refresh(temp); Assert.AreEqual(tempTitle, temp.Title); // test update method temp.Title = "New Title"; BookDao.Update(temp); Book temp1 = BookDao.FindById(temp.Id); Assert.AreEqual(temp1.Title, temp.Title); // test save method again temp.Title = "Title*"; BookDao.Save(temp, SaveOption.UPDATE_IF_EXIST); temp1 = BookDao.FindById(temp.Id); Assert.AreEqual(temp1.Title, temp.Title); }