public String likeBook() {
   this.book = services.getBook(isbn);
   String username =
       FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal().getName();
   this.user = services.getUser(username);
   user.getFavorates().add(book);
   services.updateUser(user);
   return "index";
 }
 public boolean likedThisBook() {
   this.book = services.getBook(isbn);
   String username =
       FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal().getName();
   this.user = services.getUser(username);
   for (Book bk : user.getFavorates()) {
     if (bk.getTitle().contentEquals(book.getTitle())) {
       return true;
     }
   }
   return false;
 }
 public String borrowBook() {
   this.book = services.getBook(isbn);
   String username =
       FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal().getName();
   this.user = services.getUser(username);
   Loan loan = new Loan();
   loan.setBook(book);
   loan.setUsers(user);
   loan.setLoanedTime(new Date());
   loan.setReturned(false);
   book.getLoans().add(loan);
   user.getLoans().add(loan);
   book.setAvaliable(false);
   services.updateUser(user);
   services.addBook(book);
   return "index";
 }
 public String addComments() {
   this.book = services.getBook(isbn);
   String username =
       FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal().getName();
   this.user = services.getUser(username);
   Comment com = new Comment();
   com.setComment(comments);
   com.setRating(score);
   com.setUsers(user);
   com.setBook(book);
   book.getComments().add(com);
   user.getComments().add(com);
   // services.addComments(com);
   services.updateUser(user);
   services.addBook(book);
   this.comments = "";
   // FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
   return "index";
 }