public static Result toggleStock() {
User user = UserManager.getCurrentLoggedInUser();
if (user != null && user.isAdmin()) {
boolean success = true;
GameManager gm = new GameManager();
int rs = 1;
Form<StockForm> stockForm = Form.form(StockForm.class).bindFromRequest();
if (stockForm.hasErrors()) {
success = false;
} else {
try {
rs = gm.flipEnableStock(stockForm.get().ticker);
if (rs == 2) {
success = false;
}
} catch (Exception e) {
success = false; //can not add into database
}
}
if (success) {
return ok(management.render(gm.getStockList(), "stock successfully " + (rs == 1 ? "enabled" : "disabled"), "stockTab")); //return message indicating success
} else {
return ok(management.render(gm.getStockList(), "Failed enable/disable stock", "stockTab"));//not success in general
}
} else {
return ok("You don't have acess to Admin DashBoard!");
}