Ignore:
Timestamp:
Feb 10, 2010, 5:09:22 AM (15 years ago)
Author:
gav
Message:

Move Asset delete to a service method and configure cascade deletion checks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/AssetDetailedController.groovy

    r334 r350  
    232232    */
    233233    def delete = {
    234         def assetInstance = Asset.get( params.id )
    235         if(assetInstance) {
    236             try {
    237                 assetInstance.delete(flush:true)
    238                 flash.message = "Asset ${params.id} deleted"
    239                 redirect(action:search)
    240             }
    241             catch(org.springframework.dao.DataIntegrityViolationException e) {
    242                 flash.message = "Asset ${params.id} could not be deleted"
    243                 redirect(action:show,id:params.id)
    244             }
    245         }
    246         else {
    247             flash.message = "Asset not found with id ${params.id}"
    248             redirect(action:search)
    249         }
     234        def result = assetService.delete(params)
     235
     236        if(!result.error) {
     237            flash.message = g.message(code: "default.delete.success", args: ["Asset", params.id])
     238            redirect(action:search)
     239            return
     240        }
     241
     242        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
     243
     244        if(result.error.code == "default.not.found") {
     245            redirect(action:search)
     246            return
     247        }
     248
     249        redirect(action:show, id: params.id)
    250250    }
    251251
Note: See TracChangeset for help on using the changeset viewer.