Ignore:
Timestamp:
01/23/18 15:42:13 (3 years ago)
Author:
jzenisek
Message:

#2839

  • worked on UpdateJob(..)
  • adapted permission and assignment handling methods
  • adpated dbml of HiveDataContext using the designer (added delete rules and onNull-handling)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HiveService.cs

    r15630 r15643  
    507507          } else {
    508508            var addedJobResourceIds = resourceIds.Except(job.AssignedJobResources.Select(x => x.ResourceId));
    509             var removedJobResourceIds = job.AssignedJobResources.Select(x => x.ResourceId).Except(resourceIds);
     509            var removedJobResourceIds = job.AssignedJobResources
     510              .Select(x => x.ResourceId)
     511              .Except(resourceIds)
     512              .ToArray();
    510513           
    511514            // remove resource assignments
     
    855858      AuthorizationManager.AuthorizeForProjectAdministration(projectId);
    856859      var pm = PersistenceManager;
    857       using (new PerformanceLogger("GrantProjectPermissions")) {
     860      using (new PerformanceLogger("SaveProjectPermissions")) {
    858861        var projectDao = pm.ProjectDao;
    859862        var projectPermissionDao = pm.ProjectPermissionDao;
     
    863866          var project = projectDao.GetById(projectId);
    864867          if (project == null) return;
    865           //if (project.ProjectPermissions == null) project.ProjectPermissions = new System.Data.Linq.EntitySet<DA.ProjectPermission>();
    866           var projectPermissions = project.ProjectPermissions.Select(x => x.GrantedUserId);
    867           var addedPermissions = grantedUserIds.Except(projectPermissions);
     868          var projectPermissions = project.ProjectPermissions.Select(x => x.GrantedUserId).ToArray();
     869          //var addedPermissions = grantedUserIds.Except(projectPermissions);
    868870          var removedPermissions = projectPermissions.Except(grantedUserIds);
    869871
     
    874876          } else {
    875877            assignedJobResourceDao.DeleteByProjectIdAndUserIds(project.ProjectId, removedPermissions);
    876             foreach(var item in project.ProjectPermissions.ToList().Where(x => removedPermissions.Contains(x.GrantedUserId))) {
     878            foreach(var item in project.ProjectPermissions
     879              .Where(x => removedPermissions.Contains(x.GrantedUserId))
     880              .ToList()) {
    877881              project.ProjectPermissions.Remove(item);
    878882            }
     
    907911                p.ProjectPermissions.Clear();
    908912              } else {
    909                 foreach(var item in p.ProjectPermissions.ToList().Where(x => removedPermissions.Contains(x.GrantedUserId))) {
     913                foreach(var item in p.ProjectPermissions
     914                  .Where(x => removedPermissions.Contains(x.GrantedUserId))
     915                  .ToList()) {
    910916                  p.ProjectPermissions.Remove(item);
    911917                }
     
    979985      AuthorizationManager.AuthorizeForProjectResourceAdministration(projectId, resourceIds);
    980986      var pm = PersistenceManager;
    981       using (new PerformanceLogger("AssignProjectResources")) {
     987      using (new PerformanceLogger("SaveProjectResourceAssignments")) {
    982988        var projectDao = pm.ProjectDao;
    983989        var assignedProjectResourceDao = pm.AssignedProjectResourceDao;
     
    985991        pm.UseTransaction(() => {
    986992          var project = projectDao.GetById(projectId);
    987           var assignedResources = project.AssignedProjectResources.Select(x => x.ResourceId);
    988           var addedAssignments = resourceIds.Except(assignedResources);
     993          var assignedResources = project.AssignedProjectResources.Select(x => x.ResourceId).ToArray();
     994          //var addedAssignments = resourceIds.Except(assignedResources);
    989995          var removedAssignments = assignedResources.Except(resourceIds);
    990996
     
    992998          if (reassign) {
    993999            assignedJobResourceDao.DeleteByProjectId(project.ProjectId);
    994             //assignedProjectResourceDao.DeleteByProjectIds(new List<Guid> { projectId });
    9951000            project.AssignedProjectResources.Clear();
    9961001          } else {
    9971002            assignedJobResourceDao.DeleteByProjectIdAndResourceIds(projectId, removedAssignments);
    998             //assignedProjectResourceDao.DeleteByProjectIdAndResourceIds(projectId, removedAssignments);
    999             foreach (var item in project.AssignedProjectResources.ToList().Where(x => removedAssignments.Contains(x.ResourceId))) {
     1003            foreach (var item in project.AssignedProjectResources
     1004              .Where(x => removedAssignments.Contains(x.ResourceId))
     1005              .ToList()) {
    10001006              project.AssignedProjectResources.Remove(item);
    10011007            }
     
    10301036              } else {
    10311037                //assignedProjectResourceDao.DeleteByProjectIdAndResourceIds(p.ProjectId, removedAssignments);
    1032                 foreach (var item in p.AssignedProjectResources.ToList().Where(x => removedAssignments.Contains(x.ResourceId))) {
     1038                //for(int i = p.AssignedProjectResources.Count -1; i >= 0; i--) {
     1039                //  if(removedAssignments.Contains(p.AssignedProjectResources[i].ResourceId)) {
     1040                //    p.AssignedProjectResources.RemoveAt(i);
     1041                //  }
     1042                //}
     1043                foreach (var item in p.AssignedProjectResources
     1044                  .Where(x => removedAssignments.Contains(x.ResourceId))
     1045                  .ToList()) {
    10331046                  p.AssignedProjectResources.Remove(item);
    10341047                }
Note: See TracChangeset for help on using the changeset viewer.