Beispiel #1
0
        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.bookCopyService = new BookCopyService(repFactory);
            this.authorService   = new AuthorService(repFactory);
            this.memberService   = new MemberService(repFactory);
            this.loanService     = new LoanService(repFactory);

            //Can we do this another way?
            ShowAllBooks(bookService.All());
            AuthorTabShowAllAuthors(authorService.All());
            BookTabShowAllAuthors(authorService.All());
            MemberTabShowAllMembers(memberService.All());
            BookTabBooksByAuthor(authorService.All());
            ShowAllBooksInComboBox(bookService.All());
            LoanTabShowMembers(memberService.All());
            LoanTabShowCopies(bookCopyService.GetAvailableBookCopies(loanService.All(), bookCopyService.All()));
            ShowAllLoans(loanService.GetAllCurrentLoans(), loanService.GetAllPreviousLoans(), loanService.GetAllOverdueLoans());
            LoanTabShowLoansByMember(memberService.All());

            TEST(loanService.All(), bookCopyService.All());
        }
Beispiel #2
0
 private void RefreshMember(object sender, EventArgs e)
 {
     Show(memberService.All());
     members_combo_box.Items.Clear();
     foreach (Member m in memberService.All())
     {
         members_combo_box.Items.Add(m.ToString());
     }
 }
        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.bookCopyService = new BookCopyService(repFactory);
            this.authorService   = new AuthorService(repFactory);
            this.memberService   = new MemberService(repFactory);
            this.loanService     = new LoanService(repFactory);

            //Adds event listener to bookService.
            this.bookService.Updated     += UpdateBookListEvent;
            this.bookCopyService.Updated += UpdateBookCopyListEvent;
            this.authorService.Updated   += UpdatedAuthorEvent;
            this.memberService.Updated   += UpdateMemberListEvent;
            this.loanService.Updated     += UpdatedLoansEvent;

            UpdateBookList(bookService.All().ToList());
            currentBookDisplay     = bookService.All().ToList();
            currentBookCopyDisplay = new List <BookCopy>();
            currentMemberDisplay   = memberService.All().ToList();
            currentLoanDisplay     = loanService.All().ToList();

            SetAllColors();
            editAuthorTB.AutoCompleteCustomSource.AddRange(authorService.GetAllAuthorNames().ToArray()); //Adds all the current authors to autocomplete list.
        }
Beispiel #4
0
        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);

            bookService         = new BookService(repFactory);
            copyService         = new BookCopyService(repFactory);
            authorService       = new AuthorService(repFactory);
            memberService       = new MemberService(repFactory);
            returnedLoanService = new ReturnedLoanService(repFactory);
            loanService         = new LoanService(repFactory, returnedLoanService);

            ShowAllBooks(bookService.All());
            ShowAllBookCopies(copyService.All());
            ShowAllMembers(memberService.All());
            ShowAllAuthors(authorService.All());
            ShowAllLoans(loanService.All());
            ShowAllAvailableBooks(copyService.All(), loanService.All());
            ShowAllOverDueBooks(copyService.All());

            bookService.Updated                  += BookService_Updated;
            authorService.Updated                += AuthorService_Updated;
            copyService.Updated                  += CopyService_Updated;
            memberService.Updated                += MemberService_Updated;
            loanService.Updated                  += LoanService_Updated;
            backgroundWorker1.DoWork             += BackgroundWorker1_DoWork;
            backgroundWorker1.RunWorkerCompleted += BackgroundWorker1_RunWorkerCompleted;
        }
Beispiel #5
0
        /// <summary>
        /// Constructor of form.
        /// </summary>
        public LibraryForm()
        {
            InitializeComponent();

            // Register derived strategy with seed method
            Database.SetInitializer <LibraryContext>(new LibraryDbInit());

            // 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.copyService   = new BookCopyService(repFactory);
            this.memberService = new MemberService(repFactory);
            this.loanService   = new LoanService(repFactory);

            // All objects that should show up at the start.
            ShowAllAuthors(authorService.All());
            ShowAllBooks(bookService.All(), lbBooks);
            ShowAllBooks(bookService.All(), lbOfBooks);
            ShowAllMembers(memberService.All());
            ShowAllLoans(loanService.All());
            ShowAllCopies(CopyNotOnLoan(), lbCopies);

            // Subscribe to event
            bookService.Updated   += BookService_Updated;
            copyService.Updated   += CopyService_Updated;
            authorService.Updated += AuthorService_Updated;
            memberService.Updated += MemberService_Updated;
            loanService.Updated   += LoanService_Updated;
        }
Beispiel #6
0
        /// <summary>
        /// Constructor
        /// </summary>
        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.memberService   = new MemberService(repFactory);
            this.loanService     = new LoanService(repFactory);
            this.bookCopyService = new BookCopyService(repFactory);
            ShowAllBooks(bookService.All());
            ShowAllAuthors(authorService.All());
            ShowAllMembers(memberService.All());
            ShowActiveLoans(loanService.GetActiveLoans());

            //Observers
            bookService.Updated       += OnChanged;
            authorService.Updated     += OnChanged;
            memberService.Updated     += OnChanged;
            loanService.Updated       += OnChanged;
            bookCopyService.Updated   += OnChanged;
            loanService.Updated       += new EventHandler(OnChangedLoanState);
            rbActive.CheckedChanged   += new EventHandler(OnChangedLoanState);
            rbReturned.CheckedChanged += new EventHandler(OnChangedLoanState);
            rbOverdue.CheckedChanged  += new EventHandler(OnChangedLoanState);
        }
Beispiel #7
0
 private void updateMemberList()
 {
     comboBox1.Items.Clear();
     foreach (Member element in _memberService.All())
     {
         comboBox1.Items.Add(element);
     }
 }
Beispiel #8
0
 private void memberUpdated(object sender, EventArgs e)
 {
     lbCurrentLoans.Items.Clear();
     ShowAllCurrentLoans(loanService.AllBookCopiesOnLoan());
     dropDown_members.SelectedIndex = -1;
     dropDown_members.Items.Clear();
     FillDropDownMembers(memberService.All());
 }
Beispiel #9
0
        public void ListAllMembers(object sender, EventArgs e)
        {
            lbMembers.Items.Clear();

            foreach (Member member in _memberService.All())
            {
                lbMembers.Items.Add(member);
            }
        }
        public MembersForm(MemberService memberService)
        {
            InitializeComponent();

            this.memberService = memberService;

            ShowAllMembers(memberService.All());

            memberService.Updated += memberUpdate;
        }
        public MemberList(MemberService ms, LoanService ls, BookCopyService bk)
        {
            memberService   = ms;
            loanService     = ls;
            bookCopyService = bk;

            InitializeComponent();

            memberService.Updated += MemberService_Updated;
            loanService.Updated   += LoanService_Updated;
            ShowAllMembers(memberService.All());
        }
        public void All_ShouldReturnAnEmptyList_WhenThereAreNoMembers()
        {
            var allMembers = Enumerable.Empty<Member>();
            var memberRepository = Substitute.For<IMemberRepository>();
            memberRepository.GetAll().Returns(allMembers);

            var memberSearchFilterRepository = Substitute.For<IMemberSearchFilterRepository>();
            var searchQueryService = Substitute.For<ISearchQueryService>();

            var memberService = new MemberService(memberRepository, memberSearchFilterRepository, searchQueryService);
            var results = memberService.All();

            CollectionAssert.AreEqual(allMembers, results);
        }
        public void All_ShouldReturnAListOfAllTheMembers_WhenThereAreMembers()
        {
            var allMembers = new[] { member1, member2 };
            var memberRepository = Substitute.For<IMemberRepository>();
            memberRepository.GetAll().Returns(allMembers);

            var memberSearchFilterRepository = Substitute.For<IMemberSearchFilterRepository>();
            var searchQueryService = Substitute.For<ISearchQueryService>();

            var memberService = new MemberService(memberRepository, memberSearchFilterRepository, searchQueryService);
            var results = memberService.All();

            CollectionAssert.AreEqual(allMembers, results);
        }
        public MemberForm(LibraryForm libraryForm)
        {
            InitializeComponent();

            LibraryContext context = new LibraryContext();

            RepositoryFactory repFactory = new RepositoryFactory(context);

            this.memberService = new MemberService(repFactory);
            this.libraryForm   = libraryForm;

            ShowAllMembers(memberService.All());

            memberService.Updated += MemberService_Updated;
        }
        public void All_ShouldReturnAnEmptyList_WhenThereAreNoMembers()
        {
            var allMembers       = Enumerable.Empty <Member>();
            var memberRepository = Substitute.For <IMemberRepository>();

            memberRepository.GetAll().Returns(allMembers);

            var memberSearchFilterRepository = Substitute.For <IMemberSearchFilterRepository>();
            var searchQueryService           = Substitute.For <ISearchQueryService>();

            var memberService = new MemberService(memberRepository, memberSearchFilterRepository, searchQueryService);
            var results       = memberService.All();

            CollectionAssert.AreEqual(allMembers, results);
        }
        public void All_ShouldReturnAListOfAllTheMembers_WhenThereAreMembers()
        {
            var allMembers       = new[] { member1, member2 };
            var memberRepository = Substitute.For <IMemberRepository>();

            memberRepository.GetAll().Returns(allMembers);

            var memberSearchFilterRepository = Substitute.For <IMemberSearchFilterRepository>();
            var searchQueryService           = Substitute.For <ISearchQueryService>();

            var memberService = new MemberService(memberRepository, memberSearchFilterRepository, searchQueryService);
            var results       = memberService.All();

            CollectionAssert.AreEqual(allMembers, results);
        }
Beispiel #17
0
        /// <summary>
        /// "Add new member"-button
        /// </summary>
        private void BtnAddNewMember_Click(object sender, EventArgs e)
        {
            if (textBoxMemberName.Text == "" || textBoxMemberPersonalID.Text == "")
            {
                MessageBox.Show("You need to fill in all member details.", "Error!");
            }
            else if (!textBoxMemberName.Text.All(char.IsLetter))
            {
                MessageBox.Show("Name can not contain numbers.", "Error!");
            }
            else
            {
                DateTime createdDate = DateTime.Today;
                Member   member      = new Member(textBoxMemberPersonalID.Text, textBoxMemberName.Text, createdDate);
                memberService.Add(member);

                MessageBox.Show("You have now added the member: " + textBoxMemberName.Text);
                textBoxMemberName.Clear();
                textBoxMemberPersonalID.Clear();
                MemberTabShowAllMembers(memberService.All());
                LoanTabShowMembers(memberService.All());
                LoanTabShowLoansByMember(memberService.All());
            }
        }
Beispiel #18
0
            public void MembersHasStoredCorrectly()
            {
                var repo = new Mock <IRepository <Member> >();
                var m    = new MemberService(repo.Object);
                var cols = new List <Member>();

                repo.Setup(x => x.Add(It.IsAny <Member>()))
                .Callback <Member>(member =>
                {
                    cols.Add(member);
                });
                repo.Setup(x => x.Query(It.IsAny <Func <Member, bool> >()))
                .Returns(cols.AsQueryable());


                m.CreateMember("M1", "Member1", "Email1");
                m.CreateMember("M2", "Member2", "Email2");

                var members = m.All();

                Assert.Equal(2, members.Count());
            }
Beispiel #19
0
        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;
        }
        public LoanForm(LibraryForm libraryForm)
        {
            InitializeComponent();

            LibraryContext context = new LibraryContext();

            RepositoryFactory repFactory = new RepositoryFactory(context);

            this.bookService     = new BookService(repFactory);
            this.authorService   = new AuthorService(repFactory);
            this.memberService   = new MemberService(repFactory);
            this.bookCopyService = new BookCopyService(repFactory);
            this.loanService     = new LoanService(repFactory);
            this.libraryForm     = libraryForm;

            ShowAllBooks(bookService.All());
            ShowAllBookCopies(bookCopyService.AllAvailableCopies());
            ShowAllMembers(memberService.All());
            ShowAllAuthors(authorService.All());
            ShowAllLoans(loanService.AllCurrentLoans());
            ShowAllReturns(loanService.Returns());

            loanService.Updated += LoanService_Updated;
        }
 private void memberUpdate(object sender, EventArgs e)
 {
     ShowAllMembers(memberService.All());
 }
Beispiel #22
0
 /// <summary>
 /// Observer event
 /// </summary>
 /// <param name="sender">
 /// Object reference
 /// </param>
 /// <param name="e">
 /// Event data
 /// </param>
 private void OnChanged(object sender, EventArgs args)
 {
     ShowAllBooks(bookService.All());
     ShowAllAuthors(authorService.All());
     ShowAllMembers(memberService.All());
 }