/// <summary> /// Check Out Book, make changes to the database and local collections /// </summary> /// <param name="book">Book to be checked out</param> /// <param name="cardHolder">MCardholder that is checking out the book</param> /// <param name="error">an error string to be outputted should a check out error occur</param> /// <returns></returns> public bool CheckOut(Book book, MCardholder cardHolder, out string error) { if (!IsLibrarian) //if not a librarian { error = "You are not authorized to check out a book."; return(false); } if (cardHolder.HasOverdueBooks) { error = "User has Overdue books, cannot check out additional books."; return(false); } if (book.CopiesAvailable > 0) //Make sure that there is a copy available { //Create a checkout log CheckOutLog log = new CheckOutLog { Book = book, Book_BookId = book.BookId, CheckOutDate = DateTime.Now, Cardholder_PersonId = cardHolder.ID, Cardholder = cardHolder.Cardholder }; try { //Add log to context and save context.CheckOutLogs.Add(log); context.SaveChanges(); } catch (Exception ex) { while (ex != null) { ex = ex.InnerException; } DatabaseEventArgs e = new DatabaseEventArgs(ex.Message); OnDatabaseErrorRaised(e); error = "Cannot check out book. Please try again later."; return(false); } //add log to memory collection checkoutLogs.Add(log); error = ""; return(true); } error = string.Format("{0} could not be checked out, no copies available", book.Title); return(false); }
/// <summary> /// Verifies that the UserID exists and retrives the associated MCardholder from collection /// </summary> /// <returns>Returns true if UserID is valid, false otherwise</returns> private bool VerifyUserID() { cardHolder = controller.GetCardHolder(LibraryCardIDTextBox.Text); //Retrieve MCardholder if (cardHolder == null) //MCardholder not found, notify user and prep for user input { ErrorLabel.Content = "Library Card ID not found."; LibraryCardIDTextBox.Focus(); return(false); } return(true); }
/// <summary> /// Retrives a MCardholder object that is associated with the libraryCardID passed in the argument /// </summary> /// <param name="libraryCardID">libraryCardID of MCardholder</param> /// <returns>Returns MCardholder found in collection, returns null otherwise.</returns> public MCardholder GetCardHolder(string libraryCardID) { MCardholder result = null; try { result = CardholderLibraryCardIDs[libraryCardID]; } catch (KeyNotFoundException) { result = null; } return(result); }
private ObservableCollection <Book> books; //A list of books to check out /// <summary> /// Constructor for CheckOutWindow /// Initializes fields and preps the window for user interaction /// </summary> /// <param name="controller"></param> public CheckOutWindow(LibraryClientController controller) { InitializeComponent(); //initialize fields this.controller = controller; cardHolder = null; books = new ObservableCollection <Book>(); BooksListView.ItemsSource = books; //subscribe to OnDatabaseError event this.controller.OnDatabaseError += OnDatabaseErrorHandler; //preps window for user interaction ResetWindow(); }
//Returns a generic list of /// <summary> /// Retrives a list of KeyvaluePair <CheckOutLog, MCardholder> Where the key value is an overdue CheckOutLog and the value is /// the MCardholder that is associated with that CheckOutLog. /// </summary> /// <returns>A generic list of KeyValuePair <CheckOutLog, MCardholder></returns> public List <KeyValuePair <CheckOutLog, MCardholder> > GetOverdueList() { //initialize list List <KeyValuePair <CheckOutLog, MCardholder> > overdueList = new List <KeyValuePair <CheckOutLog, MCardholder> >(); //get overdue logs List <CheckOutLog> overdueLogs = checkoutLogs.OverdueLogs; //find the corresponding MCardholder from peopleList foreach (CheckOutLog key in overdueLogs) { MCardholder value = (from p in peopleList.Cardholders where p.ID == key.Cardholder_PersonId select p).SingleOrDefault(); //create KeyValuePair and add to list KeyValuePair <CheckOutLog, MCardholder> kvp = new KeyValuePair <CheckOutLog, MCardholder>(key, value); overdueList.Add(kvp); } return(overdueList); }
/// <summary> /// Retrieves all Librarians, Cardholders, and Authors from database context to generate local memory objects. /// Populates local memory collections with the newly created objects. /// </summary> private void LoadPeopleList() { //Initialize peopleList peopleList = new PeopleList(); LibrarianUserIDs = new Dictionary <string, string>(); CardholderLibraryCardIDs = new Dictionary <string, MCardholder>(); //Librarians var dbLibrarians = (from l in context.Librarians select l).ToList(); foreach (Librarian l in dbLibrarians) { MLibrarian ml = new MLibrarian(l); peopleList.Add(ml); LibrarianUserIDs.Add(ml.UserID, ml.Password); } //Cardholders var dbCardholders = (from ch in context.Cardholders select ch).ToList(); foreach (Cardholder ch in dbCardholders) { MCardholder mch = new MCardholder(ch); peopleList.Add(mch); CardholderLibraryCardIDs.Add(mch.LibraryCardId, mch); } //Authors var dbAuthors = (from a in context.Authors select a).ToList(); foreach (Author a in dbAuthors) { MAuthor ma = new MAuthor(a); peopleList.Add(ma); } }