Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveStatistics/sources/HeuristicLab.Services.WebApp.Statistics/3.3/WebApi/UserController.cs @ 12516

Last change on this file since 12516 was 12516, checked in by dglaser, 9 years ago

#2388:

HeuristicLab.Services.Hive.DataAccess-3.3:

  • updated daos
  • changed statistics database schema
  • updated HiveStatisticsGenerator

HeuristicLab.Services.WebApp.Statistics-3.3:

  • added jobs, client and user page
File size: 2.1 KB
Line 
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
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      using (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
50    public DT.User GetUser(Guid id) {
51      using (var pm = PersistenceManager) {
52        var dimUserDao = pm.DimUserDao;
53        return pm.UseTransaction(() => {
54          var user = dimUserDao.GetById(id);
55          if (user != null) {
56            return new DT.User {
57              Id = user.UserId,
58              Name = user.Name
59            };
60          }
61          return null;
62        });
63      }
64    }
65  }
66}
Note: See TracBrowser for help on using the repository browser.