Ejemplo n.º 1
0
        public void GetDueDate_Patron_allDatesAndBookTitles()
        {
            Patron newPatron = new Patron("Britton");

            newPatron.Save();

            Book newBook1 = new Book("the book");

            newBook1.Save();
            Book newBook2 = new Book("the book2");

            newBook2.Save();

            Copy newCopy1 = new Copy(newBook1.GetId(), 15);

            newCopy1.Save();
            Copy newCopy2 = new Copy(newBook2.GetId(), 15);

            newCopy2.Save();

            newPatron.AddCopy(newCopy1);
            newPatron.AddCopy(newCopy2);

            List <string> expected = new List <string> {
                "the book", "2017-03-02", "the book2", "2017-03-02"
            };
            List <string> dueDates = newPatron.GetDueDate();

            Assert.Equal(expected, dueDates);
        }
Ejemplo n.º 2
0
        public void Test_FindCopy()
        {
            Copy newcopy = new Copy(0, new DateTime(2016,07,20), 1);
              newcopy.Save();

              Assert.Equal(newcopy.id, Copy.Find(newcopy.id).id);
        }
Ejemplo n.º 3
0
        public void Test_Find_FindCopyInDatabase()
        {
            Copy testCopy = new Copy ("New", 1, new DateTime(2016, 7, 25), new DateTime(2016, 8, 25));
             testCopy.Save();

             Copy result = Copy.Find(testCopy.GetId());

             Assert.Equal(testCopy, result);
        }
Ejemplo n.º 4
0
        public void T5_Find_FindsCopyInDatabase()
        {
            Copy testCopy = new Copy(1);
              testCopy.Save();

              Copy foundCopy = Copy.Find(testCopy.GetId());

              Assert.Equal(testCopy, foundCopy);
        }
Ejemplo n.º 5
0
        public void T3_Save_SavesToDB()
        {
            Copy testCopy = new Copy(1);
              testCopy.Save();

              List<Copy> result = Copy.GetAll();
              List<Copy> testList = new List<Copy>{testCopy};

              Assert.Equal(testList, result);
        }
Ejemplo n.º 6
0
        public void FindById_ReturnsCopyWhenSearchedById()
        {
            Copy newCopy = new Copy(1);

            newCopy.Save();

            Copy result = Copy.FindById(newCopy.GetId());

            Assert.Equal(newCopy, result);
        }
Ejemplo n.º 7
0
        public void T5_Find_FindsCopyInDatabase()
        {
            Copy testCopy = new Copy(1);

            testCopy.Save();

            Copy foundCopy = Copy.Find(testCopy.GetId());

            Assert.Equal(testCopy, foundCopy);
        }
Ejemplo n.º 8
0
        public void T4_Save_AssignsIdToCopy()
        {
            Copy testCopy = new Copy(2);
              testCopy.Save();

              Copy savedCopy = Copy.GetAll()[0];
              int result = savedCopy.GetId();
              int testId = testCopy.GetId();

              Assert.Equal(testId, result);
        }
Ejemplo n.º 9
0
        public void Test_GetAll_RetrieveAllCopies()
        {
            Copy testCopy1 = new Copy ("New", 1, new DateTime(2016, 7, 25), new DateTime(2016, 8, 25));
             Copy testCopy2 = new Copy ("Worn & Torn", 2, new DateTime(2016, 7, 25), new DateTime(2016, 8, 25));
             testCopy1.Save();
             testCopy2.Save();

              List<Copy> testList = new List<Copy> {testCopy1, testCopy2};
              List<Copy> result = Copy.GetAll();

              Assert.Equal(testList, result);
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
        public void T4_Save_AssignsIdToCopy()
        {
            Copy testCopy = new Copy(2);

            testCopy.Save();

            Copy savedCopy = Copy.GetAll()[0];
            int  result    = savedCopy.GetId();
            int  testId    = testCopy.GetId();

            Assert.Equal(testId, result);
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
        public void GetCopies_GetsCopiesFromDatabase()
        {
            Book newBook = new Book("Mr Wiggles");

            newBook.Save();
            Copy newCopy = new  Copy(newBook.GetId(), 5, DateTime.Today);

            newCopy.Save();

            int result = newBook.GetCopies();

            Assert.Equal(5, result);
        }
Ejemplo n.º 14
0
        public void Save_SavesNewCopy()
        {
            Copy newCopy = new Copy(1);

            newCopy.Save();

            List <Copy> expectedResult = new List <Copy> {
                newCopy
            };
            List <Copy> actual = Copy.GetAll();

            Assert.Equal(expectedResult, actual);
        }
Ejemplo n.º 15
0
        public void T3_Save_SavesToDB()
        {
            Copy testCopy = new Copy(1);

            testCopy.Save();

            List <Copy> result   = Copy.GetAll();
            List <Copy> testList = new List <Copy> {
                testCopy
            };

            Assert.Equal(testList, result);
        }
Ejemplo n.º 16
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);
        }
Ejemplo n.º 17
0
        public void T6_Update_UpdatesCopyInDB()
        {
            Copy testCopy = new Copy(1);

            testCopy.Save();

            int newBookId = 2;

            testCopy.Update(newBookId);

            int resultBookId = testCopy.GetBookId();

            Assert.Equal(newBookId, resultBookId);
        }
Ejemplo n.º 18
0
        public void Delete_DeletesCopyFromDatabase()
        {
            Copy newCopy = new Copy(1);

            newCopy.Save();

            newCopy.Delete();

            List <Copy> expectedResult = new List <Copy> {
            };
            List <Copy> actualResult   = Copy.GetAll();

            Assert.Equal(expectedResult, actualResult);
        }
Ejemplo n.º 19
0
        public void GetCopies_ShowsAllCopiesForSelectedBook_List()
        {
            Book newBook = new Book("Roger Rabbit");

            newBook.Save();

            Copy newCopy = new Copy(newBook.GetId());

            newCopy.Save();
            List <Copy> expectedResult = new List <Copy> {
                newCopy
            };

            Assert.Equal(expectedResult, newBook.GetCopies());
        }
Ejemplo n.º 20
0
        public void GetAll_true()
        {
            //Arrange
            Copy copyOne = new Copy(1, 5, DateTime.Today);

            copyOne.Save();
            Copy copyTwo = new Copy(4, 16, DateTime.Today);

            copyTwo.Save();
            // Act
            int result = Copy.GetAll().Count;

            //Assert
            Assert.Equal(2, result);
        }
Ejemplo n.º 21
0
        public void Test_DeleteOne_DeletesOneCopy()
        {
            Copy newCopy1 = new Copy ("New", 1, new DateTime(2016, 7, 25), new DateTime(2016, 8, 25));
             Copy newCopy2 = new Copy ("Worn & Torn", 2, new DateTime(2016, 7, 25), new DateTime(2016, 8, 25));
             newCopy1.Save();
             newCopy2.Save();
             List<Copy> newList = Copy.GetAll();

             newCopy1.DeleteOne();

             List<Copy> resultList = Copy.GetAll();
             List<Copy> testList = new List<Copy> {newCopy2};

              Assert.Equal(testList, resultList);
        }
Ejemplo n.º 22
0
        public void Test_Save_AssignsIdToCopyObject()
        {
            //Arrange
            Copy testCopy = new Copy(1, 15);

            testCopy.Save();

            //Act
            Copy savedCopy = Copy.GetAll()[0];

            int result = savedCopy.GetId();
            int testId = testCopy.GetId();

            //Assert
            Assert.Equal(testId, result);
        }
Ejemplo n.º 23
0
        public void Test_Find_FindsCopyInDatabase()
        {
            //Arrange
            Copy testCopy1 = new Copy(1, 15);

            testCopy1.Save();
            Copy testCopy2 = new Copy(2, 20);

            testCopy2.Save();

            //Act
            Copy result = Copy.Find(testCopy2.GetId());

            //Assert
            Assert.Equal(testCopy2, result);
        }
Ejemplo n.º 24
0
        public void AddCopy_AddsCopyToPatron_True()
        {
            Patron testPatron = new Patron("Penny Flowers");

            testPatron.Save();
            Copy newCopy = new Copy(1, 5, DateTime.Today);

            newCopy.Save();
            testPatron.AddCopy(newCopy);
            List <Copy> expected = new List <Copy> {
                newCopy
            };
            List <Copy> result = testPatron.GetCopies();

            Assert.Equal(expected, result);
        }
Ejemplo n.º 25
0
        public void AddCopy_OneCopy_CopyNotAvailable()
        {
            Patron testPatron = new Patron("Britton");

            testPatron.Save();

            Copy newCopy = new Copy(1, 15);

            newCopy.Save();

            testPatron.AddCopy(newCopy);

            int available = newCopy.GetAvailable();

            Assert.Equal(0, available);
        }
Ejemplo n.º 26
0
        public void AddPatron_AddsPatronToCopy_True()
        {
            Patron testPatron = new Patron("Penny Flowers");

            testPatron.Save();
            Copy newCopy = new Copy(1, 5, DateTime.Today);

            newCopy.Save();
            newCopy.AddPatron(testPatron);
            List <Patron> expected = new List <Patron> {
                testPatron
            };
            List <Patron> result = newCopy.GetPatrons();

            Assert.Equal(expected, result);
        }
Ejemplo n.º 27
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]);
        }
Ejemplo n.º 28
0
        public void CheckIn_OneCopy_PatronAndNewCopy()
        {
            Patron testPatron = new Patron("Britton");

            testPatron.Save();

            Copy newCopy = new Copy(1, 15);

            newCopy.Save();

            testPatron.AddCopy(newCopy);
            testPatron.CheckIn(newCopy);

            List <Copy> allCopies  = testPatron.GetCurrentCopy();
            int         checkedOut = allCopies.Count;

            Assert.Equal(0, checkedOut);
        }
Ejemplo n.º 29
0
        public void Delete_OneCopy_CopyDeleted()
        {
            Copy testCopy1 = new Copy(1, 15);

            testCopy1.Save();
            Copy testCopy2 = new Copy(2, 20);

            testCopy2.Save();

            testCopy1.Delete();

            List <Copy> allCopys = Copy.GetAll();
            List <Copy> expected = new List <Copy> {
                testCopy2
            };

            Assert.Equal(expected, allCopys);
        }
Ejemplo n.º 30
0
        public void AddCopy_OneCopy_PatronAndNewCopy()
        {
            Patron testPatron = new Patron("Britton");

            testPatron.Save();

            Copy newCopy = new Copy(1, 15);

            newCopy.Save();

            testPatron.AddCopy(newCopy);

            List <Copy> allCopies  = testPatron.GetCopy();
            int         checkedOut = allCopies[0].GetBookId();

            int expected = newCopy.GetBookId();

            Assert.Equal(expected, checkedOut);
        }
Ejemplo n.º 31
0
        public void T7_Delete_DeletesCopyFromDB()
        {
            //Always remember to save to DB (Save())
            Copy testCopy1 = new Copy(1);

            testCopy1.Save();
            Copy testCopy2 = new Copy(2);

            testCopy2.Save();

            testCopy1.Delete();

            List <Copy> result     = Copy.GetAll();
            List <Copy> testCopies = new List <Copy> {
                testCopy2
            };

            Assert.Equal(testCopies, result);
        }
Ejemplo n.º 32
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]);
        }
Ejemplo n.º 33
0
        public void T9_GetCopys_ReturnsAllPatronCopys()
        {
            Patron testPatron = new Patron("Barb");

            testPatron.Save();

            Copy testCopy1 = new Copy(5);

            testCopy1.Save();

            Copy testCopy2 = new Copy(6);

            testCopy2.Save();

            testPatron.AddCopy(testCopy1);
            List <Copy> result   = testPatron.GetCopies();
            List <Copy> testList = new List <Copy> {
                testCopy1
            };

            Assert.Equal(testList, result);
        }
Ejemplo n.º 34
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);
        }
Ejemplo n.º 35
0
        public void T8_AddCopy_AddsCopyToPatron()
        {
            Book newBook = new Book("Freedom");

            newBook.Save();

            Copy testCopy = new Copy(newBook.GetId());

            testCopy.Save();


            Patron testPatron = new Patron("Barb");

            testPatron.Save();

            testPatron.AddCopy(testCopy);
            List <Copy> result   = testPatron.GetCopies();
            List <Copy> testList = new List <Copy> {
                testCopy
            };

            Assert.Equal(testList, result);
        }
Ejemplo n.º 36
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);
        }
Ejemplo n.º 37
0
        public void AddCopy_OneCopy_CopyNotAvailable2()
        {
            Patron testPatron = new Patron("Britton");

            testPatron.Save();
            Patron testPatron2 = new Patron("dkjhfksjdhf");

            testPatron2.Save();

            Book newBook = new Book("super book");

            Copy newCopy = new Copy(newBook.GetId(), 1);

            newCopy.Save();

            testPatron.AddCopy(newCopy);
            testPatron2.AddCopy(newCopy);

            List <Copy> patroncopy = testPatron2.GetCopy();
            List <Copy> expected   = new List <Copy> {
            };

            Assert.Equal(expected, patroncopy);
        }
Ejemplo n.º 38
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);
        }
Ejemplo n.º 39
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);
        }
Ejemplo n.º 40
0
        public void Test_Save_SavesCopiesToDatabase()
        {
            Copy newCopy1 = new Copy ("New", 1, new DateTime(2016, 7, 25), new DateTime(2016, 8, 25));
             Copy newCopy2 = new Copy ("Worn & Torn", 2, new DateTime(2016, 7, 25), new DateTime (2016, 8, 25));
             newCopy1.Save();
             newCopy2.Save();

             int resultCount = Copy.GetAll().Count;

            Assert.Equal(2, resultCount);
        }
Ejemplo n.º 41
0
        public void Test_Update_UpdateCopyInDatabase()
        {
            Copy newCopy = new Copy ("New", 1, new DateTime(2016, 7, 25), new DateTime(2016, 8, 25));
             newCopy.Save();
             newCopy.SetCondition("Worn & Torn");
             newCopy.Update();

             Copy updatedCopy = Copy.Find(newCopy.GetId());

             Assert.Equal(newCopy.GetCondition(), updatedCopy.GetCondition());
        }
Ejemplo n.º 42
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);
        }
Ejemplo n.º 43
0
        public void Test_GetCopies_ReturnsAllCopiesForBook()
        {
            Book testBook = new Book ("Redwall");
              testBook.Save();
              Copy newCopy1 = new Copy ("New", testBook.GetId(), new DateTime(2016, 7, 25), new DateTime(2016, 8, 25));
              Copy newCopy2 = new Copy ("Worn & Torn", testBook.GetId(), new DateTime(2016, 7, 25), new DateTime (2016, 8, 25));
              newCopy1.Save();
              newCopy2.Save();

              List<Copy> testCopyList = new List<Copy> {newCopy1, newCopy2};
              List<Copy> resultCopyList = testBook.GetCopies();

              Assert.Equal(testCopyList, resultCopyList);
        }
Ejemplo n.º 44
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);
        }
Ejemplo n.º 45
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);
        }
Ejemplo n.º 46
0
        public void T9_GetCopys_ReturnsAllPatronCopys()
        {
            Patron testPatron = new Patron("Barb");
              testPatron.Save();

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

              Copy testCopy2 = new Copy(6);
              testCopy2.Save();

              testPatron.AddCopy(testCopy1);
              List<Copy> result = testPatron.GetCopies();
              List<Copy> testList= new List<Copy>{testCopy1};

              Assert.Equal(testList,result);
        }
Ejemplo n.º 47
0
        public void T7_Delete_DeletesCopyFromDB()
        {
            //Always remember to save to DB (Save())
              Copy testCopy1 = new Copy(1);
              testCopy1.Save();
              Copy testCopy2 = new Copy(2);
              testCopy2.Save();

              testCopy1.Delete();

              List<Copy> result = Copy.GetAll();
              List<Copy> testCopies = new List<Copy> {testCopy2};

              Assert.Equal(testCopies, result);
        }
Ejemplo n.º 48
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];
              };
        }
Ejemplo n.º 49
0
        public HomeModule()
        {
            Get["/"] = _ =>
            {
                return(View["patron_login.cshtml"]);
            };

            Post["/home"] = _ =>
            {
                //make newPatron object with more information like password and username
                Patron newPatron = new Patron(Request.Form["new-name"]);
                newPatron.Save();
                return(View["patron_home.cshtml", newPatron]);
            };

            Get["/search/books"] = _ =>
            {
                return(View["search_books.cshtml"]);
            };

            Post["/search/books"] = _ =>
            {
                Book foundBook = Book.Search(Request.Form["title"]);
                return(View["search_books.cshtml", foundBook]);
            };

            Get["/checkout/{id}"] = parameters =>
            {
                Book foundBook = Book.Find(parameters.id);
                return(View["checkout.cshtml", foundBook]);
            };

////////////////////////////////////////////////////////////////


            Get["/admin/login"] = _ =>
            {
                return(View["admin_login.cshtml"]);
            };

            Post["/admin/home"] = _ =>
            {
                //make newPatron object with more information like password and username
                Patron newPatron = new Patron(Request.Form["admin-new-name"]);
                newPatron.Save();
                return(View["admin_home.cshtml", newPatron]);
            };

            Get["/admin/books"] = _ =>
            {
                return(View["admin_books.cshtml", ModelMaker()]);
            };

            Post["/admin/books"] = _ =>
            {
                Author newAuthor = new Author(Request.Form["author"]);
                newAuthor.Save();

                Book newBook = new Book(Request.Form["title"]);
                newBook.Save();
                newBook.AddAuthor(newAuthor.GetId());

                for (int i = 1; i <= Request.Form["copy"]; i++)
                {
                    Copy newCopy = new Copy(newBook.GetId(), i);
                    newCopy.Save();
                }

                return(View["admin_books.cshtml", ModelMaker()]);
            };

            Get["/admin/books/{id}"] = parameters =>
            {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };

                Book newBook = Book.Find(parameters.id);
                model.Add("Book", newBook);

                List <Author> newBookAuthor = newBook.GetAuthor();
                model.Add("Authors", newBookAuthor);

                List <Copy> newBookCopies = newBook.GetCopy();
                model.Add("Copies", newBookCopies);

                return(View["book.cshtml", model]);
            };
// that works -V
            Delete["/admin/book/{id}"] = parameters =>
            {
                Book selectedBook = Book.Find(parameters.id);
                selectedBook.Delete();

                return(View["admin_books.cshtml", ModelMaker()]);
            };

            Patch["/admin/book/{id}"] = parameters =>
            {
                Book selectedBook = Book.Find(parameters.id);
                selectedBook.UpdateTitle(Request.Form["name"]);

                return(View["admin_books.cshtml", ModelMaker()]);
            };

            // Post["/admin/home"] = _ =>
            // {
            //     model =
            //     return view["admin_home.cshtml", ModelMaker()];
            // };
        }
Ejemplo n.º 50
0
        public void Test_GetCopies()
        {
            Book newbook = new Book("2a", "Sf", "The blob");
              newbook.Save();

              Copy newcopy = new Copy(newbook.id, new DateTime(2016,07,20), 1);
              newcopy.Save();

              Assert.Equal(newcopy.id, newbook.GetCopies()[0].id);
        }
Ejemplo n.º 51
0
        public void T6_Update_UpdatesCopyInDB()
        {
            Copy testCopy = new Copy(1);
              testCopy.Save();

              int newBookId = 2;

              testCopy.Update(newBookId);

              int resultBookId = testCopy.GetBookId();

              Assert.Equal(newBookId, resultBookId);
        }
Ejemplo n.º 52
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"]);
            };
        }
Ejemplo n.º 53
0
        public void T8_AddCopy_AddsCopyToPatron()
        {
            Book newBook = new Book("Freedom");
              newBook.Save();

              Copy testCopy = new Copy(newBook.GetId());
              testCopy.Save();

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

              testPatron.AddCopy(testCopy);
              List<Copy> result = testPatron.GetCopies();
              List<Copy> testList = new List<Copy> {testCopy};

              Assert.Equal(testList, result);
        }