Index: /branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/AssignedProjectResourceDao.cs
===================================================================
--- /branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/AssignedProjectResourceDao.cs	(revision 15627)
+++ /branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/AssignedProjectResourceDao.cs	(revision 15628)
@@ -107,4 +107,5 @@
         WHERE ProjectId IN ({0})
     ";
+    // tested
     private const string CheckProjectGrantedForResourcesQueryString = @"
     WITH rtree AS
@@ -125,9 +126,9 @@
 	    FROM rtree, [AssignedProjectResource] apr
 	    WHERE rtree.ParentResourceId = apr.ResourceId
-	    AND apr.ProjectId = {0}
+	    AND apr.ProjectId = '{0}'
 	    UNION
 	    SELECT apr.ResourceId
 	    FROM [AssignedProjectResource] apr
-	    WHERE apr.ProjectId = {0}
+	    WHERE apr.ProjectId = '{0}'
     )
     ";
@@ -146,10 +147,10 @@
       WHERE rtree.ParentResourceId = apr.ResourceId
       AND rtree.ResourceId = res.ResourceId
-      AND apr.ProjectId = {0}
+      AND apr.ProjectId = '{0}'
       UNION
       SELECT res.*
       FROM [AssignedProjectResource] apr, [Resource] res
       WHERE apr.ResourceId = res.ResourceId
-      AND apr.ProjectId = {0}
+      AND apr.ProjectId = '{0}'
     ";
     private const string GetAllGrantedResourceIdsByProjectIdQueryString = @"
@@ -166,9 +167,9 @@
     FROM rtree, [AssignedProjectResource] apr
     WHERE rtree.ParentResourceId = apr.ResourceId
-    AND apr.ProjectId = {0}
+    AND apr.ProjectId = '{0}'
     UNION
     SELECT apr.ResourceId
     FROM [AssignedProjectResource] apr
-    WHERE apr.ProjectId = {0}
+    WHERE apr.ProjectId = '{0}'
     ";
     private const string GetAllGrantedResourceIdsOfOwnedParentProjectsQueryString = @"
Index: /branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/ProjectPermissionDao.cs
===================================================================
--- /branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/ProjectPermissionDao.cs	(revision 15627)
+++ /branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/ProjectPermissionDao.cs	(revision 15628)
@@ -74,5 +74,5 @@
     private const string DeleteByProjectIdAndGrantedUserIdsQueryString = @"
       DELETE FROM [ProjectPermission]
-      WHERE ProjectId = '{0}'
+      WHERE ProjectId = {0}
       AND GrantedUserId IN ({1});
     ";
@@ -85,5 +85,5 @@
       SELECT COUNT(pp.ProjectId)
       FROM [ProjectPermission] pp
-      WHERE pp.ProjectId = {0}
+      WHERE pp.ProjectId = '{0}'
       AND pp.GrantedUserId IN ({1})
     ";
Index: /branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/TaskDao.cs
===================================================================
--- /branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/TaskDao.cs	(revision 15627)
+++ /branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/TaskDao.cs	(revision 15628)
@@ -64,5 +64,5 @@
     /// <param name="finished">if true, all parent task which have FinishWhenChildJobsFinished=true are returned, otherwise only FinishWhenChildJobsFinished=false are returned</param>
     /// <returns></returns>
-    public IEnumerable<Task> GetParentTasks(IEnumerable<Guid> resourceIds, int count, bool finished) {
+    public IEnumerable<Task> GetParentTasks_Old(IEnumerable<Guid> resourceIds, int count, bool finished) {
       var query = from ar in AssignedTaskResourceTable
                   where resourceIds.Contains(ar.ResourceId)
@@ -83,4 +83,27 @@
     }
 
+    /// <summary>
+    /// returns all parent tasks which are waiting for their child tasks to finish
+    /// </summary>
+    /// <param name="resourceIds">list of resourceids which for which the task should be valid</param>
+    /// <param name="count">maximum number of task to return</param>
+    /// <param name="finished">if true, all parent task which have FinishWhenChildJobsFinished=true are returned, otherwise only FinishWhenChildJobsFinished=false are returned</param>
+    /// <returns></returns>
+    public IEnumerable<Task> GetParentTasks(IEnumerable<Guid> resourceIds, int count, bool finished) {
+      var query = from t in Table
+                  where t.State == TaskState.Waiting
+                    && t.IsParentTask
+                    && !t.Job.AssignedJobResources.Select(x => x.ResourceId).Except(resourceIds).Any()
+                    && t.FinishWhenChildJobsFinished == finished
+                    && t.ChildJobs.Any()
+                    && t.ChildJobs.All(x =>
+                      x.State == TaskState.Finished
+                      || x.State == TaskState.Aborted
+                      || x.State == TaskState.Failed)
+                  orderby t.Priority descending
+                  select t;
+      return count == 0 ? query.ToArray() : query.Take(count).ToArray();
+    }
+
     public void UpdateExecutionTime(Guid taskId, double executionTime) {
       DataContext.ExecuteCommand(UpdateExecutionTimeQuery, executionTime, DateTime.Now, taskId);
@@ -96,4 +119,13 @@
 
     #region String queries
+    private const string GetParentTasksQueryString = @"
+      SELECT t.* FROM [Task] t, [Job] j, [AssignedJobResource] ajr
+        WHERE t.IsParentTask = 1
+        AND t.TaskState = 'Waiting'
+        AND t.JobId = j.JobId
+        AND j.JobId = ajr.JobId
+        AND t.FinishWhenChildJobsFinished = 1
+        ... TODO (not necessary)
+    ";
     private const string GetWaitingTasksQueryString = @"
       WITH pr AS (
Index: /branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/Converter.cs
===================================================================
--- /branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/Converter.cs	(revision 15627)
+++ /branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/Converter.cs	(revision 15628)
@@ -143,4 +143,25 @@
     #endregion
 
+    #region AssignedJobResource
+    public static DT.AssignedJobResource ToDto(this DA.AssignedJobResource source) {
+      if (source == null) return null;
+      return new DT.AssignedJobResource {
+        JobId = source.JobId,
+        ResourceId = source.ResourceId
+      };
+    }
+    public static DA.AssignedJobResource ToEntity(this DT.AssignedJobResource source) {
+      if (source == null) return null;
+      var result = new DA.AssignedJobResource();
+      source.CopyToEntity(result);
+      return result;
+    }
+    public static void CopyToEntity(this DT.AssignedJobResource source, DA.AssignedJobResource target) {
+      if ((source == null) || (target == null)) return;
+      target.JobId = source.JobId;
+      target.ResourceId = source.ResourceId;
+    }
+    #endregion
+
     #region JobPermission
     public static DT.JobPermission ToDto(this DA.JobPermission source) {
Index: /branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/DataTransfer/AssignedJobResource.cs
===================================================================
--- /branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/DataTransfer/AssignedJobResource.cs	(revision 15628)
+++ /branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/DataTransfer/AssignedJobResource.cs	(revision 15628)
@@ -0,0 +1,36 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Runtime.Serialization;
+
+namespace HeuristicLab.Services.Hive.DataTransfer {
+  [DataContract]
+  [Serializable]
+  public class AssignedJobResource : HiveItem {
+    [DataMember]
+    public Guid JobId { get; set; }
+    [DataMember]
+    public Guid ResourceId { get; set; }
+
+    public AssignedJobResource() { }
+  }
+}
Index: /branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HeuristicLab.Services.Hive-3.3.csproj
===================================================================
--- /branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HeuristicLab.Services.Hive-3.3.csproj	(revision 15627)
+++ /branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HeuristicLab.Services.Hive-3.3.csproj	(revision 15628)
@@ -119,4 +119,5 @@
   <ItemGroup>
     <Compile Include="Converter.cs" />
+    <Compile Include="DataTransfer\AssignedJobResource.cs" />
     <Compile Include="DataTransfer\AssignedProjectResource.cs" />
     <Compile Include="DataTransfer\Command.cs" />
Index: /branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HiveService.cs
===================================================================
--- /branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HiveService.cs	(revision 15627)
+++ /branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HiveService.cs	(revision 15628)
@@ -69,5 +69,5 @@
 
     #region Task Methods
-    [Obsolete]
+    
     public Guid AddTask(DT.Task task, DT.TaskData taskData, IEnumerable<Guid> resourceIds) {
       RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
@@ -397,5 +397,4 @@
     }
 
-    [Obsolete]
     public Guid AddJob(DT.Job jobDto) {
       RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
@@ -497,14 +496,26 @@
           jobDto.CopyToEntity(job);
 
-          // remove former resource assignments
-          job.AssignedJobResources.Clear();
-          // add resource assignments
-          job.AssignedJobResources.AddRange(resourceIds.Select(
-            x => new DA.AssignedJobResource {
-              ResourceId = x
-            }));
-
           if (!exists) {
+            // add resource assignments
+            job.AssignedJobResources.AddRange(resourceIds.Select(
+              x => new DA.AssignedJobResource {
+                ResourceId = x
+              }));
             jobDao.Save(job);
+          } else {
+            var addedJobResourceIds = resourceIds.Except(job.AssignedJobResources.Select(x => x.ResourceId));
+            var removedJobResourceIds = job.AssignedJobResources.Select(x => x.ResourceId).Except(resourceIds);
+            
+            // remove resource assignments
+            foreach(var rid in removedJobResourceIds) {
+              var ajr = job.AssignedJobResources.Where(x => x.ResourceId == rid).SingleOrDefault();
+              if (ajr != null) job.AssignedJobResources.Remove(ajr);
+            }
+
+            // add resource assignments
+            job.AssignedJobResources.AddRange(addedJobResourceIds.Select(
+              x => new DA.AssignedJobResource {
+                ResourceId = x
+              }));
           }
           pm.SubmitChanges();
@@ -520,9 +531,24 @@
         var jobDao = pm.JobDao;
         pm.UseTransaction(() => {
-          // child tasks will be deleted by db-trigger
+          // not necessary anymore: child tasks will be deleted by db-trigger
+          // now: tasks are deleted by jobId
           // entries in AssignedJobResource will be deleted by foreign key clause CASCADE ON DELETE
           jobDao.Delete(jobId);
           pm.SubmitChanges();
         });
+      }
+    }
+
+    public IEnumerable<DT.AssignedJobResource> GetAssignedResourcesForJob(Guid jobId) {
+      RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
+      AuthorizationManager.AuthorizeForJob(jobId, DT.Permission.Full);
+      var pm = PersistenceManager;
+      var assignedJobResourceDao = pm.AssignedJobResourceDao;
+      using (new PerformanceLogger("GetAssignedResourcesForProject")) {
+        return pm.UseTransaction(() =>
+          assignedJobResourceDao.GetByJobId(jobId)
+          .Select(x => x.ToDto())
+          .ToList()
+        );
       }
     }
@@ -747,5 +773,5 @@
 
     public DT.Project GetProject(Guid projectId) {
-      RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator);
+      RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
       var pm = PersistenceManager;
       using (new PerformanceLogger("GetProject")) {
@@ -758,9 +784,9 @@
     public IEnumerable<DT.Project> GetProjects() {
       RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
-      bool isAdministrator = RoleVerifier.IsInRole(HiveRoles.Administrator);
+      //bool isAdministrator = RoleVerifier.IsInRole(HiveRoles.Administrator);
       var pm = PersistenceManager;
       using (new PerformanceLogger("GetProjects")) {
         var projectDao = pm.ProjectDao;
-        var projectPermissionDao = pm.ProjectPermissionDao;
+        //var projectPermissionDao = pm.ProjectPermissionDao;
         var currentUserId = UserManager.CurrentUserId;
         var userAndGroupIds = new List<Guid> { currentUserId };
@@ -820,4 +846,6 @@
         pm.UseTransaction(() => {
           var project = projectDao.GetById(projectId);
+          if (project == null) return;
+          //if (project.ProjectPermissions == null) project.ProjectPermissions = new System.Data.Linq.EntitySet<DA.ProjectPermission>();
           var projectPermissions = project.ProjectPermissions.Select(x => x.GrantedUserId);
           var addedPermissions = grantedUserIds.Except(projectPermissions);
@@ -1037,4 +1065,18 @@
     public IEnumerable<DT.AssignedProjectResource> GetAssignedResourcesForProject(Guid projectId) {
       RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
+      AuthorizationManager.AuthorizeUserForProjectUse(UserManager.CurrentUserId, projectId);
+      var pm = PersistenceManager;
+      using (new PerformanceLogger("GetAssignedResourcesForProject")) {
+        var assignedProjectResourceDao = pm.AssignedProjectResourceDao;
+        return pm.UseTransaction(() => assignedProjectResourceDao.GetByProjectId(projectId)
+          .Select(x => x.ToDto())
+          .ToList()
+        );
+      }
+    }
+
+    public IEnumerable<DT.AssignedProjectResource> GetAssignedResourcesForProjectAdministration(Guid projectId) {
+      RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client);
+      AuthorizationManager.AuthorizeForProjectAdministration(projectId);
       var pm = PersistenceManager;
       using (new PerformanceLogger("GetAssignedResourcesForProject")) {
Index: /branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/Manager/AuthorizationManager.cs
===================================================================
--- /branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/Manager/AuthorizationManager.cs	(revision 15627)
+++ /branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/Manager/AuthorizationManager.cs	(revision 15628)
@@ -96,9 +96,5 @@
       var projectDao = pm.ProjectDao;
       pm.UseTransaction(() => {
-        // check if project exists (not necessary)
-        var project = projectDao.GetById(projectId);
-        if (project == null) throw new SecurityException(NOT_AUTHORIZED_USERPROJECT);
-
-        var projectBranch = projectDao.GetCurrentAndParentProjectsById(projectId);
+        var projectBranch = projectDao.GetCurrentAndParentProjectsById(projectId).ToList();
         if(!projectBranch.Select(x => x.OwnerUserId).Contains(currentUserId)
             && !RoleVerifier.IsInRole(HiveRoles.Administrator)) {
@@ -129,5 +125,5 @@
 
         // check if user is owner of a parent project
-        var projectBranch = projectDao.GetParentProjectsById(projectId);
+        var projectBranch = projectDao.GetParentProjectsById(projectId).ToList();
         if (!projectBranch.Select(x => x.OwnerUserId).Contains(currentUserId)
             && !RoleVerifier.IsInRole(HiveRoles.Administrator)) {
@@ -136,5 +132,5 @@
 
         // check if the all argument resourceIds are among the assigned resources of the owned projects
-        var grantedResourceIds = assignedProjectResourceDao.GetAllGrantedResourceIdsOfOwnedParentProjects(projectId, currentUserId);
+        var grantedResourceIds = assignedProjectResourceDao.GetAllGrantedResourceIdsOfOwnedParentProjects(projectId, currentUserId).ToList();
         if(resourceIds.Except(grantedResourceIds).Any()) {
           throw new SecurityException(NOT_AUTHORIZED_USERRESOURCE);
Index: /branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/ServiceContracts/IHiveService.cs
===================================================================
--- /branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/ServiceContracts/IHiveService.cs	(revision 15627)
+++ /branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/ServiceContracts/IHiveService.cs	(revision 15628)
@@ -31,6 +31,9 @@
   public interface IHiveService {
     #region Task Methods
-    [OperationContract]
-    Guid AddTask(Task task, TaskData taskData, IEnumerable<Guid> resourceIds);
+    //[OperationContract]
+    //Guid AddTask(Task task, TaskData taskData, IEnumerable<Guid> resourceIds);
+
+    [OperationContract]
+    Guid AddTask(Task task, TaskData taskData);
 
     [OperationContract]
@@ -77,12 +80,21 @@
     IEnumerable<Job> GetJobs();
 
-    [OperationContract]
-    Guid AddJob(Job jobDto);
-
-    [OperationContract]
-    void UpdateJob(Job jobDto);
+    //[OperationContract]
+    //Guid AddJob(Job jobDto);
+
+    [OperationContract]
+    Guid AddJob(Job jobDto, IEnumerable<Guid> resourceIds);
+
+    //[OperationContract]
+    //void UpdateJob(Job jobDto);
+
+    [OperationContract]
+    void UpdateJob(Job jobDto, IEnumerable<Guid> resourceIds);
 
     [OperationContract]
     void DeleteJob(Guid JobId);
+
+    [OperationContract]
+    IEnumerable<AssignedJobResource> GetAssignedResourcesForJob(Guid jobId);
     #endregion
 
@@ -178,4 +190,7 @@
     [OperationContract]
     IEnumerable<AssignedProjectResource> GetAssignedResourcesForProject(Guid projectId);
+
+    [OperationContract]
+    IEnumerable<AssignedProjectResource> GetAssignedResourcesForProjectAdministration(Guid projectId);
     #endregion
 
