#region License Information
/* HeuristicLab
* Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using HeuristicLab.Clients.Hive.WebJobManager.Models;
using HeuristicLab.Clients.Hive.WebJobManager.Services.Imports;
using System;
using System.Collections.Generic;
using System.Linq;
namespace HeuristicLab.Clients.Hive.WebJobManager.ViewModels.User
{
///
/// ViewModel containing User/Group/Role data
///
public class UserViewModel : MasterVM
{
public AccessAdministrationClient accessClient { get; set; }
public List users { get; set; }
public List roles { get; set; }
public List ugroups { get; set; }
public Access.User SelectedUser { get; set; }
public List SelectedUserSubscriptions { get; set; }
public List SelectedUserRoles { get; set; }
public Access.UserGroup SelectedGroup { get; set; }
public List SelectedGroupMembers { get; set; }
public Access.Role SelectedRole { get; set; }
public List SelectedRoleEnrolled { get; set; }
///
/// Initialize viewmodel and set up connection
///
/// AccessAdminClient for connection
public UserViewModel(AccessAdministrationClient ac, HiveWebUser hwu) : base(hwu)
{
users = new List();
accessClient = ac;
SelectedUser = new Access.User();
SelectedGroup = new Access.UserGroup();
SelectedRole = new Access.Role();
SelectedRole.Name = "";
SelectedUserSubscriptions = new List();
SelectedUserRoles = new List();
SelectedGroupMembers = new List();
}
///
/// Refreshes Users, Groups and Roles
///
///
public UserViewModel refreshAll()
{
refreshUsers();
refreshGroups();
refreshRoles();
return this;
}
///
/// Refreshes only the Users
///
///
public UserViewModel refreshUsers()
{
accessClient.RefreshUsers();
users = accessClient.Users.ToList();
return this;
}
///
/// Refreshes only the Roles
///
///
public UserViewModel refreshRoles()
{
accessClient.RefreshRoles();
roles = accessClient.Roles.ToList();
return this;
}
///
/// Refreshes only the User Groups
///
///
public UserViewModel refreshGroups()
{
accessClient.RefreshUserGroups();
ugroups= accessClient.Groups.ToList();
return this;
}
///
/// Returns a user by its Id
///
/// User Id
///
public Access.User getUserById(Guid id)
{
return users.Find(x => x.Id == id);
}
///
/// Returns a group by its Id
///
/// Group id
///
public Access.UserGroup getGroupById(Guid id)
{
return ugroups.Find(x => x.Id == id);
}
///
/// Returns a role by its name
///
/// Role name
///
public Access.Role getRoleByName(string name)
{
return roles.Find(x => x.Name == name);
}
}
}