Ejemplo n.º 1
0
        public void Create_User_And_Save()
        {
            Library library = new Library();
            User user = new User("Johny", "John", "Smith");
            library.AddUser(user);
            IList<User> users = library.GetUsers();
            Assert.AreEqual(1, users.Count, "Did not get a new user into the Library");

        }
Ejemplo n.º 2
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) );
        }
Ejemplo n.º 3
0
 public IList<User> GetUsers()
 {
     return With.Transaction<IList<User>>(delegate(SqlCommand command)
         {
             IList<User> users = new List<User>();
             command.CommandType = CommandType.Text;
             command.CommandText = "SELECT Username, Firstname, Lastname,Id FROM Users";
             using (SqlDataReader sdr = command.ExecuteReader())
             {
                 while (sdr.Read())
                 {
                     User user = new User();
                     user.Username = sdr.GetString(0);
                     user.Firstname = sdr.GetString(1);
                     user.Lastname = sdr.GetString(2);
                     user.ID = sdr.GetInt32(3);
                     users.Add(user);
                 }
             }
             return users;
         });
 }
Ejemplo n.º 4
0
 public void Create(User user)
 {
     try
     {
         With.Transaction(delegate(SqlCommand command)
         {
             command.CommandType = System.Data.CommandType.StoredProcedure;
             command.CommandText = InsertUserSp;
             command.Parameters.AddWithValue("username", user.Username);
             command.Parameters.AddWithValue("firstname", user.Firstname);
             command.Parameters.AddWithValue("lastname", user.Lastname);
             user.ID = Convert.ToInt32(command.ExecuteScalar());
         });
     }
     catch (SqlException e)
     {
         switch (e.Number)
         {
             case 2627:
                 throw new DuplicateNameException("Username '" + user.Username + "' already exists", e);
         }
         throw;
     }
 }
Ejemplo n.º 5
0
 public ICollection<Book> GetBooksCheckedOutBy(User user)
 {
     return booksRepository.GetBooksCheckedOutBy(user);
 }
Ejemplo n.º 6
0
        //*** Users ***//

        public void AddUser(User user)
        {
            usersRepository.Create(user);
            users.Add(user);
        }
Ejemplo n.º 7
0
 public ICollection<Book> GetBooksCheckedOutBy(User user)
 {
     return With.Transaction<ICollection<Book>>(delegate(SqlCommand command)
     {
         command.CommandType = System.Data.CommandType.StoredProcedure;
         command.CommandText = "BookGetAllCheckedOutByUser";
         command.Parameters.AddWithValue("userid", user.ID);
         return GetBooksListFromCommand(command);
     });
 }
Ejemplo n.º 8
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();
     });
 }
Ejemplo 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);
        }