import org.codehaus.groovy.grails.plugins.springsecurity.Secured

class TaskPriorityController extends BaseAppAdminController {
    
    def index = { redirect(action:list,params:params) }

    // the delete, save and update actions only accept POST requests
    static allowedMethods = [delete:'POST', save:'POST', update:'POST']

    def list = {
        params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
        [ taskPriorityInstanceList: TaskPriority.list( params ), taskPriorityInstanceTotal: TaskPriority.count() ]
    }

    def show = {
        def taskPriorityInstance = TaskPriority.get( params.id )

        if(!taskPriorityInstance) {
            flash.message = "TaskPriority not found with id ${params.id}"
            redirect(action:list)
        }
        else { return [ taskPriorityInstance : taskPriorityInstance ] }
    }

    def delete = {
        def taskPriorityInstance = TaskPriority.get( params.id )
        if(taskPriorityInstance) {
            try {
                taskPriorityInstance.delete(flush:true)
                flash.message = "TaskPriority ${params.id} deleted"
                redirect(action:list)
            }
            catch(org.springframework.dao.DataIntegrityViolationException e) {
                flash.message = "TaskPriority ${params.id} could not be deleted"
                redirect(action:show,id:params.id)
            }
        }
        else {
            flash.message = "TaskPriority not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def edit = {
        def taskPriorityInstance = TaskPriority.get( params.id )

        if(!taskPriorityInstance) {
            flash.message = "TaskPriority not found with id ${params.id}"
            redirect(action:list)
        }
        else {
            return [ taskPriorityInstance : taskPriorityInstance ]
        }
    }

    def update = {
        def taskPriorityInstance = TaskPriority.get( params.id )
        if(taskPriorityInstance) {
            if(params.version) {
                def version = params.version.toLong()
                if(taskPriorityInstance.version > version) {
                    
                    taskPriorityInstance.errors.rejectValue("version", "default.optimistic.locking.failure")
                    render(view:'edit',model:[taskPriorityInstance:taskPriorityInstance])
                    return
                }
            }
            taskPriorityInstance.properties = params
            if(!taskPriorityInstance.hasErrors() && taskPriorityInstance.save(flush: true)) {
                flash.message = "TaskPriority ${params.id} updated"
                redirect(action:show,id:taskPriorityInstance.id)
            }
            else {
                render(view:'edit',model:[taskPriorityInstance:taskPriorityInstance])
            }
        }
        else {
            flash.message = "TaskPriority not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def create = {
        def taskPriorityInstance = new TaskPriority()
        taskPriorityInstance.properties = params
        return ['taskPriorityInstance':taskPriorityInstance]
    }

    def save = {
        def taskPriorityInstance = new TaskPriority(params)
        if(!taskPriorityInstance.hasErrors() && taskPriorityInstance.save(flush: true)) {
            flash.message = "TaskPriority ${taskPriorityInstance.id} created"
            redirect(action:show,id:taskPriorityInstance.id)
        }
        else {
            render(view:'create',model:[taskPriorityInstance:taskPriorityInstance])
        }
    }
}
