Пример #1
0
        // GET: /Borrows/
        public ActionResult Index()
        {
            ViewBag.Borrowers = _context.Borrows.Where(b => b.IsReturned == false).ToList().Count();
            var processBorrowers = new ProcessLendingViewModel(_context);

            return(View(processBorrowers.GetLendingDetails()));
        }
Пример #2
0
        public ActionResult ReturnBook(string borrowerId, string bookIsbn)
        {
            // Check and see if overdue
            var checkOverdue = Overdue.Details(_context, borrowerId, bookIsbn);
            // Get borrowers details
            var borrow = _context.Borrows.Single(b => b.BorrowerId == borrowerId && b.Isbn == bookIsbn);


            if (checkOverdue.IsOverdue)
            {
                var overdue = new OverdueViewModel {
                    Borrow = borrow, OverdueDetails = checkOverdue
                };
                return(View("ReturnBook", overdue));
            }

            // Set the return date and flag the book as returned.
            borrow.ReturnDate = DateTime.Now;
            borrow.IsReturned = true;

            var book = _context.Books.Single(b => b.Isbn == bookIsbn);

            // Add the number of books in stock.
            book.NumberInStock++;

            _context.SaveChanges();

            // Initialize the Lending List
            var processBorrowers = new ProcessLendingViewModel(_context);

            ViewBag.Borrowers = _context.Borrows.Where(b => b.IsReturned == false).ToList().Count();
            return(View("Index", processBorrowers.GetLendingDetails()));
        }
Пример #3
0
        public ActionResult OverdueReturnBook(OverdueViewModel model)
        {
            var processBorrowers = new ProcessLendingViewModel(_context);


            if (model.AlreadyPaid)
            {
                var book   = _context.Books.Single(b => b.Isbn == model.Borrow.Isbn);
                var borrow = _context.Borrows.Single(b => b.Id == model.Borrow.Id);

                // Set the return date and flag the book as returned.
                borrow.ReturnDate = DateTime.Now;
                borrow.IsReturned = true;

                // Add the number of books in stock.
                book.NumberInStock++;

                _context.SaveChanges();

                // Initialize the Lending List
                ViewBag.Borrowers = _context.Borrows.Where(b => b.IsReturned == false).ToList().Count();

                return(View("Index", processBorrowers.GetLendingDetails()));
            }

            // Initialize the Lending List
            ViewBag.Borrowers = _context.Borrows.Where(b => b.IsReturned == false).ToList().Count();
            return(View("Index", processBorrowers.GetLendingDetails()));
        }
Пример #4
0
        public ActionResult AddRecord(BorrowViewModel borrowViewModel)
        {
            // Check if borrower has books in his/her possession.
            var borrowersId = borrowViewModel.Borrow.BorrowerId;
            var isbn        = borrowViewModel.Borrow.Isbn;
            var checkBook   = _context.Borrows
                              .SingleOrDefault(b => b.IsReturned == false && b.BorrowerId == borrowersId && b.Isbn == isbn);

            if (checkBook != null)
            {
                var model = new BorrowViewModel((byte)borrowViewModel.MyBooks.Length)
                {
                    BorrowTypes = _context.BorrowTypes.ToList()
                };

                var message =
                    $@"Borrower has {isbn} book in his/her possession already.";
                ModelState.AddModelError(string.Empty, message);
                return(View("AddRecord", model));
            }

            var validator = _context.Borrows
                            .Where(b => b.BorrowerId == borrowViewModel.Borrow.BorrowerId && b.IsReturned == false);
            var settings = _context.Settings.Single(s => s.Id == 1);

            if (validator.Count() >= settings.MaximumNumberOfBooksPerBorrow)
            {
                var model = new BorrowViewModel((byte)borrowViewModel.MyBooks.Length)
                {
                    BorrowTypes = _context.BorrowTypes.ToList()
                };

                var message =
                    string.Format(
                        @"Maximum number of books exceeded, the borrower has {0} books in his/her possession already.",
                        validator.Count());
                ModelState.AddModelError(string.Empty, message);
                return(View("AddRecord", model));
            }


            Booking.AddBooking(borrowViewModel, _context);

            var processBorrowers = new ProcessLendingViewModel(_context);

            ViewBag.Borrowers = _context.Borrows.Where(b => b.IsReturned == false).ToList().Count();

            return(View("Index", processBorrowers.GetLendingDetails()));
        }
Пример #5
0
        public ActionResult Extend(ExtendViewModel model)
        {
            // Arrange
            var borrow = _context.Borrows.Single(b => b.BorrowerId == model.BorrowerId && b.Isbn == model.Isbn);

            borrow.BorrowDate = borrow.BorrowDate.AddDays(model.NumberOfDays);

            // Save extension date to database
            _context.SaveChanges();

            // Initialize the Lending List
            ViewBag.Borrowers = _context.Borrows.Where(b => b.IsReturned == false).ToList().Count();
            var processBorrowers = new ProcessLendingViewModel(_context);

            return(View("Index", processBorrowers.GetLendingDetails()));
        }