/grails-app/controllers/general/TipoClienteController.groovy
Groovy | 102 lines | 90 code | 12 blank | 0 comment | 15 complexity | 7c6b0529e002fac25fa1b108099e3bda MD5 | raw file
1package general 2 3import grails.converters.JSON 4 5class TipoClienteController { 6 7 static allowedMethods = [save: "POST", update: "POST", delete: "POST"] 8 9 def index = { 10 redirect(action: "list", params: params) 11 } 12 13 def list = { 14 params.max = Math.min(params.max ? params.int('max') : 10, 100) 15 [tipoClienteInstanceList: TipoCliente.list(params), tipoClienteInstanceTotal: TipoCliente.count()] 16 } 17 18 def create = { 19 def tipoClienteInstance = new TipoCliente() 20 tipoClienteInstance.properties = params 21 return [tipoClienteInstance: tipoClienteInstance] 22 } 23 24 def save = { 25 def tipoClienteInstance = new TipoCliente(params) 26 if (tipoClienteInstance.save(flush: true)) { 27 flash.message = message(code: 'default.created.message', args: [message(code: 'tipoCliente.label', default: 'TipoCliente'), tipoClienteInstance.id]) 28 redirect(action: "show", id: tipoClienteInstance.id) 29 } 30 else { 31 render(view: "create", model: [tipoClienteInstance: tipoClienteInstance]) 32 } 33 } 34 35 def show = { 36 def tipoClienteInstance = TipoCliente.get(params.id) 37 if (!tipoClienteInstance) { 38 flash.message = message(code: 'default.not.found.message', args: [message(code: 'tipoCliente.label', default: 'TipoCliente'), params.id]) 39 redirect(action: "list") 40 } 41 else { 42 [tipoClienteInstance: tipoClienteInstance] 43 } 44 } 45 46 def edit = { 47 def tipoClienteInstance = TipoCliente.get(params.id) 48 if (!tipoClienteInstance) { 49 flash.message = message(code: 'default.not.found.message', args: [message(code: 'tipoCliente.label', default: 'TipoCliente'), params.id]) 50 redirect(action: "list") 51 } 52 else { 53 return [tipoClienteInstance: tipoClienteInstance] 54 } 55 } 56 57 def update = { 58 def tipoClienteInstance = TipoCliente.get(params.id) 59 if (tipoClienteInstance) { 60 if (params.version) { 61 def version = params.version.toLong() 62 if (tipoClienteInstance.version > version) { 63 64 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") 65 render(view: "edit", model: [tipoClienteInstance: tipoClienteInstance]) 66 return 67 } 68 } 69 tipoClienteInstance.properties = params 70 if (!tipoClienteInstance.hasErrors() && tipoClienteInstance.save(flush: true)) { 71 flash.message = message(code: 'default.updated.message', args: [message(code: 'tipoCliente.label', default: 'TipoCliente'), tipoClienteInstance.id]) 72 redirect(action: "show", id: tipoClienteInstance.id) 73 } 74 else { 75 render(view: "edit", model: [tipoClienteInstance: tipoClienteInstance]) 76 } 77 } 78 else { 79 flash.message = message(code: 'default.not.found.message', args: [message(code: 'tipoCliente.label', default: 'TipoCliente'), params.id]) 80 redirect(action: "list") 81 } 82 } 83 84 def delete = { 85 def tipoClienteInstance = TipoCliente.get(params.id) 86 if (tipoClienteInstance) { 87 try { 88 tipoClienteInstance.delete(flush: true) 89 flash.message = message(code: 'default.deleted.message', args: [message(code: 'tipoCliente.label', default: 'TipoCliente'), params.id]) 90 redirect(action: "list") 91 } 92 catch (org.springframework.dao.DataIntegrityViolationException e) { 93 flash.message = message(code: 'default.not.deleted.message', args: [message(code: 'tipoCliente.label', default: 'TipoCliente'), params.id]) 94 redirect(action: "show", id: params.id) 95 } 96 } 97 else { 98 flash.message = message(code: 'default.not.found.message', args: [message(code: 'tipoCliente.label', default: 'TipoCliente'), params.id]) 99 redirect(action: "list") 100 } 101 } 102}