PageRenderTime 263ms CodeModel.GetById 141ms app.highlight 9ms RepoModel.GetById 112ms app.codeStats 0ms

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

http://github.com/jdmr/mateo
Groovy | 102 lines | 90 code | 12 blank | 0 comment | 15 complexity | 5f67ba016449c14f2bb432dfdde44c41 MD5 | raw file
  1package general
  2
  3import grails.converters.JSON
  4
  5class ClienteController {
  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		[clienteInstanceList: Cliente.list(params), clienteInstanceTotal: Cliente.count()]
 16	}
 17
 18    def create = {
 19        def clienteInstance = new Cliente()
 20        clienteInstance.properties = params
 21        return [clienteInstance: clienteInstance]
 22    }
 23
 24    def save = {
 25        def clienteInstance = new Cliente(params)
 26        if (clienteInstance.save(flush: true)) {
 27            flash.message = message(code: 'default.created.message', args: [message(code: 'cliente.label', default: 'Cliente'), clienteInstance.id])
 28            redirect(action: "show", id: clienteInstance.id)
 29        }
 30        else {
 31            render(view: "create", model: [clienteInstance: clienteInstance])
 32        }
 33    }
 34
 35    def show = {
 36        def clienteInstance = Cliente.get(params.id)
 37        if (!clienteInstance) {
 38            flash.message = message(code: 'default.not.found.message', args: [message(code: 'cliente.label', default: 'Cliente'), params.id])
 39            redirect(action: "list")
 40        }
 41        else {
 42            [clienteInstance: clienteInstance]
 43        }
 44    }
 45
 46    def edit = {
 47        def clienteInstance = Cliente.get(params.id)
 48        if (!clienteInstance) {
 49            flash.message = message(code: 'default.not.found.message', args: [message(code: 'cliente.label', default: 'Cliente'), params.id])
 50            redirect(action: "list")
 51        }
 52        else {
 53            return [clienteInstance: clienteInstance]
 54        }
 55    }
 56
 57    def update = {
 58        def clienteInstance = Cliente.get(params.id)
 59        if (clienteInstance) {
 60            if (params.version) {
 61                def version = params.version.toLong()
 62                if (clienteInstance.version > version) {
 63                    
 64                    clienteInstance.errors.rejectValue("version", "default.optimistic.locking.failure", [message(code: 'cliente.label', default: 'Cliente')] as Object[], "Another user has updated this Cliente while you were editing")
 65                    render(view: "edit", model: [clienteInstance: clienteInstance])
 66                    return
 67                }
 68            }
 69            clienteInstance.properties = params
 70            if (!clienteInstance.hasErrors() && clienteInstance.save(flush: true)) {
 71                flash.message = message(code: 'default.updated.message', args: [message(code: 'cliente.label', default: 'Cliente'), clienteInstance.id])
 72                redirect(action: "show", id: clienteInstance.id)
 73            }
 74            else {
 75                render(view: "edit", model: [clienteInstance: clienteInstance])
 76            }
 77        }
 78        else {
 79            flash.message = message(code: 'default.not.found.message', args: [message(code: 'cliente.label', default: 'Cliente'), params.id])
 80            redirect(action: "list")
 81        }
 82    }
 83
 84    def delete = {
 85        def clienteInstance = Cliente.get(params.id)
 86        if (clienteInstance) {
 87            try {
 88                clienteInstance.delete(flush: true)
 89                flash.message = message(code: 'default.deleted.message', args: [message(code: 'cliente.label', default: 'Cliente'), 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: 'cliente.label', default: 'Cliente'), 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: 'cliente.label', default: 'Cliente'), params.id])
 99            redirect(action: "list")
100        }
101    }
102}