Пример #1
0
 //CRUD Operations
 //1. CREAT
 public Book AddNewBook(Book newBook)
 {
     if (newBook == null)
               throw new ArgumentNullException("newBook");
      newBook.BookId = counter++;
      books.Add(newBook);
      return newBook;
 }
 public string UpdateBook(Book book, string id)
 {
     bool updated = repository.UpdateABook(book);
       if (updated)
             return "Book with id = " + id + " updated successfully";
      else
            return "Unable to update book with id = " + id;
 }
Пример #3
0
        //4. UPDATE
        public bool UpdateABook(Book updatedBook)
        {
            if (updatedBook == null)
                    throw new ArgumentNullException("updatedBook");

               int idx = books.FindIndex(b => b.BookId == updatedBook.BookId);
               if (idx == -1)
                    return false;

                books.RemoveAt(idx);
                books.Add(updatedBook);
                return true;
        }
 public string AddBook(Book book, string id)
 {
     Book newBook = repository.AddNewBook(book);
       return "id=" + newBook.BookId;
 }