Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Server.Console/AddUserForm.cs @ 1018

Last change on this file since 1018 was 1018, checked in by aleitner, 16 years ago

Job and User insert updated, also job with parent-job, user in user-group. (#380)

File size: 2.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Linq;
7using System.Text;
8using System.Windows.Forms;
9using HeuristicLab.Hive.Contracts.Interfaces;
10using HeuristicLab.Hive.Contracts.BusinessObjects;
11using HeuristicLab.Hive.Contracts;
12
13namespace HeuristicLab.Hive.Server.Console {
14  public partial class AddUserForm : Form {
15
16    ResponseList<UserGroup> userGroups = null;
17    IUserRoleManager userRoleManager;
18    bool group;
19
20    public AddUserForm(string addForm, bool group) {
21      this.group = group;
22      InitializeComponent();
23      this.Name = "Add " + addForm;
24
25      lblOne.Text = addForm;
26      if (group) {
27        lblOne.Text += " Group";
28      }
29
30      lblGroup.Text = addForm + " Groups";
31
32      if (addForm == "User") {
33        addUser();
34      }
35    }
36
37    private void addUser() {
38     userRoleManager = ServiceLocator.GetUserRoleManager();
39      userGroups = userRoleManager.GetAllUserGroups();
40      cbGroups.Items.Add("none");
41      cbGroups.SelectedIndex = 0;
42      foreach (UserGroup ug in userGroups.List) {
43        cbGroups.Items.Add(ug.Name);
44      }
45    }
46
47    private void btnAdd_Click(object sender, EventArgs e) {
48      if (!group) {
49        if (tbOne.Text != "") {
50          User u = new User() { Name = tbOne.Text, Password = tbPwd.Text };
51          ResponseObject<User> respUser = userRoleManager.AddNewUser(u);
52          if (respUser.Success == true) {
53            if (cbGroups.SelectedIndex != 0) {
54              u = respUser.Obj;
55              foreach (UserGroup ug in userGroups.List) {
56                if (cbGroups.SelectedItem.ToString().Equals(ug.Name)) {
57                  Response resp = userRoleManager.AddUserToGroup
58                    (ug.Id, u.Id);
59                }
60              }
61            }
62          }
63        }
64      } else {
65        UserGroup ug = new UserGroup { Name = tbOne.Text };
66        ResponseObject<UserGroup> respug = userRoleManager.AddNewUserGroup(ug);
67        if (respug.Success == true) {
68          if (!cbGroups.SelectedText.Equals("none")) {
69            ug = respug.Obj;
70            foreach (UserGroup ugs in userGroups.List) {
71              if (cbGroups.SelectedText.Equals(ugs.Name)) {
72                Response resp = userRoleManager.AddUserGroupToGroup
73                  (ug.Id, ugs.Id);
74              }
75            }
76          }
77        }
78      }
79    }
80
81    private void btnClose_Click(object sender, EventArgs e) {
82      this.Close();
83    }
84  }
85}
Note: See TracBrowser for help on using the repository browser.