Created
March 28, 2014 09:37
-
-
Save labra/9828936 to your computer and use it in GitHub Desktop.
Application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package controllers; | |
import models.Country; | |
import play.data.Form; | |
import play.mvc.Controller; | |
import play.mvc.Result; | |
import views.html.*; | |
public class Application extends Controller { | |
public static Result index() { | |
return ok(index.render("Your new application is ready.")); | |
} | |
public static Result saludaEdad(String nombre, Integer edad) { | |
return ok(index.render("Hola " + nombre + ", tienes " + edad + " años")); | |
} | |
public static Result showCountries() { | |
return | |
ok(countries.render(Country.find.all())); | |
} | |
public static Result showCountry(String code) { | |
Country c = Country.find.byId(code); | |
return ok(country.render(c)); | |
} | |
public static Result addCountry() { | |
Country c = countryForm.bindFromRequest().get(); | |
c.save(); | |
return | |
redirect(routes.Application.showCountries()); | |
} | |
public static Result updateCountry(String code) { | |
Country c = Country.find.byId(code); | |
Country updated = countryForm.bindFromRequest().get(); | |
c.name = updated.name; | |
c.save(); | |
return | |
redirect(routes.Application.showCountries()); | |
} | |
public static Result delCountry(String code) { | |
Country c = Country.find.byId(code); | |
c.delete(); | |
return | |
redirect(routes.Application.showCountries()); | |
} | |
static Form<Country> countryForm = Form.form(Country.class); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment