1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2015 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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using System.Web.Http;
|
---|
26 | using HeuristicLab.Services.Hive;
|
---|
27 | using HeuristicLab.Services.Hive.DataAccess.Interfaces;
|
---|
28 | using DT = HeuristicLab.Services.WebApp.Statistics.WebApi.DataTransfer;
|
---|
29 |
|
---|
30 | namespace 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 | } |
---|