public bool Borrow(string isbn, string cnp) { var searchedBookIndex = AvailableBooks.FindIndex(item => item.Book.ISBN == isbn); if (searchedBookIndex != -1 && AvailableBooks[searchedBookIndex].Quantity > 0 && _dependencyService.Get <IValidationService>().IsValidCNP(cnp)) { AvailableBooks[searchedBookIndex].Quantity--; var currentDate = DateTimeOffset.UtcNow; BorrowedBooks.Add(new Borrowing { CNP = cnp, ISBN = isbn, BorrowingPrice = AvailableBooks[searchedBookIndex].BorrowPrice, BorrowingStartDate = currentDate.ToUnixTimeMilliseconds().ToString(), BorrowingEndDate = currentDate.AddDays(AppConstants.MAX_LOAN_DAYS).ToUnixTimeMilliseconds().ToString() }); return(true); } else { return(false); } }
private void usuń_książkę(object sender, RoutedEventArgs e) { Button button = sender as Button; AvailableBooks book = button.DataContext as AvailableBooks; _data.delBook(_module.SqlProfile.connectionString.ToString(), book); refresh(); }
public List <AvailableBooks> GetAvailableBooks(List <JToken> result) { List <AvailableBooks> list = new List <AvailableBooks>(); foreach (var res in result) { AvailableBooks el = JsonConvert.DeserializeObject <AvailableBooks>(res.ToString()); list.Add(el); } return(list); }
public void AddBook(Book book) { if (book.Available) { AvailableBooks.Add(book); } else { CheckedOutBooks.Add(book); } }
public async void delBook(string connectionString, AvailableBooks book) { var p = new { isbn = book.ISBN }; using (IDbConnection cnn = new SqlConnection(connectionString)) { cnn.Execute("[dbo].[SpDelBook]", p, commandType: CommandType.StoredProcedure); } }
public bool AddExistingBook(string isbn, int quantity = 1) { var bookIndex = AvailableBooks.FindIndex(item => item.Book.ISBN == isbn); if ((bookIndex != -1) && _dependencyService.Get <IValidationService>().IsValidQuantity(quantity)) { AvailableBooks[bookIndex].Quantity += quantity; return(true); } return(false); }
public int GetAvailableQuantity(string isbn) { var searchedBook = AvailableBooks.FirstOrDefault(bookInfo => bookInfo.Book.ISBN == isbn); if (searchedBook != null) { return(searchedBook.Quantity); } else { return(-1); } }
private void dodaj_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(dataOddania.ToString())) { dataOddania.BorderBrush = Brushes.Red; return; } if (users.SelectedItem == null) { users.BorderBrush = Brushes.Red; return; } if (books.SelectedItem == null) { books.BorderBrush = Brushes.Red; return; } try { ReaderModel reader = (ReaderModel)users.SelectedItem; AvailableBooks book = (AvailableBooks)books.SelectedItem; DateTime time = (DateTime)dataOddania.SelectedDate; _data.NewRental(_module.SqlProfile.connectionString.ToString(), book, reader, time); books.BorderBrush = Brushes.Transparent; users.BorderBrush = Brushes.Transparent; dataOddania.BorderBrush = Brushes.Transparent; fUser.Text = null; fBook.Text = null; users.SelectedItem = null; books.SelectedItem = null; dataOddania.SelectedDate = null; BooksList(); UsersList(); } catch (System.Data.SqlClient.SqlException) { dataOddania.BorderBrush = Brushes.Red; } catch { books.BorderBrush = Brushes.Red; users.BorderBrush = Brushes.Red; dataOddania.BorderBrush = Brushes.Red; } }
public void NewRental(string connectionString, AvailableBooks book, ReaderModel reader, DateTime time) { var p = new { isbn = book.ISBN, Nr_Czytelnika = reader.Nr_czytelnika, spodziewanaDataZwrotu = time }; using (IDbConnection cnn = new SqlConnection(connectionString)) { cnn.Execute("[dbo].[SpNewRental]", p, commandType: CommandType.StoredProcedure); } }
public void CheckOutBooks() { System.Console.WriteLine("Enter the number of the book that you'd like to check out: "); ViewBooks(AvailableBooks); Book bookToCheckOut = ValidateUserInput(AvailableBooks); if (bookToCheckOut == null) { return; } bookToCheckOut.Available = false; AvailableBooks.Remove(bookToCheckOut); CheckedOutBooks.Add(bookToCheckOut); System.Console.WriteLine("We hope that you enjoy {0}", bookToCheckOut.Title); }
public void Checkout(string selection) { Book selectedBook = ValidateBook(selection, AvailableBooks); if (selectedBook == null) { Console.Clear(); System.Console.WriteLine(@"Invalid Selection"); return; } selectedBook.Available = false; AvailableBooks.Remove(selectedBook); CheckedOut.Add(selectedBook); System.Console.WriteLine("Congrats my dude, you go it"); }
public void CheckoutBook() { System.Console.WriteLine("Enter the number of the book you'd like to checkout."); ViewBooks(AvailableBooks); Book bookToCheckout = ValidateUserInput(AvailableBooks); if (bookToCheckout == null) { return; } bookToCheckout.Available = false; AvailableBooks.Remove(bookToCheckout); CheckedOutBooks.Add(bookToCheckout); System.Console.WriteLine($"Enjoy your copy of {bookToCheckout.Title}."); }
// CHECKOUT BOOK public void CheckoutBook(string selection) { Book selectedBook = ValidateBook(AvailableBooks, selection); if (selectedBook == null) { Console.WriteLine(" Invalid Selection"); return; } else { selectedBook.Available = false; CheckedOut.Add(selectedBook); AvailableBooks.Remove(selectedBook); Console.WriteLine(" Check out successful!"); } }
public void NewBook(string connectionString, AvailableBooks book, SimlpeAthor athor) { var p = new { isbn = book.ISBN, tytul = book.Tytuł, rok_wydania = book.Rok_wydania, wydawca = book.Wydawca, kategoria = book.Kategoria, nr_autora = athor.Nr_autora }; using (IDbConnection cnn = new SqlConnection(connectionString)) { cnn.Execute("[dbo].[SpNewBook]", p, commandType: CommandType.StoredProcedure); } }
// RETURN BOOK public void ReturnBook(string selection) { Book selectedBook = ValidateBook(CheckedOut, selection); if (selectedBook == null) { Console.WriteLine(" Invalid Selection"); return; } else { selectedBook.Available = true; AvailableBooks.Add(selectedBook); CheckedOut.Remove(selectedBook); Console.Clear(); Console.WriteLine(" Book Returned!"); } }
public void ReturnBook(string selection) { Book selectedBook = ValidateBook(selection, CheckedOut); if (selectedBook == null || selectedBook.Available == true) { Console.Clear(); System.Console.WriteLine(@"Invalid Selection"); return; } else { selectedBook.Available = true; AvailableBooks.Add(selectedBook); CheckedOut.Remove(selectedBook); System.Console.WriteLine("Congrats my Dude, Book is back"); } }
//The checkout method removes a book from Books, marks it as no long available, and moves it to CheckedOut public void Checkout(string selection) { Book selectedBook = ValidateUserSelection(selection, AvailableBooks); if (selectedBook == null) { Console.Clear(); System.Console.WriteLine(@"Invalid Selection "); return; } selectedBook.Available = false; CheckedOut.Add(selectedBook); AvailableBooks.Remove(selectedBook); Console.Clear(); System.Console.WriteLine(@"Enjoy your Book! "); }
public void ReturnBook(string selection) { //checkout book Book selectedBook = ValidateUserSelection(selection, CheckedOut); if (selectedBook == null) { System.Console.WriteLine(@"Invalid Selection, please make a valid selection: 1 "); return; } selectedBook.Available = true; AvailableBooks.Add(selectedBook); CheckedOut.Remove(selectedBook); Console.Clear(); System.Console.WriteLine("Successfully Returned Book!"); }
public void ReturnBook(string input) { Book selectedBook = ValidateBook(input, CheckedOutBooks); if (selectedBook == null) { Console.Clear(); System.Console.WriteLine("Invalid Selection... Press enter to continue"); Console.ReadLine(); return; } //set available to false, add book to checked out and remove from available array selectedBook.Available = true; AvailableBooks.Add(selectedBook); CheckedOutBooks.Remove(selectedBook); Console.Clear(); System.Console.WriteLine($"Thanks for returning {selectedBook.Title}!"); }
public void ReturnBook() { System.Console.WriteLine("Enter the number of the book you'd like to return."); ViewBooks(CheckedOutBooks); Book bookToReturn = ValidateUserInput(CheckedOutBooks); // null check to prevent breaking errors if (bookToReturn == null) { return; } // if found a book to return then: // 1. reassign the available property to true // 2. remove the book from the checkoutbooks list // 3. add the book to the availablebooks list bookToReturn.Available = true; CheckedOutBooks.Remove(bookToReturn); AvailableBooks.Add(bookToReturn); System.Console.WriteLine("Thanks for returning {0}!", bookToReturn.Title); }
public bool AddNewBook(Book book, double price, int quantity = 1) { var validationService = _dependencyService.Get <IValidationService>(); if (validationService.isValidBook(book) && validationService.IsValidPrice(price) && validationService.IsValidQuantity(quantity)) { var searchedIndex = AvailableBooks.FindIndex(item => item.Book.ISBN == book.ISBN); if (searchedIndex == -1) { AvailableBooks.Add(new BookProductInfo { Book = book, BorrowPrice = price, Quantity = quantity }); return(true); } } return(false); }
private void dodaj_książke(object sender, RoutedEventArgs e) { try { AvailableBooks book = new AvailableBooks(); book.ISBN = string.IsNullOrWhiteSpace(isbn.Text) ? throw new Exception() : isbn.Text; book.Rok_wydania = rok_wydania.Text; book.Wydawca = wydawca.Text; book.Tytuł = string.IsNullOrWhiteSpace(tytul.Text) ? throw new Exception() : tytul.Text; SimlpeAthor author = new SimlpeAthor(); author.imie_nazwisko = autor.SelectedItem?.ToString() ?? throw new Exception(); autors.ForEach(x => { if (x.imie_nazwisko == author.imie_nazwisko) { author.Nr_autora = x.Nr_autora; } }); categories.ForEach(x => { if (x.nazwa_kategorii == kategoria.SelectedItem?.ToString()) { book.Kategoria = x.id_kategorii.ToString(); } }); _data.NewBook(_module.SqlProfile.connectionString.ToString(), book, author); } catch { buttOn.Background = Brushes.DarkRed; } refresh(); Clean(); }
public void Checkout(string selection) { Book selectedBook = ValidateBook(selection, AvailableBooks); if (selectedBook == null) { Console.Clear(); System.Console.WriteLine(@"Invalid Selection "); return; } int index = Int32.TryParse(selection, out bookIndex); if (index < checkedOut.Count) { Book book = checkedOut[index]; selectedBook.Available = false; AvailableBooks.Remove(book); checkedOut.Add(book); System.Console.WriteLine($"You Gots a {selectedBook.Title}"); } }
public void LastBook() { System.Console.WriteLine(AvailableBooks.Last().Title); System.Console.WriteLine("Here is the last book. Press enter to continue"); Console.ReadLine(); }
public void AddBook(Book book) { AvailableBooks.Add(book); }
internal void addBook(Book book) { AvailableBooks.Add(book); }