Exemplo n.º 1
0
        //[Route("{controller}/{action}/{loanBooks}")]
        // GET: Loans/Create/loanbooks.int[]
        public IActionResult Create()
        {
            var vm = new CreateLoanVm();

            vm.Members       = new SelectList(memberService.GetAllMembers(), "ID", "Name");
            vm.AvalibleBooks = loanService.ShowAllBooksNotOnLoan();
            return(View(vm));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create(CreateLoanVm vm, int[] loanBooks) //([Bind("ID,TimeOfLoan,TimeToReturnBook,BookCopyID,MemberID")] Loan loan)
        {
            if (loanBooks.Count() <= 0)
            {
                return(RedirectToAction("Create"));
            }
            //This must be changed!!
            //var vm = new CreateLoanVm();
            //vm.TimeOfLoan = new DateTime();
            //vm.TimeToReturnBook =
            if (ModelState.IsValid)
            {
                var loan = new Loan();
                //loan.BookCopyID = vm.BookCopyID;
                loan.MemberID         = vm.MemberID;
                loan.TimeOfLoan       = Convert.ToDateTime(vm.TimeOfLoan);
                loan.TimeToReturnBook = Convert.ToDateTime(vm.TimeToReturnBook);

                //Get books from bookids in loanbooks

                loan.BookCopies = bookService.GetBookCopiesById(loanBooks);


                //Add bookCopyies to loaned out books

                //Save
                loanService.LoanOutBook(loan);

                return(RedirectToAction(nameof(Index)));
                //_context.Add(loan);
                //await _context.SaveChangesAsync();
                //return RedirectToAction(nameof(Index));
            }
            //ViewData["BookCopyID"] = new SelectList(_context.Book, "ID", "ID", loan.BookCopyID);
            //ViewData["MemberID"] = new SelectList(_context.Member, "ID", "ID", loan.MemberID);
            //return View(loan);
            return(RedirectToAction("Error", "Home", ""));
        }