예제 #1
0
        /// <summary>
        /// Add new loan
        /// </summary>
        /// <param name="member"></param>
        /// <param name="bookCopy"></param>
        /// <param name="AlreadyExpiredLoan">Register as already expired loan for testing purposes</param>
        public void Add(Member member, BookCopy bookCopy, bool alreadyExpiredLoan)
        {
            if (bookCopy != null && bookCopy.CurrentLoan != null)
            {
                throw new ValidationException("This book copy is already on loan");
            }

            Loan loan = new Loan()
            {
                TimeOfLoan = DateTime.Now,
                DueDate = alreadyExpiredLoan ? DateTime.Now.AddDays(-15) : DateTime.Now.AddDays(15),
                Member = member,
                BookCopy = bookCopy
            };

            ValidationResult error = ObjectValidator.Validate(loan);

            if (error != null)
            {
                throw new ValidationException(error.ErrorMessage);
            }
            else
            {
                _loanRepository.Add(loan);
                OnUpdated(new EventArgs());
            }
        }
예제 #2
0
 public Member(int pNummer, string firstName, string lastName, Loan _loan)
 {
     this.MemberId = generateNewId();
     this.Pnumber = pNummer;
     this.FirstName = firstName;
     this.LastName = lastName;
     this.loan = _loan;
 }
예제 #3
0
        public async Task<Loan> LoanBook(int userId, int bookId, int days)
        {
            var b = await _bookService.Details(bookId);
            var u = await _userService.Details(userId);

            if (b == null || u == null) throw null;

            var currentDate = DateTime.UtcNow;
            var loan = new Loan()
            {
                Book = b,
                User = u,
                LoanStart = currentDate,
                LoanEnd = currentDate.AddDays(days)
            };
            _libraryContext.Loans.Add(loan);
            int rowsSaved = await _libraryContext.SaveChangesAsync();
            return loan;
        }
예제 #4
0
        public void CreateLibrary()
        {
            Author AlexDumas = new Author()
            {
                Name = "Alexander Dumas",
                books = new List<Book>()
            };

            Author JamesJoyce = new Author()
            {
                Name = "James Joyce",
                books = new List<Book>()
            };

            string description = "The story of Edmund Dantes, self-styled Count of Monte Cristo, is told with consummate skill.";
            string descriptionTwo = "This is a description";
            string descriptionThree = "It was the best of times, it was the worst of times";

            string title = "The Count of Monte Cristo";
            string titleTwo = "The Count of Monte Blisto";
            string titleThree = "Ulysses";

            long isbnOne = 9781435132115;
            long isbnTwo = 9781435132114;
            long isbnThree = 9789100146238;

            int nrOfCopyOne = 7;
            int nrOfCopyTwo = 6;

            Book monteCristo = new Book(AlexDumas, title, description, isbnOne, nrOfCopyOne);
            Book monteBlisto = new Book(AlexDumas, titleTwo, descriptionTwo, isbnTwo, nrOfCopyTwo);
            Book ulysses = new Book(JamesJoyce, titleThree, descriptionThree, isbnThree, nrOfCopyOne);

            AlexDumas.books.Add(monteCristo);
            AlexDumas.books.Add(monteBlisto);
            JamesJoyce.books.Add(ulysses);

            _authorService.Add(AlexDumas);
            _authorService.Add(JamesJoyce);
            //_bookService.Add(monteCristo);

            Member Love = new Member()
            {
                Pnumber = 920217,
                Name = "Love",
                loans = new List<Loan>()
            };

            _memberService.Add(Love);

            BookCopy bCopy = _bookCopyService.Find(monteCristo.Id);

            Loan loanTest = new Loan(bCopy, Love);
            _loanService.Add(loanTest);
        }
예제 #5
0
        /// <summary>
        /// Return loan an calculate fee if loan is returned past it's due date
        /// </summary>
        /// <param name="loan"></param>
        /// <param name="fee">The fee for passing the loan due date</param>
        public void Return(Loan loan, out double fee)
        {
            fee = 0;

            if (loan != null && loan.TimeOfReturn == null)
            {
                // 10 SEK fee per day after due date
                if (DateTime.Now > loan.DueDate)
                    fee = (DateTime.Now - loan.DueDate).Days * 10;

                loan.TimeOfReturn = DateTime.Now;
                OnUpdated(new EventArgs());
            }
            else
                throw new InvalidOperationException("The book you are trying to return has already been returned");
        }
예제 #6
0
        /// <summary>
        /// Event method for the loan submit button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void loanSelectedButton_Click(object sender, EventArgs e)
        {
            try
            {
                iscorrectofrmat(mtxtbxSSNR1);
                string memberSocialSecNr = mtxtbxSSNR1.Text;
                int bookId = Convert.ToInt16(searchListView.SelectedItems[0].SubItems[0].Text);
                Member theMember;
                BookCopy theCopy;

                //fetch bookcopy and member from repos and catch exceptions to throw specific exceptions
                try
                {
                    var bookCopy = bookCopyService.All().Where(b => b.Book.Id == bookId && b.IsLoaned == false).First();
                    theCopy = bookCopy;
                }
                catch (InvalidOperationException)
                {
                    throw new NoCopyAvailableException();
                }
                try
                {
                    var member = memberService.All().Where(m => m.SocialSecurityNr == memberSocialSecNr).First();
                    theMember = member;
                }
                catch (InvalidOperationException)
                {
                    throw new NoMemberFoundException();
                }

                //create a new loan
                Loan newLoan = new Loan { BookCopy = theCopy, Member = theMember, TimeofLoan = DateTime.Today.Date, ToReturn = DateTime.Today.AddDays(15).Date, Returned = null };
                //Add the loan to the repo
                loanService.Add(newLoan);
                theCopy.IsLoaned = true;
                bookCopyService.Edit(theCopy);
            }
            catch (ArgumentOutOfRangeException)
            {
                MessageBox.Show("Select a book to loan");
            }
            catch (NoMemberFoundException)
            {
                MessageBox.Show("Member not found");
            }
            catch (NoCopyAvailableException)
            {
                MessageBox.Show(searchListView.SelectedItems[0].SubItems[2].Text + " is not available at this moment.");

            }
            catch (InvalidSSNRException)
            {
                MessageBox.Show(mtxtbxSSNR1.Text + " is not a valid Social security number, please enter a social scurity number by the form YYMMDD-XXXX");
            }
        }
예제 #7
0
        private void grd_Members_Loans_SelectionChanged(object sender, EventArgs e)
        {
            // Enable/disable buttons depending on selected row
            if (grd_Members_Loans.SelectedRows.Count > 0)
            {
                _selectedMemberLoan = GetSelectedMemberLoan();

                // The selected loan is active and not returned yet - enable return button
                if (_selectedMemberLoan != null && _selectedMemberLoan.TimeOfReturn == null)
                    btn_Members_ReturnLoan.Enabled = true;

                // The selected loan is returned - disable return button
                else if (_selectedMemberLoan != null && _selectedMemberLoan.TimeOfReturn != null)
                    btn_Members_ReturnLoan.Enabled = false;

                // No loan selected
                else
                    btn_Members_ReturnLoan.Enabled = false;
            }
            else
            {
                _selectedMemberLoan = null;

                btn_Members_ReturnLoan.Enabled = false;
            }
        }
예제 #8
0
 public void RemoveLoan(Loan item, string name)
 {
     _memberRepository.RemoveLoan(item, name);
 }
예제 #9
0
 public void Remove(Loan item)
 {
 }
예제 #10
0
 public void Edit(Loan item)
 {
 }
예제 #11
0
 public void Add(Loan item)
 {
 }
예제 #12
0
 public string ReturnLoan(Loan loan)
 {
     OnUpdated(this, new EventArgs());
     return _loanRepository.ReturnLoan(loan);
 }
예제 #13
0
 public void Remove(Loan item)
 {
     _loanRepository.Remove(item);
 }
예제 #14
0
 public void ModLoan(Loan item)
 {
     OnUpdated(this, new EventArgs());
     _loanRepository.ModLoan(item);
 }
예제 #15
0
 public void Add(Loan item)
 {
     _loanRepository.Add(item);
 }