/** * Sets the banned property of a user to true * * @param username The name of the user * @return if the customer was found */ public Boolean ban(String username) { CustomerDTO customer = em.find(Customer.class, username); if (customer == null) { return false; } else { customer.setBanned(true); em.merge(customer); return true; } }
/** * 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; } }