Index: branches/HiveStatistics/sources/HeuristicLab.Services.WebApp.Statistics/3.3/WebApi/GroupController.cs
===================================================================
--- branches/HiveStatistics/sources/HeuristicLab.Services.WebApp.Statistics/3.3/WebApi/GroupController.cs	(revision 12562)
+++ branches/HiveStatistics/sources/HeuristicLab.Services.WebApp.Statistics/3.3/WebApi/GroupController.cs	(revision 12858)
@@ -35,38 +35,84 @@
 
     public DT.GroupDetails GetGroupDetails(Guid id) {
-      using (var pm = PersistenceManager) {
-        var dimClientDao = pm.DimClientDao;
-        var factClientInfoDao = pm.FactClientInfoDao;
-        var factTaskDao = pm.FactTaskDao;
-        return pm.UseTransaction(() => {
-          var clientTimeData = factClientInfoDao.GetAll()
-            .Join(dimClientDao.GetAll(), x => x.ClientId, y => y.Id, (x, y) => new {
-              y.ResourceGroupId,
-              x.IdleTime,
-              x.OfflineTime,
-              x.UnavailableTime
-            })
-            .Where(x => x.ResourceGroupId == id)
-            .GroupBy(x => x.ResourceGroupId)
-            .Select(x => new {
-              TotalIdleTime = x.Sum(y => y.IdleTime),
-              TotalOfflineTime = x.Sum(y => y.OfflineTime),
-              TotalUnavailableTime = x.Sum(y => y.UnavailableTime)
-            })
-            .FirstOrDefault();
+      var pm = PersistenceManager;
+      var dimClientDao = pm.DimClientDao;
+      var factClientInfoDao = pm.FactClientInfoDao;
+      var factTaskDao = pm.FactTaskDao;
+      return pm.UseTransaction(() => {
+        var clientTimeData = factClientInfoDao.GetAll()
+          .Join(dimClientDao.GetAll(), x => x.ClientId, y => y.Id, (x, y) => new {
+            y.ResourceGroupId,
+            x.IdleTime,
+            x.OfflineTime,
+            x.UnavailableTime
+          })
+          .Where(x => x.ResourceGroupId == id)
+          .GroupBy(x => x.ResourceGroupId)
+          .Select(x => new {
+            TotalIdleTime = x.Sum(y => y.IdleTime),
+            TotalOfflineTime = x.Sum(y => y.OfflineTime),
+            TotalUnavailableTime = x.Sum(y => y.UnavailableTime)
+          })
+          .FirstOrDefault();
 
-          var taskTimeData = factTaskDao.GetByGroupId(id)
-            .Select(x => new {
-              id,
-              x.CalculatingTime,
-              x.TransferTime
-            })
-            .GroupBy(x => x.id)
-            .Select(x => new {
-              CalculatingTime = x.Sum(y => y.CalculatingTime),
-              TransferTime = x.Sum(y => y.TransferTime)
-            })
-            .FirstOrDefault();
-          return (from client in dimClientDao.GetActiveClients().Where(x => x.ResourceGroupId == id)
+        var taskTimeData = factTaskDao.GetByGroupId(id)
+          .Select(x => new {
+            id,
+            x.CalculatingTime,
+            x.TransferTime
+          })
+          .GroupBy(x => x.id)
+          .Select(x => new {
+            CalculatingTime = x.Sum(y => y.CalculatingTime),
+            TransferTime = x.Sum(y => y.TransferTime)
+          })
+          .FirstOrDefault();
+        return (from client in dimClientDao.GetActiveClients().Where(x => x.ResourceGroupId == id)
+                join info in factClientInfoDao.GetAll()
+                  on client.Id equals info.ClientId into clientInfoJoin
+                from clientInfo in clientInfoJoin.OrderByDescending(x => x.Time).Take(1)
+                let offline = (clientInfo.SlaveState == DA.SlaveState.Offline)
+                select new {
+                  ResourceGroupId = client.ResourceGroupId,
+                  GroupName = client.GroupName,
+                  TotalCores = clientInfo.NumTotalCores,
+                  UsedCores = offline ? 0 : clientInfo.NumUsedCores,
+                  TotalMemory = clientInfo.TotalMemory,
+                  UsedMemory = offline ? 0 : clientInfo.UsedMemory,
+                  CpuUtilization = offline ? 0 : clientInfo.CpuUtilization,
+                  SlaveState = clientInfo.SlaveState
+                })
+          .GroupBy(x => new { x.ResourceGroupId, x.GroupName })
+          .Select(x => new DT.GroupDetails {
+            Id = id,
+            Name = x.Key.GroupName,
+            TotalClients = x.Count(),
+            OnlineClients = x.Count(y => y.SlaveState != DA.SlaveState.Offline),
+            TotalCores = x.Sum(y => y.TotalCores),
+            UsedCores = x.Sum(y => y.UsedCores),
+            TotalMemory = x.Sum(y => y.TotalMemory),
+            UsedMemory = x.Sum(y => y.UsedMemory),
+            TotalCpuUtilization = x.Average(y => (double?)y.CpuUtilization) ?? 0.0,
+            ActiveCpuUtilization = x.Where(y => y.SlaveState != DA.SlaveState.Offline).Average(y => (double?)y.CpuUtilization) ?? 0.0,
+            TotalUnavailableTime = clientTimeData != null ? clientTimeData.TotalUnavailableTime : 0,
+            TotalCalculatingTime = taskTimeData != null ? taskTimeData.CalculatingTime : 0,
+            TotalIdleTime = clientTimeData != null ? clientTimeData.TotalIdleTime : 0,
+            TotalOfflineTime = clientTimeData != null ? clientTimeData.TotalOfflineTime : 0,
+            TotalTransferringTime = taskTimeData != null ? taskTimeData.TransferTime : 0,
+            TasksStates = factTaskDao.GetByGroupId(id)
+                                  .GroupBy(y => y.TaskState)
+                                  .Select(y => new DT.TaskStateCount {
+                                    State = y.Key.ToString(),
+                                    Count = y.Count()
+                                  }).ToList()
+          }).FirstOrDefault();
+      });
+    }
+
+    public DT.GroupPage GetGroups(int page, int size) {
+      var pm = PersistenceManager;
+      var dimClientDao = pm.DimClientDao;
+      var factClientInfoDao = pm.FactClientInfoDao;
+      var data = (from client in dimClientDao.GetActiveClients()
                   join info in factClientInfoDao.GetAll()
                     on client.Id equals info.ClientId into clientInfoJoin
@@ -75,5 +121,4 @@
                   select new {
                     ResourceGroupId = client.ResourceGroupId,
-                    GroupName = client.GroupName,
                     TotalCores = clientInfo.NumTotalCores,
                     UsedCores = offline ? 0 : clientInfo.NumUsedCores,
@@ -82,85 +127,38 @@
                     CpuUtilization = offline ? 0 : clientInfo.CpuUtilization,
                     SlaveState = clientInfo.SlaveState
-                  })
-            .GroupBy(x => new { x.ResourceGroupId, x.GroupName })
-            .Select(x => new DT.GroupDetails {
-              Id = id,
-              Name = x.Key.GroupName,
-              TotalClients = x.Count(),
-              OnlineClients = x.Count(y => y.SlaveState != DA.SlaveState.Offline),
-              TotalCores = x.Sum(y => y.TotalCores),
-              UsedCores = x.Sum(y => y.UsedCores),
-              TotalMemory = x.Sum(y => y.TotalMemory),
-              UsedMemory = x.Sum(y => y.UsedMemory),
-              TotalCpuUtilization = x.Average(y => (double?)y.CpuUtilization) ?? 0.0,
-              ActiveCpuUtilization = x.Where(y => y.SlaveState != DA.SlaveState.Offline).Average(y => (double?)y.CpuUtilization) ?? 0.0,
-              TotalUnavailableTime = clientTimeData != null ? clientTimeData.TotalUnavailableTime : 0,
-              TotalCalculatingTime = taskTimeData != null ? taskTimeData.CalculatingTime : 0,
-              TotalIdleTime = clientTimeData != null ? clientTimeData.TotalIdleTime : 0,
-              TotalOfflineTime = clientTimeData != null ? clientTimeData.TotalOfflineTime : 0,
-              TotalTransferringTime = taskTimeData != null ? taskTimeData.TransferTime : 0,
-              TasksStates = factTaskDao.GetByGroupId(id)
-                                    .GroupBy(y => y.TaskState)
-                                    .Select(y => new DT.TaskStateCount {
-                                      State = y.Key.ToString(),
-                                      Count = y.Count()
-                                    }).ToList()
-            }).FirstOrDefault();
+                  }).GroupBy(x => x.ResourceGroupId).Select(x => new {
+                    GroupId = x.Key,
+                    TotalClients = x.Count(),
+                    OnlineClients = x.Count(y => y.SlaveState != DA.SlaveState.Offline),
+                    TotalCores = x.Sum(y => y.TotalCores),
+                    UsedCores = x.Sum(y => y.UsedCores),
+                    TotalMemory = x.Sum(y => y.TotalMemory),
+                    UsedMemory = x.Sum(y => y.UsedMemory),
+                    CpuUtilization = x.Where(y => y.SlaveState != DA.SlaveState.Offline).Average(y => (double?)y.CpuUtilization) ?? 0.0
+                  });
+      var query = dimClientDao.GetAll()
+        .GroupBy(x => new { x.ResourceGroupId, x.GroupName })
+        .Select(x => new {
+          Id = x.Key.ResourceGroupId ?? default(Guid),
+          Name = x.Key.GroupName
         });
-      }
-    }
-
-    public DT.GroupPage GetGroups(int page, int size) {
-      using (var pm = PersistenceManager) {
-        var dimClientDao = pm.DimClientDao;
-        var factClientInfoDao = pm.FactClientInfoDao;
-        var data = (from client in dimClientDao.GetActiveClients()
-                    join info in factClientInfoDao.GetAll()
-                      on client.Id equals info.ClientId into clientInfoJoin
-                    from clientInfo in clientInfoJoin.OrderByDescending(x => x.Time).Take(1)
-                    let offline = (clientInfo.SlaveState == DA.SlaveState.Offline)
-                    select new {
-                      ResourceGroupId = client.ResourceGroupId,
-                      TotalCores = clientInfo.NumTotalCores,
-                      UsedCores = offline ? 0 : clientInfo.NumUsedCores,
-                      TotalMemory = clientInfo.TotalMemory,
-                      UsedMemory = offline ? 0 : clientInfo.UsedMemory,
-                      CpuUtilization = offline ? 0 : clientInfo.CpuUtilization,
-                      SlaveState = clientInfo.SlaveState
-                    }).GroupBy(x => x.ResourceGroupId).Select(x => new {
-                      GroupId = x.Key,
-                      TotalClients = x.Count(),
-                      OnlineClients = x.Count(y => y.SlaveState != DA.SlaveState.Offline),
-                      TotalCores = x.Sum(y => y.TotalCores),
-                      UsedCores = x.Sum(y => y.UsedCores),
-                      TotalMemory = x.Sum(y => y.TotalMemory),
-                      UsedMemory = x.Sum(y => y.UsedMemory),
-                      CpuUtilization = x.Where(y => y.SlaveState != DA.SlaveState.Offline).Average(y => (double?)y.CpuUtilization) ?? 0.0
-                    });
-        var query = dimClientDao.GetAll()
-          .GroupBy(x => new { x.ResourceGroupId, x.GroupName })
-          .Select(x => new {
-            Id = x.Key.ResourceGroupId ?? default(Guid),
-            Name = x.Key.GroupName
-          });
-        return pm.UseTransaction(() => new DT.GroupPage {
-          TotalGroups = query.Count(),
-          Groups = query
-          .Skip((page - 1) * size)
-          .Take(size)
-          .Join(data, x => x.Id, y => y.GroupId,
-            (group, info) => new DT.Group {
-              Id = group.Id,
-              Name = group.Name,
-              TotalClients = info.TotalClients,
-              OnlineClients = info.OnlineClients,
-              TotalCores = info.TotalCores,
-              UsedCores = info.UsedCores,
-              TotalMemory = info.TotalMemory,
-              UsedMemory = info.UsedMemory,
-              CpuUtilization = info.CpuUtilization
-            }).ToList()
-        });
-      }
+      return pm.UseTransaction(() => new DT.GroupPage {
+        TotalGroups = query.Count(),
+        Groups = query
+        .Skip((page - 1) * size)
+        .Take(size)
+        .Join(data, x => x.Id, y => y.GroupId,
+          (group, info) => new DT.Group {
+            Id = group.Id,
+            Name = group.Name,
+            TotalClients = info.TotalClients,
+            OnlineClients = info.OnlineClients,
+            TotalCores = info.TotalCores,
+            UsedCores = info.UsedCores,
+            TotalMemory = info.TotalMemory,
+            UsedMemory = info.UsedMemory,
+            CpuUtilization = info.CpuUtilization
+          }).ToList()
+      });
     }
   }
