Index: trunk/grails-app/controllers/AssignedGroupDetailedController.groovy
===================================================================
--- trunk/grails-app/controllers/AssignedGroupDetailedController.groovy	(revision 242)
+++ trunk/grails-app/controllers/AssignedGroupDetailedController.groovy	(revision 247)
@@ -3,5 +3,10 @@
 class AssignedGroupDetailedController extends BaseController {
 
-    def index = { redirect(action:list,params:params) }
+    def assignedGroupService
+
+    def index = {
+        flash.message = g.message(code: "assignedGroup.task.not.found")
+        redirect(controller:"taskDetailed", action:"search")
+    }
 
     // the delete, save and update actions only accept POST requests
@@ -9,99 +14,104 @@
 
     def list = {
-        params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
-        [ assignedGroupInstanceList: AssignedGroup.list( params ), assignedGroupInstanceTotal: AssignedGroup.count() ]
+            def result = assignedGroupService.list(params)
+            if(!result.error) {
+                return [ assignedGroupInstanceList: result.assignedGroupInstanceList,
+                                assignedGroupInstanceTotal: result.assignedGroupInstanceTotal ]
+            }
+
+            flash.message = g.message(code: result.error.code, args: result.error.args)
+            redirect( url: resource(dir:'') )
     }
 
     def show = {
-        def assignedGroupInstance = AssignedGroup.get( params.id )
+        def result = assignedGroupService.show(params)
 
-        if(!assignedGroupInstance) {
-            flash.message = "AssignedGroup not found with id ${params.id}"
-            redirect(action:list)
-        }
-        else { return [ assignedGroupInstance : assignedGroupInstance ] }
+        if(!result.error)
+            return [ assignedGroupInstance: result.assignedGroupInstance ]
+
+        flash.message = g.message(code: result.error.code, args: result.error.args)
+
+        if(params.task?.id)
+            redirect(controller:"taskDetailed", action:"show", id: params.task.id)
+
+        redirect(controller:"taskDetailed", action:"search")
     }
 
     def delete = {
-        def assignedGroupInstance = AssignedGroup.get( params.id )
-        if(assignedGroupInstance) {
-            try {
-                def taskId = assignedGroupInstance.task.id
-                assignedGroupInstance.delete()
-                flash.message = "AssignedGroup ${params.id} deleted"
-                redirect(controller:"taskDetailed", action:"show", id: taskId)
-            }
-            catch(org.springframework.dao.DataIntegrityViolationException e) {
-                flash.message = "AssignedGroup ${params.id} could not be deleted"
-                redirect(action:show,id:params.id)
-            }
+        def result = assignedGroupService.delete(params)
+
+        if(!result.error) {
+            flash.message = g.message(code: "default.delete.success", args: ["AssignedGroup", params.id])
+            redirect(controller:"taskDetailed", action:"show", id: params.task?.id)
+            return
         }
-        else {
-            flash.message = "AssignedGroup not found with id ${params.id}"
-            redirect(action:list)
+
+        flash.message = g.message(code: result.error.code, args: result.error.args)
+
+        if(result.error.code == "default.not.found") {
+            redirect(controller:"taskDetailed", action:"show", id: params.task?.id)
+            return
         }
+
+        redirect(action:show, id: params.id)
     }
 
     def edit = {
-        def assignedGroupInstance = AssignedGroup.get( params.id )
+        def result = assignedGroupService.edit(params)
 
-        if(!assignedGroupInstance) {
-            flash.message = "AssignedGroup not found with id ${params.id}"
-            redirect(action:list)
-        }
-        else {
-            return [ assignedGroupInstance : assignedGroupInstance ]
-        }
+        if(!result.error)
+            return [ assignedGroupInstance : result.assignedGroupInstance ]
+
+        flash.message = g.message(code: result.error.code, args: result.error.args)
+
+        redirect(controller:"taskDetailed", action:"show", id: params.task?.id)
+
     }
 
     def update = {
-        def assignedGroupInstance = AssignedGroup.get( params.id )
-        if(assignedGroupInstance) {
-            if(params.version) {
-                def version = params.version.toLong()
-                if(assignedGroupInstance.version > version) {
+        def result = assignedGroupService.update(params)
 
-                    assignedGroupInstance.errors.rejectValue("version", "assignedGroup.optimistic.locking.failure", "Another user has updated this AssignedGroup while you were editing.")
-                    render(view:'edit',model:[assignedGroupInstance:assignedGroupInstance])
-                    return
-                }
-            }
-            assignedGroupInstance.properties = params
-            if(!assignedGroupInstance.hasErrors() && assignedGroupInstance.save(flush: true)) {
-                flash.message = "AssignedGroup ${params.id} updated"
-                redirect(action:show,id:assignedGroupInstance.id)
-            }
-            else {
-                render(view:'edit',model:[assignedGroupInstance:assignedGroupInstance])
-            }
+        if(!result.error) {
+            flash.message = g.message(code: "default.update.success", args: ["AssignedGroup", params.id])
+            redirect(action:show, id: params.id)
+            return
         }
-        else {
-            flash.message = "AssignedGroup not found with id ${params.id}"
-            redirect(action:edit,id:params.id)
+
+        if(result.error.code == "default.not.found") {
+            flash.message = g.message(code: result.error.code, args: result.error.args)
+            redirect(controller:"taskDetailed", action:"show", id: params.task?.id)
+            return
         }
+
+        render(view:'edit', model:[assignedGroupInstance: result.assignedGroupInstance.attach()])
     }
 
     def create = {
-        if(!params.task?.id) {
-            flash.message = "Please select a task and then 'Add Assigned Group'"
+        def result = assignedGroupService.create(params)
+
+        if(!result.error)
+            return [assignedGroupInstance: result.assignedGroupInstance]
+
+        if(result.error.code == "assignedGroup.task.not.found") {
+            flash.message = g.message(code: result.error.code, args: result.error.args)
             redirect(controller: "taskDetailed", action: "search")
+            return
         }
-        else {
-            def assignedGroupInstance = new AssignedGroup()
-            assignedGroupInstance.properties = params
-            return ['assignedGroupInstance':assignedGroupInstance]
-        }
+
+        flash.message = g.message(code: result.error.code, args: result.error.args)
+        redirect(controller:"taskDetailed", action:"show", id: params.task?.id)
     }
 
     def save = {
-        def assignedGroupInstance = new AssignedGroup(params)
+        def result = assignedGroupService.save(params)
 
-        if(!assignedGroupInstance.hasErrors() && assignedGroupInstance.save(flush: true)) {
-            flash.message = "AssignedGroup ${assignedGroupInstance.id} created"
-            redirect(controller:"taskDetailed", action:"show", id: params.task.id)
+        if(!result.error) {
+            flash.message = g.message(code: "default.create.success", args: ["AssignedGroup", result.assignedGroupInstance.id])
+            redirect(controller:"taskDetailed", action:"show", id: result.assignedGroupInstance.task.id)
+            return
         }
-        else {
-            render(view:'create',model:[assignedGroupInstance:assignedGroupInstance])
-        }
+
+        render(view:'edit', model:[assignedGroupInstance: result.assignedGroupInstance])
     }
+
 }
