Free cookie consent management tool by TermsFeed Policy Generator

source: branches/CEDMA-Refactoring-Ticket419/HeuristicLab.Hive.Server.Core/UserRoleManager.cs @ 1248

Last change on this file since 1248 was 907, checked in by msteinbi, 16 years ago

Implementation of UserRoleManager (#417)

File size: 3.2 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Hive.Contracts.Interfaces;
6using HeuristicLab.Hive.Contracts.BusinessObjects;
7using HeuristicLab.Hive.Server.Core.InternalInterfaces.DataAccess;
8using System.Resources;
9using System.Reflection;
10using HeuristicLab.Hive.Contracts;
11
12namespace HeuristicLab.Hive.Server.Core {
13  class UserRoleManager: IUserRoleManager {
14
15    List<User> users;
16    List<UserGroup> userGroups;
17
18    IUserAdapter userAdapter;
19    ResourceManager rm;
20
21    public UserRoleManager() {
22      userAdapter = ServiceLocator.GetUserAdapter();
23      rm = new ResourceManager("HiveServerMessages.resx", Assembly.GetExecutingAssembly());
24
25      users = new List<User>();
26      userGroups = new List<UserGroup>();
27
28      users.Add(new User { PermissionOwnerId = 1, Name = "Hugo", Password = "hUg0" });
29      users.Add(new User { PermissionOwnerId = 2, Name = "Seppl", Password = "seppl" });
30      users.Add(new User { PermissionOwnerId = 3, Name = "Greg", Password = "greg" });
31
32      userGroups.Add(new UserGroup { UserGroupId = 1 });
33      userGroups.Add(new UserGroup { UserGroupId = 2 });
34    }
35
36    #region IUserRoleManager Members
37
38    public ResponseList<User> GetAllUsers() {
39      ResponseList<User> response = new ResponseList<User>();
40
41      List<User> allUsers = new List<User>(userAdapter.GetAllUsers());
42      response.List = allUsers;
43      response.Success = true;
44      response.StatusMessage = ApplicationConstants.RESPONSE_USERROLE_GET_ALL_USERS;
45
46      return response;
47    }
48
49    public Response AddNewUser(User user) {
50      Response response = new Response();
51
52      User dbUser = userAdapter.GetUserByName(user.Name);
53      if (dbUser != null) {
54        response.Success = false;
55        response.StatusMessage = ApplicationConstants.RESPONSE_USERROLE_USER_EXISTS_ALLREADY;
56        return response;
57      }
58      userAdapter.UpdateUser(user);
59      response.Success = true;
60      response.StatusMessage = ApplicationConstants.RESPONSE_USERROLE_USER_SUCCESSFULLY_ADDED;
61     
62      return response;
63    }
64
65    public ResponseList<UserGroup> GetAllUserGroups() {
66      ResponseList<UserGroup> response = new ResponseList<UserGroup>();
67
68      return response;
69    }
70
71    public Response RemoveUser(long userId) {
72      Response response = new Response();
73      User user = userAdapter.GetUserById(userId);
74      if (user == null) {
75        response.Success = false;
76        response.StatusMessage = ApplicationConstants.RESPONSE_USERROLE_USER_DOESNT_EXIST;
77        return response;
78      }
79      response.Success = true;
80      response.StatusMessage = ApplicationConstants.RESPONSE_USERROLE_USER_REMOVED;
81
82      return response;
83    }
84
85    public Response AddNewUserGroup(UserGroup userGroup) {
86      return null;
87    }
88
89    public Response RemoveUserGroup(long groupId) {
90      return null;
91    }
92
93    public Response AddUserToGroup(long groupId, long userId) {
94      throw new NotImplementedException();
95    }
96
97    public Response RemoveUserFromGroup(long groupId, long userId) {
98      throw new NotImplementedException();
99    }
100
101    #endregion
102  }
103}
Note: See TracBrowser for help on using the repository browser.