static void Main(string[] args) { try { logger.Trace("Начало работы программы"); logger.Trace("Создание книг начато"); Book a = new Book("Anna Korenina", "Tolstoy", 1878, "russian"); Book b = new Book("Idiot", "Dostoevsky", 1868, "russian"); Book c = new Book("Misery", "Stiven King", 1987, "english"); Book d = new Book("It", "Stiven King", 1985, "english"); logger.Trace("Создание книг завершено"); BineryFileStorage data = new BineryFileStorage(); BookListService dataService = new BookListService(data); logger.Trace("Добавление книг начато"); dataService.AddBook(a); dataService.AddBook(b); dataService.AddBook(c); dataService.AddBook(d); logger.Trace("Добавление книг завершено"); logger.Trace("Удаляется книга"); dataService.RemoveBook(a); Show(data.Load()); dataService.SortBooksByTag(BookListService.Tags.Year); Show(data.Load()); Show(dataService.FindByTag(BookListService.Tags.Year, 1985)); } catch (ArgumentException e) { logger.Error(e.ToString()); } }
public void DeleteBook(Book request) { using (var db = DbConnectionFactory.OpenDbConnection()) { db.Delete(request); } }
static void Main(string[] args) { List<Book> library = new List<Book> { new Book("Михаил Булгаков", "Мастер и Маргарита", 462, "Эксмо", 2006), new Book("Фёдор Достоевский", "Преступление и наказание", 630, "АСТ, Неоклассик", 2006), new Book("Михаил Лермонтов", "Герой нашего времени", 189, "АСТ, Неоклассик", 2008), new Book("Лев Толстой", "Анна Каренина", 706, "Издательский Дом Ридерз Дайджест", 2006), }; BookListService service = new BookListService(library); DisplayBook(service.ListBooks); Book bookToAdd = new Book("Александр Пушкин", "Евгений Онегин", 203, "Питер", 2012); service.AddBook(bookToAdd); DisplayBook(service.ListBooks); service.RemoveBook(library[2]); DisplayBook(service.ListBooks); ComparerByNumberOfPages compareNumberOfPages = new ComparerByNumberOfPages(); ComparerByPublisher comparePublisher = new ComparerByPublisher(); ComparerByTitle comaperTitle = new ComparerByTitle(); ComparerByYearIssued comaperYearIssued = new ComparerByYearIssued(); service.SortsBooksByTag(comaperTitle); DisplayBook(service.ListBooks); IEnumerable<Book> resultBook = service.FindByTag(book => book.YearIssued == 2006); foreach (var item in resultBook) Console.WriteLine(item); Console.ReadKey(); }
public void AddBook(Book book) { books = storageAdapter.Load(); if (books.Contains(book)) throw new ArgumentException("The book which to be added is already exist"); books.Add(book); Commit(); }
public void RemoveBook(Book book) { books = storageAdapter.Load(); if (!books.Contains(book)) throw new ArgumentException("The book which to be removed is not finded"); books.Remove(book); Commit(); }
public void TestCompareTo() { Book a = new Book("Anna Korenina", "Tolstoy", 1785, "russian"); Book b = new Book("Idiot", "Dostoevsky", 1755, "russian"); Book c = new Book("Anna Korenina", "Tolstoy", 1785, "russian"); Assert.AreEqual(0, a.CompareTo(c)); Assert.AreEqual(-1, a.CompareTo(b)); }
public void RemoveBook(Book book) { if (book == null) return; if (!ListBooks.Contains(book)) throw new RemoveBookException("Book to be deleted was not found"); ListBooks.Remove(book); }
public void AddBook(Book book) { if (book == null) return; if (ListBooks.Contains(book)) throw new AddBookException("This book already exists in the list"); ListBooks.Add(book); }
public void AddBook(Book book) { if (book == null) return; if (listBooks.Contains(book)) throw new Exception("This book already exists in the list"); listBooks.Add(book); WriteBookInFile(listBooks[listBooks.Count - 1]); }
public void RemoveBook(Book book) { if (book == null) return; if (!listBooks.Contains(book)) throw new Exception("Book to be deleted was not found"); listBooks.Remove(book); File.Delete(path); WriteListBooksInFile(listBooks); }
public object Post(BookInformation submission) { var book = new Book() { Id = submission.Id, Title = submission.Title, Author = submission.Author, Price = submission.Price }; int id = Repo.AddBook(book); return new {Id = id}; }
public object Post(BookInformation request) { var book = new Book() { Id = request.Id, Author = request.Author, Title = request.Title, Price = request.Price }; int id = Repo.AddBook(book); return new {Id = id}; }
public int AddBook(Book request) { using (var db = DbConnectionFactory.OpenDbConnection()) { db.CreateTable<Book>(); if (request.Id == 0) { db.Insert(request); } else { db.Update(request); } return (int)db.LastInsertId(); } }
public int AddBook(Book request) { using (var db = DbConnectionFactory.OpenDbConnection()) { db.CreateTable<Book>(); if (request.Id == 0) { return (int)db.Insert(request, selectIdentity: true); } else { db.Update(request); return request.Id; } } }
public static void Main(string[] args) { SaveAndLoadFile sl = new SaveAndLoadFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "test.txt")); BookListService service = new BookListService(sl); Book existingBook = new Book("Блок Александр", "Ее песни", 116, "Минск-Пресс", 2014); Book bookForRemove = new Book("Салтыков-Щедрин Михаил", "Дикий помещик", 365, "Добрая книга", 2003); try { serviceBookLogger.Info("Start of block processing TYR in which adding books"); service.AddBook(existingBook); serviceBookLogger.Info("End of block processing TYR in which adding books"); } catch (AddBookException ex) { Console.WriteLine(ex.Message); serviceBookLogger.Info(ex.Message); serviceBookLogger.Error(ex.StackTrace); } try { serviceBookLogger.Info("Start of block processing TYR in which remove book"); service.RemoveBook(bookForRemove); serviceBookLogger.Info("End of block processing TYR in which remove book"); } catch (RemoveBookException ex) { Console.WriteLine(ex.Message); serviceBookLogger.Info(ex.Message); serviceBookLogger.Error(ex.StackTrace); } service.SortsBooksByTag(book => book.Title); serviceBookLogger.Info("Sorting internal list books by Title"); DisplayBook(service.ListBooks); List<Book> resultFind = service.FindByTag(book => book.NumberOfPages == 189); serviceBookLogger.Info("Find list book where number of page = 189"); DisplayBook(resultFind); Console.ReadKey(); }
public List<Book> Load() { List<Book> books = new List<Book>(); using (FileStream fsRead = new FileStream(path, FileMode.Open, FileAccess.Read)) { using (BinaryReader reader = new BinaryReader(fsRead)) { while (reader.PeekChar() != -1) { Book book = new Book ( reader.ReadString(), reader.ReadString(), reader.ReadInt32(), reader.ReadString() ); books.Add(book); } } } return books; }
private void WriteBookInFile(Book bookForWrite) { if (bookForWrite == null) throw new ArgumentNullException("Book for write is null"); using (FileStream fs = new FileStream(path, FileMode.Append, FileAccess.Write)) using (BinaryWriter writer = new BinaryWriter(fs)) { writer.Write(bookForWrite.Author); writer.Write(bookForWrite.Title); writer.Write(bookForWrite.NumberOfPages); writer.Write(bookForWrite.Publisher); writer.Write(bookForWrite.YearIssued); } }
private bool FindByLanguadge(Book book, string languadge) { return book.Languadge == languadge; }
private bool FindByYear(Book book, string year) { return book.Year == Int32.Parse(year); }
private bool FindByAuthor(Book book, string author) { return book.Author == author; }
private bool FindByTitle(Book book, string title) { return book.Title == title; }