public IActionResult LoanBooks(LoanViewModel model) { var bookIsAvailable = _loanService.CheckIfBookIsAvailable(model.SelectedBook); var userHasTheBook = _loanService.CheckIfUserHasTheBook(model.SelectedBook); var moreThan3 = _loanService.LoanedMoreThan3(); if (!bookIsAvailable) { ModelState.AddModelError("CustomError", "The book isn't available."); return(View(model)); } else if (userHasTheBook) { ModelState.AddModelError("CustomError", "You have already loaned the book ."); return(View(model)); } else if (moreThan3) { ModelState.AddModelError("CustomError", "You have already loaned 3 books, can't have more "); return(View(model)); } _loanService.CreateLoan(model); return(RedirectToAction("LogIn", "User")); }
public IActionResult LoanBooks(LoanViewModel model) { var bookIsAvailable = _loanService.CheckIfBookIsAvailable(model.SelectedBook); var userHasTheBook = _loanService.CheckIfUserHasTheBook(model.SelectedBook); var moreThan5 = _loanService.LoanedMoreThan5(); if (!bookIsAvailable) { ModelState.AddModelError("CustomError", "The book isn't available.Please select another book."); return(View(model)); } else if (userHasTheBook) { ModelState.AddModelError("CustomError", "You have already loaned the book that you have selected.Please select another book."); return(View(model)); } else if (moreThan5) { ModelState.AddModelError("CustomError", "You have already loaned 5 Books. Please return one book so you can loan new book."); return(View(model)); } _loanService.CreateLoan(model); return(RedirectToAction("LogIn", "User")); }