static void Main(string[] args) { var book = new Book(30, "Drama"); var book1 = new Book(15, "Action"); var book2 = new Book(13, "SF"); var author = new Author("Bob", "*****@*****.**"); var author1 = new Author("Jim", "*****@*****.**"); var author2 = new Author("Jake", "*****@*****.**"); book.AddAuthor(author); book1.AddAuthor(author2); book2.AddAuthor(author1); Library librarie = new Library("GHEORGHE ASACHI"); librarie.AddBook(book); librarie.AddBook(book1); librarie.AddBook(book2); librarie.RemoveBook(book1); librarie.Print(); }
public HomeModule() { Get["/"] = _ => { return(View["index.cshtml"]); }; Get["/wipe-database"] = _ => { return(View["wipe-database.cshtml"]); }; Post["/wipe-database"] = _ => { Book.DeleteAll(); Author.DeleteAll(); Checkout.DeleteAll(); Copy.DeleteAll(); Patron.DeleteAll(); return(View["index.cshtml"]); }; Get["/books"] = _ => { Console.WriteLine("book page navigation"); return(View["book-management.cshtml", Book.GetAll()]); }; Post["/books"] = _ => { Console.WriteLine("adding new book"); Book newBook = new Book(Request.Form["title"]); newBook.Save(); string[] separator = new string[] { ", " }; string authorList = Request.Form["author"]; string[] authors = authorList.Split(separator, StringSplitOptions.RemoveEmptyEntries); foreach (var author in authors) { if (Author.CheckIfAuthorExists(author)) { Author newAuthor = Author.FindByName(author); newBook.AddAuthor(newAuthor); } else { Author newAuthor = new Author(author); newAuthor.Save(); newBook.AddAuthor(newAuthor); } } for (int i = 0; i < Int32.Parse(Request.Form["copies"]); i++) { Copy newCopy = new Copy(newBook.GetTitle()); newCopy.Save(); newCopy.AddBookCopy(newBook); } return(View["book-management.cshtml", Book.GetAll()]); }; Get["/confirm-checkout/{id}"] = parameter => { Copy tempCopy = Copy.Find(parameter.id); Patron newPatron = new Patron(Request.Form["patron"]); } // Post["/confirm-checkout/{id}"] =parameter=> { // Copy foundCopy = Copy.Find(parameter.id); // if(Patron.CheckIfPatronExists(Request.Form["patron"])) // { // Patron foundPatron = Patron.FindByName(Request.Form["patron"]); // foundPatron.CheckoutCopy(foundCopy); // // } // else // { // Patron newPatron = new Patron(Request.Form["patron"]); // newPatron.Save(); // newPatron.CheckoutCopy(foundCopy); // } // Checkout foundCheckout = new Checkout() // return View["checked-out.cshtml", ] // } Get["/delete-single-book/{id}"] = parameter => { Book tempBook = Book.Find(parameter.id); return(View["delete-single-book-confirm.cshtml", tempBook]); }; Post["/delete-book-confirmed"] = _ => { Book tempBook = Book.Find(Request.Form["id"]); tempBook.DeleteSingle(); return(View["book-management.cshtml", Book.GetAll()]); }; Get["/checkout-book/{id}"] = parameter => { Book tempBook = Book.Find(parameter.id); return(View["checkout-book.cshtml", tempBook]); }; Get["/authors"] = _ => { Console.WriteLine("author page navigation"); return(View["author-management.cshtml", Author.GetAll()]); }; Get["/single-author/{id}"] = parameter => { Author tempAuthor = Author.Find(parameter.id); return(View["single-author.cshtml", tempAuthor]); }; Get["/search"] = _ => { return(View["search.cshtml", Book.GetAll()]); }; }
public HomeModule() { Get["/"] = _ => { Dictionary <object, object> model = new Dictionary <object, object>(); List <Checkout> allCheckouts = Checkout.GetAll(); foreach (Checkout checkout in allCheckouts) { Patron thisPatron = Patron.Find(checkout.GetPatronsId()); model.Add(checkout, thisPatron); } return(View["index.cshtml", model]); }; Get["/books"] = _ => { List <Book> allBooks = Book.GetAll(); return(View["books.cshtml", allBooks]); }; Get["/patrons"] = _ => { List <Patron> allPatrons = Patron.GetAll(); return(View["patrons.cshtml", allPatrons]); }; Get["/authors"] = _ => { List <Author> allAuthors = Author.GetAll(); return(View["authors.cshtml", allAuthors]); }; Post["/add_book"] = _ => { Book newBook = new Book(Request.Form["title"]); newBook.Save(); Author newAuthor = new Author(Request.Form["author-first"], Request.Form["author-last"]); newAuthor.Save(); newBook.AddAuthor(newAuthor); Copy newCopy = new Copy(newBook.GetId()); newCopy.Save(); newBook.AddCopy(Request.Form["num-copies"]); List <Book> allBooks = Book.GetAll(); return(View["books.cshtml", allBooks]); }; Post["/add_patron"] = _ => { Patron newPatron = new Patron(Request.Form["patron-first"], Request.Form["patron-last"]); newPatron.Save(); List <Patron> allPatrons = Patron.GetAll(); return(View["patrons.cshtml", allPatrons]); }; Get["/book/{id}"] = parameters => { Book newBook = Book.Find(parameters.id); Dictionary <string, object> model = new Dictionary <string, object>(); model.Add("book", newBook); model.Add("allAuthors", Author.GetAll()); return(View["book.cshtml", model]); }; Get["/author/{id}"] = parameters => { Author newAuthor = Author.Find(parameters.id); return(View["author.cshtml", newAuthor]); }; Get["/patron/{id}"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object>(); Patron newPatron = Patron.Find(parameters.id); model.Add("patron", newPatron); model.Add("allBooks", Book.GetAll()); return(View["patron.cshtml", model]); }; Post["/patron/delete/{id}"] = parameters => { Patron newPatron = Patron.Find(parameters.id); newPatron.DeletePatron(); List <Patron> allPatrons = Patron.GetAll(); return(View["patrons.cshtml", allPatrons]); }; Post["/patrons/delete"] = _ => { Patron.DeleteAll(); List <Patron> allPatrons = Patron.GetAll(); return(View["patrons.cshtml", allPatrons]); }; Post["/books/delete"] = _ => { Book.DeleteAll(); List <Book> allBooks = Book.GetAll(); return(View["books.cshtml", allBooks]); }; Post["/book/delete/{id}"] = parameters => { Book newBook = Book.Find(parameters.id); newBook.DeleteBook(); List <Book> allBooks = Book.GetAll(); return(View["books.cshtml", allBooks]); }; Post["/book/search_title"] = _ => { Book searchedBook = Book.SearchTitle(Request.Form["search-book-title"]); Dictionary <string, object> model = new Dictionary <string, object>(); model.Add("book", searchedBook); model.Add("allAuthors", Author.GetAll()); return(View["book.cshtml", model]); }; Post["/patron/search_name"] = _ => { Patron searchedPatron = Patron.SearchPatron(Request.Form["search-patron-name"]); Dictionary <string, object> model = new Dictionary <string, object>(); model.Add("patron", searchedPatron); model.Add("allBooks", Book.GetAll()); return(View["patron.cshtml", model]); }; Post["book/add_author/{id}"] = parameters => { Book searchedBook = Book.Find(parameters.id); searchedBook.AddAuthor(Author.Find(Request.Form["author-id"])); Dictionary <string, object> model = new Dictionary <string, object>(); model.Add("book", searchedBook); model.Add("allAuthors", Author.GetAll()); return(View["book.cshtml", model]); }; Patch["/book/update_title"] = _ => { Book newBook = Book.Find(Request.Form["book-id"]); newBook.UpdateTitle(Request.Form["new-title"]); Dictionary <string, object> model = new Dictionary <string, object>(); model.Add("book", newBook); model.Add("allAuthors", Author.GetAll()); return(View["book.cshtml", model]); }; Post["/book/add_copy"] = _ => { Book newBook = Book.Find(Request.Form["book-id"]); newBook.AddCopy(Request.Form["copy-amount"]); Dictionary <string, object> model = new Dictionary <string, object>(); model.Add("book", newBook); model.Add("allAuthors", Author.GetAll()); return(View["book.cshtml", model]); }; Post["/book/checkout/{id}"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object>(); Patron foundPatron = Patron.Find(parameters.id); Book checkedoutBook = Book.Find(Request.Form["book-id"]); checkedoutBook.CheckoutBook(foundPatron.GetId()); model.Add("patron", foundPatron); model.Add("allBooks", Book.GetAll()); return(View["patron.cshtml", model]); }; Post["/add_author"] = _ => { Author newAuthor = new Author(Request.Form["author-first"], Request.Form["author-last"]); newAuthor.Save(); List <Author> allAuthors = Author.GetAll(); return(View["authors.cshtml", allAuthors]); }; Post["/authors/delete"] = _ => { Author.DeleteAll(); List <Author> allAuthors = Author.GetAll(); return(View["authors.cshtml", allAuthors]); }; Post["/delete/author/{id}"] = parameters => { Author foundAuthor = Author.Find(parameters.id); foundAuthor.DeleteAuthor(); List <Author> allAuthors = Author.GetAll(); return(View["authors.cshtml", allAuthors]); }; }