Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2695_dataset-ids/HeuristicLab.Services.WebApp.Statistics/3.3/WebApi/UserController.cs @ 16124

Last change on this file since 16124 was 14185, checked in by swagner, 8 years ago

#2526: Updated year of copyrights in license headers

File size: 2.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Web.Http;
26using HeuristicLab.Services.Hive;
27using HeuristicLab.Services.Hive.DataAccess.Interfaces;
28using DT = HeuristicLab.Services.WebApp.Statistics.WebApi.DataTransfer;
29
30namespace HeuristicLab.Services.WebApp.Statistics.WebApi {
31
32  [Authorize(Roles = HiveRoles.Administrator)]
33  public class UserController : ApiController {
34    private IPersistenceManager PersistenceManager {
35      get { return ServiceLocator.Instance.PersistenceManager; }
36    }
37
38    public IEnumerable<DT.User> GetUsers() {
39      var pm = PersistenceManager;
40      var dimUserDao = pm.DimUserDao;
41      return pm.UseTransaction(() => {
42        return dimUserDao.GetAll().Select(x => new DT.User {
43          Id = x.UserId,
44          Name = x.Name
45        }).ToList();
46      });
47    }
48
49    public DT.UserDetails GetUser(Guid id) {
50      var pm = PersistenceManager;
51      var dimUserDao = pm.DimUserDao;
52      var factTaskDao = pm.FactTaskDao;
53      return pm.UseTransaction(() => {
54        var user = dimUserDao.GetById(id);
55        if (user != null) {
56          return new DT.UserDetails {
57            Id = user.UserId,
58            Name = user.Name,
59            TasksStates = factTaskDao.GetByUserId(id)
60                          .GroupBy(x => x.TaskState)
61                          .Select(x => new DT.TaskStateCount {
62                            State = x.Key.ToString(),
63                            Count = x.Count()
64                          }).ToList()
65          };
66        }
67        return null;
68      });
69    }
70  }
71}
Note: See TracBrowser for help on using the repository browser.