Esempio n. 1
0
 public int GetCopies(Book book)
 {
     return With.Transaction<int>(delegate(SqlCommand command)
       {
           command.CommandType = System.Data.CommandType.Text;
           command.CommandText = "SELECT COUNT(*) FROM BookCopy WHERE ISBN = @ISBN";
           command.Parameters.AddWithValue("isbn", book.ISBN);
           return (int)command.ExecuteScalar();
       });
 }
Esempio n. 2
0
 public void Create(Book book)
 {
     With.Transaction(delegate(SqlCommand command)
     {
         command.CommandType = System.Data.CommandType.StoredProcedure;
         command.CommandText = InsertBookSp;
         command.Parameters.AddWithValue("isbn", book.ISBN);
         command.Parameters.AddWithValue("name", book.Name);
         command.ExecuteNonQuery();
     });
 }
Esempio n. 3
0
        public void CheckOutCopyOf(Book book1, User user)
        {
            // remember transactions!
            // find if book has free copies
            //  if not, throw NoFreeBookException
            // find copy id #
            // add new row to the checkouts table, with the proper data


            //booksRepository.CheckOut(book1, user, TimeSpan.FromDays(14) );
        }
Esempio n. 4
0
 private IList<Book> GetBooksListFromCommand(SqlCommand command)
 {
     IList<Book> mybooklist = new List<Book>();
     using (SqlDataReader mydr = command.ExecuteReader())
     {
         while (mydr.Read())
         {
             Book mybook = new Book(mydr.GetString(0), mydr.GetString(1));
             mybooklist.Add(mybook);
         }
     }
     return mybooklist;
 }
Esempio n. 5
0
        public void Get_Book_List()
        {
            Library library = CreateTestLibrary();
            Book book1 = new Book("1-1231-13", "War & Peace vol 1");
            Book book2 = new Book("1-1231-14", "War & Peace vol 2");
            Book book3 = new Book("1-1231-15", "War & Peace vol 3");

            library.AddBook(book1);
            library.AddBook(book2);
            library.AddBook(book3);

            IList<Book> bl = library.GetBookList();


            Assert.AreEqual("War & Peace vol 2", bl[1].Name);
        }
Esempio n. 6
0
        public IList<BookCopy> GetBookCopies(Book mybook)
        {
            return With.Transaction<IList<BookCopy>>(delegate(SqlCommand command)
             {
                 IList<BookCopy> mybookcopylist = new List<BookCopy>();

                 command.CommandType = System.Data.CommandType.Text;
                 command.CommandText = "SELECT Id, ISBN FROM BookCopy where isbn=@isbn";
                 command.Parameters.AddWithValue("isbn", mybook.ISBN);
                 using (SqlDataReader mydr = command.ExecuteReader())
                 {
                     while (mydr.Read())
                     {
                         BookCopy mybookcopy = new BookCopy(mydr.GetString(1));
                         mybookcopy.Id = mydr.GetInt32(0);
                         mybookcopylist.Add(mybookcopy);
                     }
                 }
                 return mybookcopylist;
             });
        }
 public void Create(Book entity)
 {
     _db.Books.Add(entity);
     _db.SaveChanges();
 }
Esempio n. 8
0
 public IList<BookCopy> GetBookCopies(Book book1)
 {
     return booksRepository.GetBookCopies(book1);
 }
Esempio n. 9
0
        public void Can_Check_A_Book_From_Library()
        {
            Library library = CreateTestLibrary();
            Book book1 = new Book("1-1231-13", "War & Peace vol 1");
            library.AddBook(book1);

            User user = new User("read-alot", "read", "a lot");
            library.AddUser(user);


            ICollection<Book> books = library.GetBooksCheckedOutBy(user);
            Assert.AreEqual(0, books.Count);

            library.CheckOutCopyOf(book1, user);

            books = library.GetBooksCheckedOutBy(user);
            Assert.AreEqual(1, books.Count);
        }
Esempio n. 10
0
 public int GetNumberOfCopies(Book book)
 {
     return booksRepository.GetCopies(book);
 }
Esempio n. 11
0
 public void AddBookCopy(Book book)
 {
     booksRepository.AddBookCopy(book);
 }
Esempio n. 12
0
        public Book GetBookByISBN(String bookisbn)
        {
            return With.Transaction<Book>(delegate(SqlCommand command)
            {
                Book mybook;
                command.CommandType = System.Data.CommandType.Text;
                command.CommandText = "SELECT * FROM Books where isbn=@isbn";
                command.Parameters.AddWithValue("isbn", bookisbn);
                using (SqlDataReader mydr = command.ExecuteReader())
                {
                    if (mydr.HasRows)
                    {
                        mydr.Read();
                        mybook = new Book(mydr.GetString(0), mydr.GetString(1));
                        return mybook;
                    }
                    else
                    {
                        return null;
                    }
                }

            });
        }
Esempio n. 13
0
 public void AddBook(Book book)
 {
     booksRepository.Create(book);
     books.Add(book);
 }
Esempio n. 14
0
        public void Add_Book_And_Five_Copies_With_Single_Transaction()
        {
            With.TotalOpenedTransactionCount = 0;

            With.Transaction(delegate
            {
                Library library = CreateTestLibrary();
                Book book1 = new Book("1-1231-13", "War & Peace vol 1");
                library.AddBook(book1);
                for (int i = 0; i < 4; i++)
                    library.AddBookCopy(book1);

            });

            Assert.AreEqual(1, With.TotalOpenedTransactionCount);
        }
Esempio n. 15
0
 public void Update(Book entity)
 {
     _db.Entry<Book>(entity).State = EntityState.Modified;
     _db.SaveChanges();
 }
Esempio n. 16
0
        public void Get_Book_Copies()
        {
            Library library = CreateTestLibrary();
            Book book1 = new Book("1-1231-13", "War & Peace vol 1");

            library.AddBook(book1);
            library.AddBookCopy(book1);
            library.AddBookCopy(book1);

            IList<BookCopy> bcl = library.GetBookCopies(book1);

            Assert.AreEqual(3, bcl.Count);
        }
Esempio n. 17
0
 public void AddBookCopy(Book book)
 {
     With.Transaction(delegate(SqlCommand command)
     {
         command.CommandType = System.Data.CommandType.Text;
         command.CommandText = "insert into BookCopy (ISBN) values(@ISBN)";
         command.Parameters.AddWithValue("isbn", book.ISBN);
         command.ExecuteNonQuery();
     });
 }
Esempio n. 18
0
 /// <summary>
 /// This is not working!
 /// Left for home
 /// </summary>
 public void CheckOut(Book book, User user, TimeSpan checkOutDuration)
 {
     With.Transaction(IsolationLevel.Serializable, delegate(SqlCommand command)
     {
         command.CommandType = CommandType.StoredProcedure;
         command.CommandText = BookFindAvailableCopy;
         command.Parameters.AddWithValue("isbn", book.ISBN);
         object value = command.ExecuteScalar();
         int copyId = (int)value;
         command.CommandType = CommandType.Text;
         command.CommandText = @"INSERT INTO CheckOuts(BookCopyId, UserId, CheckedOutAt, DueDate) 
             VALUES(@copyId, @userId, @checkOutAt, @dueDate)";
         command.Parameters.AddWithValue("copyId", copyId);
         command.Parameters.AddWithValue("userId", user.ID);
         command.Parameters.AddWithValue("checkOutAt", DateTime.Today);
         command.Parameters.AddWithValue("dueDate", DateTime.Today.Add(checkOutDuration));
         command.ExecuteNonQuery();
     });
 }
Esempio n. 19
0
        public Task<HttpResponseMessage> Put(Book book)
        {
            HttpResponseMessage response = new HttpResponseMessage();

            try
            {
                _repository.Update(book);
                response = Request.CreateResponse(HttpStatusCode.OK, book);
            }
            catch (Exception)
            {
                response = Request.CreateResponse(HttpStatusCode.BadRequest, "Falha ao recuperar livros");
                throw;
            }

            var tsc = new TaskCompletionSource<HttpResponseMessage>();
            tsc.SetResult(response);
            return tsc.Task;
        }
Esempio n. 20
0
        public void Get_Book_By_ID()
        {
            Library library = CreateTestLibrary();
            Book book1 = new Book("1-1231-13", "War & Peace vol 1");
            Book book2;
            library.AddBook(book1);

            book2 = library.GetBookByISBN("1-1231-13");
            Assert.AreEqual(book1.Name, book2.Name);
        }