コード例 #1
0
        public void GetTheRightNumberOfCopiesTest(int selectedBook, int i, int expected)
        {
            DateTime date1  = DateTime.Today;
            DateTime date   = date1.AddYears(1);
            Book     book   = SelectBookById.ValidateSelectedBook(selectedBook, i);
            int      result = CheckLoansToCopies.Book(book.Id, expected, date1, date);

            Assert.AreEqual(expected, result);
        }
コード例 #2
0
        public IActionResult Create(string memberId, string bookId, DateTime startDate, DateTime endDate)
        {
            ObjectId memberOId = new ObjectId(memberId);
            ObjectId bookOId   = new ObjectId(bookId);

            Book book = BookRepository.GetBookById(bookOId);

            int copiesRemaining = CheckLoansToCopies.Book(book.Id, book.NumberOfCopies, startDate, endDate);

            if (copiesRemaining > 0)
            {
                Loan loan = CreateLoan(memberOId, book.Id, startDate, endDate);
                BookLoanRepository.InsertBookLoan(loan);
            }
            else if (copiesRemaining <= 0)
            {
                string        errorMessage  = "No availiable copies at that date. Please try an other one";
                BookLoanModel bookLoanModel = new BookLoanModel();
                bookLoanModel.ErrorMessage = errorMessage;
                return(View(bookLoanModel));
            }

            return(Redirect("/BookLoan"));
        }