Example #1
0
        //
        public static Patron Find(int id)
        {
            SqlConnection conn = DB.Connection();
              conn.Open();

              SqlCommand cmd = new SqlCommand("SELECT * FROM patrons WHERE id = @PatronId;", conn);
              SqlParameter patronIdParameter = new SqlParameter();
              patronIdParameter.ParameterName = "@PatronId";
              patronIdParameter.Value = id.ToString();

              cmd.Parameters.Add(patronIdParameter);

              SqlDataReader rdr = cmd.ExecuteReader();

              int foundPatronId = 0;
              string foundPatronName = null;

              while (rdr.Read())
              {
            foundPatronId = rdr.GetInt32(0);
            foundPatronName = rdr.GetString(1);
              }
              Patron foundPatron = new Patron(foundPatronName, foundPatronId);

              if (rdr != null)
              {
            rdr.Close();
              }
              if (conn != null)
              {
            conn.Close();
              }
              return foundPatron;
        }
Example #2
0
        public void T2_Equal_ReturnsTrueIfPatronIsSame()
        {
            Patron firstPatron = new Patron("Judy");
              Patron secondPatron = new Patron("Judy");

              Assert.Equal(firstPatron, secondPatron);
        }
        public void Test_Equal_EntriesMatch()
        {
            Patron testPatron1 = new Patron ("Jane", "Doe", "555-555-5555");
              Patron testPatron2 = new Patron ("Jane", "Doe", "555-555-5555");

              Assert.Equal(testPatron1, testPatron2);
        }
Example #4
0
        public void T5_Find_FindsPatronInDatabase()
        {
            Patron testPatron = new Patron("Judy");
              testPatron.Save();

              Patron foundPatron = Patron.Find(testPatron.GetId());

              Assert.Equal(testPatron, foundPatron);
        }
        public void Test_Find_FindPatronInDatabase()
        {
            Patron testPatron1 = new Patron ("Jane", "Doe", "555-555-5555");
              testPatron1.Save();

              Patron result = Patron.Find(testPatron1.GetId());

              Assert.Equal(testPatron1, result);
        }
Example #6
0
        public void T3_Save_SavesToDB()
        {
            Patron testPatron = new Patron("Judy");
              testPatron.Save();

              List<Patron> result = Patron.GetAll();
              List<Patron> testList = new List<Patron>{testPatron};

              Assert.Equal(testList, result);
        }
Example #7
0
        public void T4_Save_AssignsIdToPatron()
        {
            Patron testPatron = new Patron("Judy");
              testPatron.Save();

              Patron savedPatron = Patron.GetAll()[0];
              int result = savedPatron.GetId();
              int testId = testPatron.GetId();

              Assert.Equal(testId, result);
        }
Example #8
0
        public void Test_Checkout()
        {
            Copy newcopy = new Copy(0, new DateTime(2016,07,20), 1);
              newcopy.Save();

              Patron p = new Patron(0, "Pat", "");
              p.Save();

              p.Checkout(newcopy.id);

              Assert.Equal(p.id, Copy.Find(newcopy.id).patron_id);
        }
        public void Test_AddCopy_AddAnCopyToAPatron()
        {
            Patron testPatron = new Patron ("Jane", "Doe", "555-555-5555");
              testPatron.Save();
              Copy newCopy = new Copy ("New", 1, new DateTime(2016, 7, 25), new DateTime(2016, 8, 25));
              newCopy.Save();
              testPatron.AddCopy(newCopy);

              List<Copy> testCopy = new List<Copy> {newCopy};
              List<Copy> allCopies = testPatron.GetCopies();

              Assert.Equal(testCopy, allCopies);
        }
Example #10
0
        public void Test_Checkin()
        {
            Copy newcopy = new Copy(0, new DateTime(2016,06,27), 1);
              newcopy.Save();

              Patron p = new Patron(0, "Pat", "");
              p.Save();

              p.Checkout(newcopy.id);
              newcopy.Update(new List<string> {"due_date"}, new List<object> {new DateTime(2016,07,19)});
              Copy.Find(newcopy.id).Checkin();

              Assert.Equal(10, Patron.Find(p.id).balance);
        }
        public void Test_DeleteOne_DeletesOnePatron()
        {
            Patron newPatron1 = new Patron ("Jane", "Doe", "555-555-5555");
              Patron newPatron2 = new Patron ("John", "Watson", "444-444-4444");
              newPatron1.Save();
              newPatron2.Save();
              List<Patron> newList = Patron.GetAll();

              newPatron1.DeleteOne();

              List<Patron> resultList = Patron.GetAll();
              List<Patron> testList = new List<Patron> {newPatron2};

              Assert.Equal(testList, resultList);
        }
Example #12
0
        public void T1_Checkout_CreatesACheckoutRecord()
        {
            Patron testPatron = new Patron("Judy");
              testPatron.Save();

              Copy testCopy = new Copy(5);
              testCopy.Save();

              DateTime checkoutDate = new DateTime(2016,08,04);
              DateTime dueDate = new DateTime(2017,01,02);

              Checkout newCheckout = new Checkout(testCopy.GetId(), testPatron.GetId(), checkoutDate, dueDate);
              newCheckout.Save();

              List<Checkout> result = Checkout.GetAll();

              Assert.Equal(newCheckout, result[0]);
        }
Example #13
0
        public static Patron Find(int searchId)
        {
            Patron foundPatron = new Patron ("", "", ""); //Program needs some value inside a Patron object
              SqlConnection conn = DB.Connection();
              conn.Open();
              SqlDataReader rdr = null;

              SqlCommand cmd = new SqlCommand ("SELECT * FROM patrons WHERE id = @PatronId;", conn);

              SqlParameter idParameter = new SqlParameter();
              idParameter.ParameterName = "@PatronId";
              idParameter.Value = searchId;

              cmd.Parameters.Add(idParameter);

              rdr = cmd.ExecuteReader();

              while (rdr.Read())
              {
            int patronId = rdr.GetInt32(0);
            string patronFirstName = rdr.GetString(1);
            string patronLastName = rdr.GetString(2);
            string patronPhoneNumber = rdr.GetString(3);
            Patron newPatron = new Patron(patronFirstName, patronLastName, patronPhoneNumber, patronId);

            foundPatron = newPatron;
              }
              if (rdr != null)
              {
            rdr.Close();
              }
              if (conn != null)
              {
            conn.Close();
              }
              return foundPatron;
        }
        public void Test_Save_SavesPatronsToDatabase()
        {
            Patron newPatron1 = new Patron ("Jane", "Doe", "555-555-5555");
              Patron newPatron2 = new Patron ("John", "Watson", "444-444-4444");
              newPatron1.Save();
              newPatron2.Save();

              int resultCount = Patron.GetAll().Count;

              Assert.Equal(2, resultCount);
        }
Example #15
0
        public void Test_GetHistory()
        {
            Copy newcopy = new Copy(0, new DateTime(2016,07,20), 1);
              newcopy.Save();

              Patron p = new Patron(0, "Pat", "");
              p.Save();

              p.Checkout(newcopy.id);

              Assert.Equal(1, p.GetHistory().Count);
        }
Example #16
0
        public void Test_overDueBooks()
        {
            Patron p = new Patron(0, "Pat", "");
              p.Save();

              Copy newcopy = new Copy(0, new DateTime(2016,06,27), 1);
              newcopy.Save();

              p.Checkout(newcopy.id);

              newcopy.Update(new List<string> {"due_date"}, new List<object> {new DateTime(2016,07,19)});

              List<Copy> isoverdue = Copy.OverdueBooks();

              Assert.Equal(1, isoverdue.Count);
        }
Example #17
0
        public void Test_GetItemsOut()
        {
            Patron p = new Patron(0, "Pat", "");
              p.Save();

              Copy newcopy = new Copy(0, new DateTime(2016,07,20), p.id);
              newcopy.Save();

              Assert.Equal(newcopy.id, p.GetItemsOut()[0].id);
        }
Example #18
0
 public List<MediaItem> GetCheckedOutMedia(Patron p = null)
 {
     return OurMediaItem.getCheckedOutItems(conn, p);
 }
Example #19
0
        public void T8_Addpatron_AddspatronToCopy()
        {
            Book newBook = new Book("Freedom");
              newBook.Save();

              Patron testPatron = new Patron("Sarah");
              testPatron.Save();

              Copy testCopy = new Copy(1);
              testCopy.Save();

              testCopy.AddPatron(testPatron);
              List<Patron> result = testCopy.GetPatron();
              List<Patron> testList = new List<Patron> {testPatron};

              Assert.Equal(testList, result);
        }
Example #20
0
        public HomeModule()
        {
            Get["/"] =_=>{
            return View["index.cshtml"];
              };

              Get["/references"] =_=>{
            List<Book> search = new List<Book> {};
            return View["references.cshtml",search];
              };

              Get["/patrons"]=_=>{
            List<Book> search = new List<Book> {};
            return View["patrons.cshtml",search];
              };

              Get["/books/{id}"] =parameters=> {
            Book b = Book.Find(parameters.id);
            return View["book.cshtml", b];
              };
              Get["/patronview/books/{id}"] =parameters=> {
            Book b = Book.Find(parameters.id);
            return View["patronview-book.cshtml", b];
              };
              Get["/copies/{id}"] =parameters=> {
            Copy c = Copy.Find(parameters.id);
            return View["copy.cshtml", c];
              };
              Get["/patronview/copies/{id}"] =parameters=> {
            Copy c = Copy.Find(parameters.id);
            return View["patronview-copy.cshtml", c];
              };
              Delete["/copies/delete/{id}"] =parameters=> {
            Copy c = Copy.Find(parameters.id);
            c.Delete(new string[] {"checkouts"}, new string[] {"copy_id"});
            return View["book.cshtml", Book.Find(c.book_id)];
              };
              Patch["/books/edit/{id}"] =parameters=> {
            Book b = Book.Find(parameters.id);
            b.Update(new List<string> {"call_number", "collection", "title"}, new List<object> {(string)Request.Form["callNumber"], (string)Request.Form["collection"], (string)Request.Form["title"]});
            b.RemoveAuthors();
            for(int i = 0; i<Request.Form["number-of-authors"]; i++)
            {
              Author a = Author.FindByName(Request.Form["author" + i]);
              if(a==null)
              {
            a = new Author(Request.Form["author" + i]);
            a.Save();
              }
              b.AddAuthor(a.id);
            }
            return View["book.cshtml", b];
              };
              Get["/circulation"] =_=>{
            return View["circulation.cshtml"];
              };
              Post["/patron/new"] =_=> {
            Patron p = new Patron(0, (string)Request.Form["name"], "");
            p.Save();
            return View["patron.cshtml", p];
              };
              Post["/check-out/{id}"] =parameters=> {
            Patron p = Patron.Find(parameters.id);
            Copy c = Copy.Find((int)Request.Form["itemId"]);
            if(c!=null)
            {
              p.Checkout(c.id);
            }
            return View["patron.cshtml", p];
              };
              Get["/check-in"] =_=> {
            return View["check-in.cshtml"];
              };
              Post["/check-in/new"] =_=> {
            int copyId = (int)Request.Form["id"];
            Copy c = Copy.Find(copyId);
            if(c!=null)
            {
              c.Checkin();
            }
            return View["check-in.cshtml"];
              };
              Get["/check-out"] =_=> {
            return View["check-out.cshtml", ""];
              };
              Post["/patron"] =_=> {
            Patron p = Patron.Find((int)Request.Form["patronId"]);
            if(p==null)
            {
              return View["check-out.cshtml", "No Patron Found"];
            }
            else
            {
              return View["patron.cshtml", p];
            }
              };

              Post["/patronview"] =_=> {
            Patron p = Patron.Find((int)Request.Form["patronId"]);
            if(p==null)
            {
              return View["check-out.cshtml", "No Patron Found"];
            }
            else
            {
              return View["patronview.cshtml", p];
            }
              };

              Get["/catalog"] =_=>{
            return View["catalog.cshtml"];
              };
              Post["books/new"] =_=> {
            Book newBook = new Book(Request.Form["callNumber"], Request.Form["collection"], Request.Form["title"]);
            newBook.Save();
            Copy newCopy = new Copy(newBook.id, new DateTime(1900,1,1), 0);
            newCopy.Save();
            for(int i = 0; i<Request.Form["number-of-authors"]; i++)
            {
              Author a = Author.FindByName(Request.Form["author" + i]);
              if(a==null)
              {
            a = new Author(Request.Form["author" + i]);
            a.Save();
              }
              newBook.AddAuthor(a.id);
            }
            return View["book.cshtml", newBook];
              };
              Post["copies/new"] =_=> {
            int bookId = (int)Request.Form["book_id"];
            Copy newCopy = new Copy(bookId, new DateTime(1900,1,1), 0);
            newCopy.Save();
            return View["copy.cshtml", newCopy];
              };

              Post["/search"] =_=> {
            string search = Request.Form["search"];
            string searchType = Request.Form["searchdef"];

            List<Book> booksearch = Book.Search(search,searchType);

            return View["references.cshtml",booksearch];
              };
              Post["/patronview/search"] =_=> {
            string search = Request.Form["search"];
            string searchType = Request.Form["searchdef"];

            List<Book> booksearch = Book.Search(search,searchType);

            return View["patrons.cshtml",booksearch];
              };
              Get["/patron/edit/{id}"]=parameters=>{
            Patron findpatron = Patron.Find(parameters.id);

            return View["updatepatron.cshtml", findpatron];
              };

              Patch["/patron/edit/{id}"]=parameters=>{
            Patron findpatron = Patron.Find(parameters.id);

            findpatron.Update(new List<string>{"name", "notes"}, new List<object>{(string)Request.Form["patronname"], (string)Request.Form["notes"]});

            return View["patron.cshtml", findpatron];
              };
              Patch["/patron/payfines/{id}"]=parameters=> {
            Patron p = Patron.Find(parameters.id);
            p.PayFines(Request.Form["amount"]);
            return View["patron.cshtml", p];
              };

              Get["/overdue"]=_=>
              {
            List<Copy> overDueBooks = Copy.OverdueBooks();
            return View["overdue.cshtml",overDueBooks];
              };

              Get["/patron/{id}"] = parameters => {
            Patron p = Patron.Find(parameters.id);
            return View["patron.cshtml", p];
              };
        }
Example #21
0
        public void AddPatron(Patron newPatron)
        {
            SqlConnection conn = DB.Connection();
              conn.Open();

              SqlCommand cmd = new SqlCommand("INSERT INTO checkouts (patron_id, copy_id) VALUES (@PatronId, @CopyId);", conn);

              SqlParameter patronIdParameter = new SqlParameter();
              patronIdParameter.ParameterName = "@PatronId";
              patronIdParameter.Value = newPatron.GetId();
              cmd.Parameters.Add(patronIdParameter);

              SqlParameter copyIdParameter = new SqlParameter();
              copyIdParameter.ParameterName = "@CopyId";
              copyIdParameter.Value = this.GetId();
              cmd.Parameters.Add(copyIdParameter);

              cmd.ExecuteNonQuery();

              if (conn != null)
              {
            conn.Close();
              }
        }
Example #22
0
        public List<Patron> GetPatron()
        {
            SqlConnection conn = DB.Connection();
              conn.Open();

              SqlCommand cmd = new SqlCommand("SELECT patrons.* FROM patrons JOIN checkouts ON (patrons.id = checkouts.patron_id) JOIN copies ON (checkouts.copy_id = copies.id) WHERE copies.id = @CopyId",conn);

              SqlParameter copyIdParameter = new SqlParameter();
              copyIdParameter.ParameterName= "@CopyId";
              copyIdParameter.Value=this.GetId();
              cmd.Parameters.Add(copyIdParameter);

              SqlDataReader rdr = cmd.ExecuteReader();
              List<Patron> patrons = new List<Patron> {};

              while(rdr.Read())
              {
            int patronId = rdr.GetInt32(0);
            string patronName = rdr.GetString(1);
            Patron newPatron = new Patron(patronName, patronId);
            patrons.Add(newPatron);
              }

              if(rdr !=null)
              {
            rdr.Close();
              }

              if (conn != null)
              {
            conn.Close();
              }
              return patrons;
        }
Example #23
0
 public void save(Patron item)
 {
     (item as OurPatron).save(conn);
 }
        public void Test_Update_UpdatePatronInDatabase()
        {
            Patron newPatron = new Patron ("Jane", "Doe", "555-555-5555");
              newPatron.Save();
              newPatron.SetPhoneNumber ("111-111-1111");
              newPatron.Update();

              Patron updatedPatron = Patron.Find(newPatron.GetId());

              Assert.Equal(newPatron.GetPhoneNumber(), updatedPatron.GetPhoneNumber());
        }
Example #25
0
        public void T9_GetPatrons_ReturnsAllCopyPatrons()
        {
            Patron testPatron1 = new Patron("Sarah");
              testPatron1.Save();
              Patron testPatron2 = new Patron("John");
              testPatron2.Save();

              Copy testCopy = new Copy(5);
              testCopy.Save();

              testCopy.AddPatron(testPatron1);
              List<Patron> result = testCopy.GetPatron();
              List<Patron> testList= new List<Patron>{testPatron1};

              Assert.Equal(testList,result);
        }
Example #26
0
        /// <summary>
        /// Purpose: helper for btnDisplayCheckedPerPatron
        /// </summary>
        /// <param name="P">Patron</param>
        private void displayChecked(Patron P)
        {
            String str = P._name + " has ";

            if (P._currentChecked.Count > 0)
            {
                str += "checked out:\n\n";
                foreach (KeyValuePair<uint, Media> m in P._currentChecked)
                {
                    str += "\t" + m.Value.Title + "\n";
                }
            }
            else
            {
                str += "nothing checked out.";
            }

            MessageBox.Show(str);
        }
Example #27
0
        /// <summary>
        /// Checks the book out, assigns borrower
        /// </summary>
        /// <param name="borrower">Patron borrowing the media</param>
        public bool CheckOut(Patron borrower, DateTime dateChecked)
        {
            //call checkout from patron, which needs to check age for eligibility
            //has patron already checked maximum number of items?
            //is book already checked out?

            if (CheckedOut == false && borrower._currentChecked.Count <= borrower._maxCheckouts)
            {
                CheckedOut = true;
                borrower.addMedia(this, this.ID);
                dateCheckedOut = dateChecked;
                Borrower = borrower;
                return true;
            }
            else
            {
                return false;
            }
        }
Example #28
0
        /// <summary>
        /// Fills the list box with the items the patron currently has checked out
        /// </summary>
        /// <param name="patron"></param>
        private void UpdatePatronItemsCheckedOut(Patron patron)
        {
            txtPatronItemsCheckedOut.Items.Clear();

            foreach (KeyValuePair<uint, Media> m in patron._currentChecked)
            {
                Media media = m.Value;
                txtPatronItemsCheckedOut.Items.Add(media);
                txtPatronItemsCheckedOut.DisplayMember = "Title";
            }

            if (txtPatronItemsCheckedOut.Items.Count > 0)
            {
                txtPatronItemsCheckedOut.SelectedIndex = 0;
            }

            CheckCheckInButton();
        }
Example #29
0
 internal static List<MediaItem> getCheckedOutItems(SqliteConnection conn, Patron p = null)
 {
     if (p != null)
         return getItems(conn, "where checked_to_patron_id = " + (p as OurPatron).id.ToString());
     else
         return getItems(conn, "where checked_to_patron_id is not null");
 }
        public void Test_GetAll_RetrieveAllPatrons()
        {
            Patron testPatron1 = new Patron ("Jane", "Doe", "555-555-5555");
              Patron testPatron2 = new Patron ("John", "Watson", "444-444-4444");
              testPatron1.Save();
              testPatron2.Save();

              List<Patron> testList = new List<Patron> {testPatron1, testPatron2};
              List<Patron> result = Patron.GetAll();

              Assert.Equal(testList, result);
        }
Example #31
0
        public HomeModule()
        {
            Get["/"] = _ => {
                // List<Stylist> AllLists = Stylist.GetAll();
                return(View["index.cshtml"]);
            };
            Get["/books"] = _ => {
                var AllBooks = Book.GetAll();
                return(View["books.cshtml", AllBooks]);
            };
            Get["/patrons"] = _ => {
                List <Patron> allPatrons = Patron.GetAll();
                return(View ["patrons.cshtml", allPatrons]);
            };
            Get["/books/new"] = _ => {
                return(View["books_form.cshtml"]);
            };
            Post["/books/new"] = _ => {
                Book newBook = new Book(Request.Form["title"]);
                newBook.Save();
                Copy newCopy = new Copy(newBook.GetId(), Request.Form["number-of"], DateTime.Today);
                newCopy.Save();
                Author newAuthor = new Author(Request.Form["author"]);
                newAuthor.Save();
                newBook.AddAuthor(newAuthor);
                List <Author> allAuthors = Author.GetAll();
                List <Copy>   allCopies  = Copy.GetAll();
                List <Book>   allBooks   = Book.GetAll();
                return(View["success.cshtml"]);
            };
            Get["/books/search"] = _ => {
                return(View["books_search.cshtml"]);
            };
            Get["/books/found"] = _ => {
                List <Author> selectAuthors = new List <Author> {
                };
                List <Book> foundBooks      = new List <Book> {
                };
                string        authorName    = Request.Form["name"];
                List <Author> allAuthors    = Author.GetAll();
                foreach (Author listAuthor in allAuthors)
                {
                    if (listAuthor.GetName() == authorName)
                    {
                        selectAuthors.Add(listAuthor);
                    }
                }
                foreach (Author newAuthor in selectAuthors)
                {
                    foundBooks = newAuthor.GetBooks();
                }
                return(View["/books_found.cshtml", foundBooks]);
            };
            Get["/patrons/new"] = _ => {
                List <Patron> AllPatrons = Patron.GetAll();
                return(View["patrons_form.cshtml", AllPatrons]);
            };

            Post["/patrons/new"] = _ => {
                Patron newPatron = new Patron(Request.Form["name"]);
                newPatron.Save();
                return(View["success.cshtml"]);
            };

            Get["/books/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                var           selectedBook        = Book.Find(parameters.id);
                List <Author> author = selectedBook.GetAuthors();
                selectedBook.AddAuthor(author[0]);
                var copies = selectedBook.GetCopies();
                model.Add("book", selectedBook);
                model.Add("author", author);
                model.Add("copies", copies);
                return(View["book.cshtml", model]);
            };

            Get["/patron/{id}"] = parameters => {
                Patron        selectedPatron = Patron.Find(parameters.id);
                List <object> model          = new List <object> {
                };
                List <Book> bookList         = Book.GetAll();
                model.Add(selectedPatron);
                model.Add(bookList);
                return(View["patron.cshtml", model]);
            };
            Get["patron/checkout/{id}"] = parameters => {
                List <Book> bookList  = new List <Book> {
                };
                Patron selectedPatron = Patron.Find(parameters.id);
                Book   newBook        = Book.Find(int.Parse(Request.Form("book")));
                Console.WriteLine(newBook);
                bookList.Add(newBook);
                return(View["patron_checkout.cshtml", bookList]);
            };
            // Patch["patron/checkout/{id}"] = parameters => {
            //   Patron selectedPatron = Patron.Find(parameters.id);
            //   Book newBook = Book.Find(Request.Form("book"));
            //   return View["success.cshtml"];
            // };

            Get["/book/edit/{id}"] = parameters => {
                Book selectedBook = Book.Find(parameters.id);
                return(View["book_edit.cshtml", selectedBook]);
            };
            Patch["/book/edit/{id}"] = parameters => {
                Book selectedBook = Book.Find(parameters.id);
                selectedBook.Update(Request.Form["book-title"]);
                return(View["success.cshtml"]);
            };
            Get["/patron/edit/{id}"] = parameters => {
                Patron selectedPatron = Patron.Find(parameters.id);
                return(View["patron_edit.cshtml", selectedPatron]);
            };
            Patch["/patron/edit/{id}"] = parameters => {
                Patron selectedPatron = Patron.Find(parameters.id);
                selectedPatron.Update(Request.Form["name"]);
                return(View["success.cshtml"]);
            };
            Get["/book/delete/{id}"] = parameters => {
                Book selectedBook = Book.Find(parameters.id);
                return(View["/book_delete.cshtml", selectedBook]);
            };
            Delete["book/delete/{id}"] = parameters => {
                Book selectedBook = Book.Find(parameters.id);
                selectedBook.Delete();
                return(View["success.cshtml"]);
            };
            Get["/patron/delete/{id}"] = parameters => {
                Patron selectedPatron = Patron.Find(parameters.id);
                return(View["/patron_delete.cshtml", selectedPatron]);
            };
            Delete["/patron/delete/{id}"] = parameters => {
                Patron selectedPatron = Patron.Find(parameters.id);
                selectedPatron.Delete();
                return(View["success.cshtml"]);
            };
        }