예제 #1
0
        public async Task <IActionResult> CloseBookLoan(BookLoanData data)
        {
            if (data != null)
            {
                var bookLoan = await _context.BookLoans.SingleAsync(l => l.ID == data.loan.ID);

                var libAccount = await _context.LibAccounts.SingleAsync(l => l.ID == bookLoan.LibAccountID);

                bookLoan.ReturnedDate = data.loan.ReturnedDate;
                // TODO: Change this code to properly decrement the number of books checked out.
                libAccount.ItemsCheckedOut = libAccount.ItemsCheckedOut - 1;
                var returnID = data.loan.LibAccountID;

                try
                {
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Details), new { id = returnID }));
                }
                catch (DbUpdateException ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }
            return(RedirectToAction(nameof(CloseBookLoan), data.loan.ID));
        }
예제 #2
0
        public async Task <IActionResult> CreateBookLoan(BookLoanData data)
        {
            if (ModelState.IsValid)
            {
                var bookLoan   = data.loan;
                var libAccount = await _context.LibAccounts.SingleAsync(l => l.ID == bookLoan.LibAccountID);

                // TODO: Change this code to properly increment the number of books checked out.
                libAccount.ItemsCheckedOut = libAccount.ItemsCheckedOut + 1;

                try
                {
                    _context.BookLoans.Add(bookLoan);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch (DbUpdateException ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }

            var libAccounts = await _context.LibAccounts.Include(l => l.Owner).ToListAsync();

            var returnModel = new BookLoanData
            {
                loan        = data.loan,
                libAccounts = libAccounts,
                bookItem    = data.bookItem
            };

            return(View(returnModel));
        }
예제 #3
0
        public async Task <IActionResult> CreateBookLoan(Guid?id)
        {
            if (id != null)
            {
                var libAccounts = await _context.LibAccounts.Include(l => l.Owner).ToListAsync();

                var newBookItem = await _context.BookItems.SingleOrDefaultAsync(b => b.ID == id);

                var newLoan = new BookLoan
                {
                    BookItemID = newBookItem.ID,
                };

                var bookLoanData = new BookLoanData
                {
                    loan        = newLoan,
                    libAccounts = libAccounts,
                    bookItem    = newBookItem
                };

                return(View(bookLoanData));
            }

            return(RedirectToAction(nameof(Index)));
        }
예제 #4
0
        public async Task <IActionResult> CloseBookLoan(Guid?id)
        {
            if (id != null)
            {
                var bookLoan = await _context.BookLoans.SingleAsync(b => b.ID == id);

                bookLoan.ReturnedDate = DateTime.Now;

                var libAccounts = await _context.LibAccounts.Include(l => l.Owner).ToListAsync();

                var newBookItem = await _context.BookItems.SingleAsync(b => b.ID == bookLoan.BookItemID);

                var bookLoanData = new BookLoanData
                {
                    loan     = bookLoan,
                    bookItem = newBookItem,
                };

                return(View(bookLoanData));
            }
            return(RedirectToAction(nameof(Index)));
        }