/grails-app/controllers/general/TipoClienteController.groovy

http://github.com/jdmr/mateo · Groovy · 102 lines · 90 code · 12 blank · 0 comment · 15 complexity · 7c6b0529e002fac25fa1b108099e3bda MD5 · raw file

  1. package general
  2. import grails.converters.JSON
  3. class TipoClienteController {
  4. static allowedMethods = [save: "POST", update: "POST", delete: "POST"]
  5. def index = {
  6. redirect(action: "list", params: params)
  7. }
  8. def list = {
  9. params.max = Math.min(params.max ? params.int('max') : 10, 100)
  10. [tipoClienteInstanceList: TipoCliente.list(params), tipoClienteInstanceTotal: TipoCliente.count()]
  11. }
  12. def create = {
  13. def tipoClienteInstance = new TipoCliente()
  14. tipoClienteInstance.properties = params
  15. return [tipoClienteInstance: tipoClienteInstance]
  16. }
  17. def save = {
  18. def tipoClienteInstance = new TipoCliente(params)
  19. if (tipoClienteInstance.save(flush: true)) {
  20. flash.message = message(code: 'default.created.message', args: [message(code: 'tipoCliente.label', default: 'TipoCliente'), tipoClienteInstance.id])
  21. redirect(action: "show", id: tipoClienteInstance.id)
  22. }
  23. else {
  24. render(view: "create", model: [tipoClienteInstance: tipoClienteInstance])
  25. }
  26. }
  27. def show = {
  28. def tipoClienteInstance = TipoCliente.get(params.id)
  29. if (!tipoClienteInstance) {
  30. flash.message = message(code: 'default.not.found.message', args: [message(code: 'tipoCliente.label', default: 'TipoCliente'), params.id])
  31. redirect(action: "list")
  32. }
  33. else {
  34. [tipoClienteInstance: tipoClienteInstance]
  35. }
  36. }
  37. def edit = {
  38. def tipoClienteInstance = TipoCliente.get(params.id)
  39. if (!tipoClienteInstance) {
  40. flash.message = message(code: 'default.not.found.message', args: [message(code: 'tipoCliente.label', default: 'TipoCliente'), params.id])
  41. redirect(action: "list")
  42. }
  43. else {
  44. return [tipoClienteInstance: tipoClienteInstance]
  45. }
  46. }
  47. def update = {
  48. def tipoClienteInstance = TipoCliente.get(params.id)
  49. if (tipoClienteInstance) {
  50. if (params.version) {
  51. def version = params.version.toLong()
  52. if (tipoClienteInstance.version > version) {
  53. tipoClienteInstance.errors.rejectValue("version", "default.optimistic.locking.failure", [message(code: 'tipoCliente.label', default: 'TipoCliente')] as Object[], "Another user has updated this TipoCliente while you were editing")
  54. render(view: "edit", model: [tipoClienteInstance: tipoClienteInstance])
  55. return
  56. }
  57. }
  58. tipoClienteInstance.properties = params
  59. if (!tipoClienteInstance.hasErrors() && tipoClienteInstance.save(flush: true)) {
  60. flash.message = message(code: 'default.updated.message', args: [message(code: 'tipoCliente.label', default: 'TipoCliente'), tipoClienteInstance.id])
  61. redirect(action: "show", id: tipoClienteInstance.id)
  62. }
  63. else {
  64. render(view: "edit", model: [tipoClienteInstance: tipoClienteInstance])
  65. }
  66. }
  67. else {
  68. flash.message = message(code: 'default.not.found.message', args: [message(code: 'tipoCliente.label', default: 'TipoCliente'), params.id])
  69. redirect(action: "list")
  70. }
  71. }
  72. def delete = {
  73. def tipoClienteInstance = TipoCliente.get(params.id)
  74. if (tipoClienteInstance) {
  75. try {
  76. tipoClienteInstance.delete(flush: true)
  77. flash.message = message(code: 'default.deleted.message', args: [message(code: 'tipoCliente.label', default: 'TipoCliente'), params.id])
  78. redirect(action: "list")
  79. }
  80. catch (org.springframework.dao.DataIntegrityViolationException e) {
  81. flash.message = message(code: 'default.not.deleted.message', args: [message(code: 'tipoCliente.label', default: 'TipoCliente'), params.id])
  82. redirect(action: "show", id: params.id)
  83. }
  84. }
  85. else {
  86. flash.message = message(code: 'default.not.found.message', args: [message(code: 'tipoCliente.label', default: 'TipoCliente'), params.id])
  87. redirect(action: "list")
  88. }
  89. }
  90. }