public void T5_Find_FindsPatronInDatabase() { Patron testPatron = new Patron("Judy"); testPatron.Save(); Patron foundPatron = Patron.Find(testPatron.GetId()); Assert.Equal(testPatron, foundPatron); }
public void Patron_Find_3() { Patron newPatron = new Patron("Johnny English", "555-555-5555"); newPatron.Save(); Patron foundPatron = Patron.Find(newPatron.GetId()); Assert.Equal(newPatron, foundPatron); }
public void Find_FindsPatronInDatabase_true() { //Arrange Patron testPatron = new Patron("Penny Flowers"); testPatron.Save(); //Act Patron foundPatron = Patron.Find(testPatron.GetId()); //Assert Assert.Equal(testPatron, foundPatron); }
public void Test_Find_FindsPatronInDatabase() { //Arrange Patron testPatron1 = new Patron("example patron1"); testPatron1.Save(); Patron testPatron2 = new Patron("example patron2"); testPatron2.Save(); //Act Patron result = Patron.Find(testPatron2.GetId()); //Assert Assert.Equal(testPatron2, result); }
public HomeModule() { string thisDay = "1"; Get["/"] = _ => { return(View["index.cshtml", ModelMaker()]); }; Post["/overdue-date"] = _ => { thisDay = Request.Form["current-day"]; Dictionary <string, object> model = ModelMaker(); model.Add("Overdue", Checkout.GetAllOverdue(thisDay)); return(View["overdue.cshtml", model]); }; Post["/add-book"] = _ => { Book newBook = new Book(Request.Form["book-name"], Request.Form["copies"]); newBook.Save(); if (Request.Form["author-name"] != null) { Author newAuthor = new Author(Request.Form["author-name"]); newAuthor.Save(); newBook.AddAuthor(newAuthor.GetId()); } Dictionary <string, object> model = ModelMaker(); model.Add("Book", newBook); return(View["book.cshtml", model]); }; Post["/add-author"] = _ => { Author newAuthor = new Author(Request.Form["author-name"]); newAuthor.Save(); Dictionary <string, object> model = ModelMaker(); model.Add("Author", newAuthor); return(View["author.cshtml", model]); }; Post["/patron/{patronId}/return/{id}"] = parameters => { Checkout.Return(parameters.id); Dictionary <string, object> model = ModelMaker(); model.Add("Patron", Patron.Find(parameters.patronId)); model.Add("Patron Checkouts", Patron.Find(parameters.patronId).GetCheckouts()); return(View["patron.cshtml", model]); }; Post["/add-patron"] = _ => { Patron newPatron = new Patron(Request.Form["patron-name"], Request.Form["patron-phone"]); newPatron.Save(); Dictionary <string, object> model = ModelMaker(); model.Add("Patron", newPatron); model.Add("Patron Checkouts", newPatron.GetCheckouts()); return(View["patron.cshtml", model]); }; Get["/patron/{id}"] = parameters => { Dictionary <string, object> model = ModelMaker(); model.Add("Patron", Patron.Find(parameters.id)); model.Add("Patron Checkouts", Patron.Find(parameters.id).GetCheckouts()); return(View["patron.cshtml", model]); }; Post["/patron/{id}"] = parameters => { Checkout newCheckout = new Checkout(Request.Form["due-date"], parameters.id, Request.Form["booklist"]); newCheckout.Save(Book.Find(Request.Form["booklist"])); Dictionary <string, object> model = ModelMaker(); model.Add("Patron", Patron.Find(parameters.id)); model.Add("Patron Checkouts", Patron.Find(parameters.id).GetCheckouts()); return(View["patron.cshtml", model]); }; Patch["/patron/{id}"] = parameters => { Patron.Find(parameters.id).Update(Request.Form["new-name"], Request.Form["new-phone"]); Dictionary <string, object> model = ModelMaker(); model.Add("Patron", Patron.Find(parameters.id)); model.Add("Patron Checkouts", Patron.Find(parameters.id).GetCheckouts()); return(View["patron.cshtml", model]); }; Get["/author/{id}"] = parameters => { Dictionary <string, object> model = ModelMaker(); model.Add("Author", Author.Find(parameters.id)); return(View["author.cshtml", model]); }; Post["/author/{id}"] = parameters => { Author.Find(parameters.id).AddBook(Request.Form["book-id"]); Dictionary <string, object> model = ModelMaker(); model.Add("Author", Author.Find(parameters.id)); return(View["author.cshtml", model]); }; Patch["/author/{id}"] = parameters => { Author.Find(parameters.id).Update(Request.Form["new-name"]); Dictionary <string, object> model = ModelMaker(); model.Add("Author", Author.Find(parameters.id)); return(View["author.cshtml", model]); }; Delete["/author/{id}"] = parameters => { Author.Delete(parameters.id); return(View["index.cshtml", ModelMaker()]); }; Get["/book/{id}"] = parameters => { Dictionary <string, object> model = ModelMaker(); model.Add("Book", Book.Find(parameters.id)); return(View["book.cshtml", model]); }; Delete["/book/{id}"] = parameters => { Dictionary <string, object> model = ModelMaker(); model.Add("Overdue", Checkout.GetAllOverdue(thisDay)); Book.Delete(parameters.id); return(View["index.cshtml", model]); }; Post["/book/{id}"] = parameters => { Book.Find(parameters.id).AddAuthor(Request.Form["author-id"]); Dictionary <string, object> model = ModelMaker(); model.Add("Book", Book.Find(parameters.id)); return(View["book.cshtml", model]); }; Post["/book/{id}/remove_author"] = parameters => { Book.Find(parameters.id).RemoveAuthor(Request.Form["author-id"]); Dictionary <string, object> model = ModelMaker(); model.Add("Book", Book.Find(parameters.id)); return(View["book.cshtml", model]); }; Patch["/book/{id}"] = parameters => { Book.Find(parameters.id).Update(Request.Form["new-name"], Request.Form["new-copies"]); Dictionary <string, object> model = ModelMaker(); model.Add("Book", Book.Find(parameters.id)); return(View["book.cshtml", model]); }; }
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"]); }; }