PageRenderTime 344ms CodeModel.GetById 151ms app.highlight 10ms RepoModel.GetById 181ms app.codeStats 0ms

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

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