Free cookie consent management tool by TermsFeed Policy Generator

source: branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/ViewModels/User/UserViewModel.cs @ 15870

Last change on this file since 15870 was 13862, checked in by jlodewyc, 9 years ago

#2582 Start angular OKB manager, data loaded

File size: 4.8 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 HeuristicLab.Clients.Hive.WebJobManager.Models;
23using HeuristicLab.Clients.Hive.WebJobManager.Services.Imports;
24using System;
25using System.Collections.Generic;
26using System.Linq;
27
28namespace HeuristicLab.Clients.Hive.WebJobManager.ViewModels.User
29{
30    /// <summary>
31    /// ViewModel containing User/Group/Role data
32    /// </summary>
33    public class UserViewModel : MasterVM
34    {
35        public AccessAdministrationClient accessClient { get; set; }
36        public List<Access.User> users { get; set; }
37        public List<Access.Role> roles { get; set; }
38        public List<Access.UserGroup> ugroups { get; set; }
39
40        public Access.User SelectedUser { get; set; }
41        public List<Access.UserGroup> SelectedUserSubscriptions { get; set; }
42        public List<Access.Role> SelectedUserRoles { get; set; }
43        public Access.UserGroup SelectedGroup { get; set; }
44        public List<Access.UserGroupBase> SelectedGroupMembers { get; set; }
45        public Access.Role SelectedRole { get; set; }
46        public List<Access.UserGroupBase> SelectedRoleEnrolled { get; set; }
47
48        /// <summary>
49        /// Initialize viewmodel and set up connection
50        /// </summary>
51        /// <param name="ac">AccessAdminClient for connection</param>
52        public UserViewModel(AccessAdministrationClient ac, HiveWebUser hwu) : base(hwu)
53        {
54            users = new List<Access.User>();
55            accessClient = ac;
56
57            SelectedUser = new Access.User();
58            SelectedGroup = new Access.UserGroup();
59            SelectedRole = new Access.Role();
60            SelectedRole.Name = "";
61
62            SelectedUserSubscriptions = new List<Access.UserGroup>();
63            SelectedUserRoles = new List<Access.Role>();
64            SelectedGroupMembers = new List<Access.UserGroupBase>();
65           
66           
67        }
68        /// <summary>
69        /// Refreshes Users, Groups and Roles
70        /// </summary>
71        /// <returns></returns>
72        public UserViewModel refreshAll()
73        {
74            refreshUsers();
75            refreshGroups();
76            refreshRoles();
77            return this;
78        }
79        /// <summary>
80        /// Refreshes only the Users
81        /// </summary>
82        /// <returns></returns>
83        public UserViewModel refreshUsers()
84        {
85            accessClient.RefreshUsers();
86            users = accessClient.Users.ToList();
87            return this;
88        }
89        /// <summary>
90        /// Refreshes only the Roles
91        /// </summary>
92        /// <returns></returns>
93        public UserViewModel refreshRoles()
94        {
95            accessClient.RefreshRoles();
96            roles = accessClient.Roles.ToList();
97            return this;
98        }
99        /// <summary>
100        /// Refreshes only the User Groups
101        /// </summary>
102        /// <returns></returns>
103        public UserViewModel refreshGroups()
104        {
105            accessClient.RefreshUserGroups();
106            ugroups= accessClient.Groups.ToList();
107            return this;
108        }
109        /// <summary>
110        /// Returns a user by its Id
111        /// </summary>
112        /// <param name="id">User Id</param>
113        /// <returns></returns>
114        public Access.User getUserById(Guid id)
115        {
116            return users.Find(x => x.Id == id);
117        }
118        /// <summary>
119        /// Returns a group by its Id
120        /// </summary>
121        /// <param name="id">Group id</param>
122        /// <returns></returns>
123        public Access.UserGroup getGroupById(Guid id)
124        {
125            return ugroups.Find(x => x.Id == id);
126        }
127        /// <summary>
128        /// Returns a role by its name
129        /// </summary>
130        /// <param name="name">Role name</param>
131        /// <returns></returns>
132        public Access.Role getRoleByName(string name)
133        {
134            return roles.Find(x => x.Name == name);
135        }
136    }
137}
Note: See TracBrowser for help on using the repository browser.