Exemplo n.º 1
0
        public ActionResult MakeLoan(MakeLoanViewModel model)
        {
            model.Books = context.Books.ToList();

            if (ModelState.IsValid)
            {
                try
                {
                    Student student = context.Students.First(m => m.IdNumber == model.StudentIdNumber.Trim());
                    Book    book    = context.Books.First(m => m.BookId == model.BookId);
                    Loan    loan    = new Loan
                    {
                        BookId      = model.BookId,
                        StudentId   = student.Id,
                        LibrarianId = User.Identity.GetUserId(),
                        LoanDate    = DateTime.Now,
                        ReturnDate  = null,
                        Fine        = null,
                    };

                    context.Loans.Add(loan);
                    context.SaveChanges();

                    // Successfull
                    TempData["BookId"]    = model.BookId;
                    TempData["StudentId"] = model.StudentIdNumber;
                }
                catch (Exception)
                {
                    ModelState.AddModelError(String.Empty, "The book/student id you have entered is invalid, please try again.");
                }
            }
            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult MakeLoan()
        {
            MakeLoanViewModel model = new MakeLoanViewModel();

            model.Books = context.Books.ToList();
            return(View(model));
        }