private void bookCopyUpdated(object sender, EventArgs e) { lbCopies.Items.Clear(); IEnumerable <Loan> allCurrentLoans = loanService.AllBookCopiesOnLoan(); IEnumerable <BookCopy> bookCopiesNotOnLoan = bookCopyService.AllExcept(allCurrentLoans); ShowAllAvailableCopies(bookCopiesNotOnLoan); }
public LibraryForm() { InitializeComponent(); // We create only one context in our application, which gets shared among repositories LibraryContext context = new LibraryContext(); // We use a factory object that will create the repositories as they are needed, it also makes // sure all the repositories created use the same context. RepositoryFactory repFactory = new RepositoryFactory(context); this.bookService = new BookService(repFactory); this.authorService = new AuthorService(repFactory); this.bookCopyService = new BookCopyService(repFactory); this.loanService = new LoanService(repFactory); this.memberService = new MemberService(repFactory); //Set all starting values. ShowAllBooks(bookService.All()); ShowAllBookCopies(bookCopyService.All()); IEnumerable <Loan> allCurrentLoans = loanService.AllBookCopiesOnLoan(); ShowAllCurrentLoans(allCurrentLoans); IEnumerable <BookCopy> bookCopiesNotOnLoan = bookCopyService.AllExcept(allCurrentLoans); ShowAllAvailableCopies(bookCopiesNotOnLoan); FillDropDownMembers(memberService.All().OrderBy(m => m.Name)); FillDropDownAuthors(authorService.All().OrderBy(a => a.Name)); //Subscribe to the Updated() event in each service to update the GUI when changes in the database has been made. bookService.Updated += bookUpdated; bookCopyService.Updated += bookCopyUpdated; authorService.Updated += authorUpdated; memberService.Updated += memberUpdated; loanService.Updated += loanUpdated; }