Esempio n. 1
0
 /**
  * Withdraws the total basket price if the user has enough money and empties the basket
  *
  * @param customer A custmomer object to perform operations on
  * @param total The total price of all items
  * @return if the purchase was made or not
  */
 public boolean buy(CustomerDTO customer, Integer total) {
   int balance = customer.getBalance();
   if (total > balance) {
     return false;
   } else {
     balance = balance - total;
     customer.setBalance(balance);
     em.merge(customer);
     emptyBasket(customer.getUsername());
     return true;
   }
 }