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