Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7637


Ignore:
Timestamp:
03/19/12 21:15:33 (11 years ago)
Author:
ascheibe
Message:

#1648 added CRUD operations for user groups in ui

Location:
branches/ClientUserManagement
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • branches/ClientUserManagement/HeuristicLab.Clients.Access.Administration/3.3/AccessAdministrationClient.cs

    r7635 r7637  
    6767      ExecuteActionAsync(RefreshUserGroups, exceptionCallback);
    6868    }
     69    #endregion
     70
     71    #region Store
     72    public void StoreUsers() {
     73      foreach (User u in users) {
     74        if (u.Modified) {
     75          if (u.Id == Guid.Empty) {
     76            CallAccessService(s => u.Id = s.AddUser(u).Id);
     77          } else {
     78            CallAccessService(s => s.UpdateUser(u));
     79          }
     80          u.SetUnmodified();
     81        }
     82      }
     83    }
     84
     85    public void StoreUsersAsync(Action<Exception> exceptionCallback) {
     86      ExecuteActionAsync(StoreUsers, exceptionCallback);
     87    }
     88
     89    public void StoreUserGroups() {
     90      foreach (UserGroup g in Groups) {
     91        if (g.Modified) {
     92          if (g.Id == Guid.Empty) {
     93            CallAccessService(s => g.Id = s.AddUserGroup(g));
     94          } else {
     95            CallAccessService(s => s.UpdateUserGroup(g));
     96          }
     97          g.SetUnmodified();
     98        }
     99      }
     100    }
     101
     102    public void StoreUserGroupsAsync(Action<Exception> exceptionCallback) {
     103      ExecuteActionAsync(StoreUserGroups, exceptionCallback);
     104    }
     105
     106    //i don't think such a generic method is a good idea
     107    /*public static void Store(IAccessItem item) {
     108     
     109    } */
     110    #endregion
     111
     112    #region Delete
     113    public void DeleteUser(User u) {
     114      CallAccessService(s => s.DeleteUser(u));
     115    }
     116
     117    public void DeleteUserAsync(User u, Action<Exception> exceptionCallback) {
     118      Action deleteUserAction = new Action(delegate { DeleteUser(u); });
     119      ExecuteActionAsync(deleteUserAction, exceptionCallback);
     120    }
     121
     122    public void DeleteUserGroup(UserGroup u) {
     123      CallAccessService(s => s.DeleteUserGroup(u));
     124    }
     125
     126    public void DeleteUserGroupAsync(UserGroup u, Action<Exception> exceptionCallback) {
     127      Action deleteUserGroupAction = new Action(delegate { DeleteUserGroup(u); });
     128      ExecuteActionAsync(deleteUserGroupAction, exceptionCallback);
     129    }
     130    #endregion
    69131
    70132    public void ExecuteActionAsync(Action action, Action<Exception> exceptionCallback) {
     
    86148        if (ex != null) exceptionCallback(ex);
    87149      }, null);
    88     }
    89     #endregion
    90 
    91     public static void Store(IAccessItem item) {
    92       //TODO: storing
    93150    }
    94151
  • branches/ClientUserManagement/HeuristicLab.Clients.Access.Administration/3.3/Views/RefreshableUserGroupListView.Designer.cs

    r7635 r7637  
    2424    /// </summary>
    2525    private void InitializeComponent() {
     26      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(RefreshableUserGroupListView));
    2627      this.userGroupListView = new HeuristicLab.Clients.Access.Administration.UserGroupListView();
     28      this.storeButton = new System.Windows.Forms.Button();
    2729      this.SuspendLayout();
    2830      //
    2931      // userGroupListView
    3032      //
    31       this.userGroupListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
    32             | System.Windows.Forms.AnchorStyles.Left) 
     33      this.userGroupListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     34            | System.Windows.Forms.AnchorStyles.Left)
    3335            | System.Windows.Forms.AnchorStyles.Right)));
    3436      this.userGroupListView.Caption = "UserGroupList View";
     
    4042      this.userGroupListView.TabIndex = 2;
    4143      //
     44      // storeButton
     45      //
     46      this.storeButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.PublishToWeb;
     47      this.storeButton.Location = new System.Drawing.Point(33, 3);
     48      this.storeButton.Name = "storeButton";
     49      this.storeButton.Size = new System.Drawing.Size(24, 24);
     50      this.storeButton.TabIndex = 4;
     51      this.storeButton.UseVisualStyleBackColor = true;
     52      this.storeButton.Click += new System.EventHandler(this.storeButton_Click);
     53      //
    4254      // RefreshableUserGroupListView
    4355      //
    4456      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    4557      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     58      this.Controls.Add(this.storeButton);
    4659      this.Controls.Add(this.userGroupListView);
    4760      this.Name = "RefreshableUserGroupListView";
     
    4962      this.Controls.SetChildIndex(this.userGroupListView, 0);
    5063      this.Controls.SetChildIndex(this.refreshButton, 0);
     64      this.Controls.SetChildIndex(this.storeButton, 0);
    5165      this.ResumeLayout(false);
    5266
     
    5670
    5771    private UserGroupListView userGroupListView;
     72    private System.Windows.Forms.Button storeButton;
    5873
    5974  }
  • branches/ClientUserManagement/HeuristicLab.Clients.Access.Administration/3.3/Views/RefreshableUserGroupListView.cs

    r7635 r7637  
    3737        base.Content_Refreshing(sender, e);
    3838        userGroupListView.Enabled = false;
     39        if (Content.Groups != null) {
     40          Content.Groups.ItemsRemoved -= new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<UserGroup>>(Groups_ItemsRemoved);
     41        }
    3942      }
    4043    }
     
    4750        userGroupListView.Enabled = true;
    4851        userGroupListView.Content = Content.Groups;
     52        if (Content.Groups != null) {
     53          Content.Groups.ItemsRemoved += new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<UserGroup>>(Groups_ItemsRemoved);
     54        }
    4955      }
     56    }
     57
     58    void Groups_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<Collections.IndexedItem<UserGroup>> e) {
     59      foreach (var u in e.Items) {
     60        Content.DeleteUserGroupAsync(u.Value, PluginInfrastructure.ErrorHandling.ShowErrorDialog);
     61      }
     62    }
     63
     64    protected override void DeregisterContentEvents() {
     65      if (Content.Groups != null) {
     66        Content.Groups.ItemsRemoved -= new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<UserGroup>>(Groups_ItemsRemoved);
     67      }
     68      base.DeregisterContentEvents();
     69    }
     70
     71    private void storeButton_Click(object sender, EventArgs e) {
     72      Content.StoreUserGroupsAsync(PluginInfrastructure.ErrorHandling.ShowErrorDialog);
    5073    }
    5174  }
  • branches/ClientUserManagement/HeuristicLab.Clients.Access.Administration/3.3/Views/RefreshableUserListView.Designer.cs

    r7614 r7637  
    2525    private void InitializeComponent() {
    2626      this.userListView = new HeuristicLab.Clients.Access.Administration.UserListView();
     27      this.storeButton = new System.Windows.Forms.Button();
    2728      this.SuspendLayout();
    2829      //
     
    3031      //
    3132      this.userListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    32                   | System.Windows.Forms.AnchorStyles.Left)
    33                   | System.Windows.Forms.AnchorStyles.Right)));
     33            | System.Windows.Forms.AnchorStyles.Left)
     34            | System.Windows.Forms.AnchorStyles.Right)));
    3435      this.userListView.Caption = "UserList View";
    3536      this.userListView.Content = null;
     
    4041      this.userListView.TabIndex = 2;
    4142      //
     43      // storeButton
     44      //
     45      this.storeButton.Location = new System.Drawing.Point(33, 3);
     46      this.storeButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.PublishToWeb;
     47      this.storeButton.Name = "storeButton";
     48      this.storeButton.Size = new System.Drawing.Size(24, 24);
     49      this.storeButton.TabIndex = 3;
     50      this.storeButton.UseVisualStyleBackColor = true;
     51      this.storeButton.Click += new System.EventHandler(this.storeButton_Click);
     52      //
    4253      // RefreshableUserListView
    4354      //
     
    4556      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    4657      this.Controls.Add(this.userListView);
     58      this.Controls.Add(this.storeButton);
    4759      this.Name = "RefreshableUserListView";
    4860      this.Size = new System.Drawing.Size(565, 411);
     61      this.Controls.SetChildIndex(this.storeButton, 0);
    4962      this.Controls.SetChildIndex(this.userListView, 0);
    5063      this.Controls.SetChildIndex(this.refreshButton, 0);
     
    5669
    5770    private UserListView userListView;
     71    private System.Windows.Forms.Button storeButton;
    5872  }
    5973}
  • branches/ClientUserManagement/HeuristicLab.Clients.Access.Administration/3.3/Views/RefreshableUserListView.cs

    r7635 r7637  
    3737        base.Content_Refreshing(sender, e);
    3838        userListView.Enabled = false;
     39        if (Content.Users != null) {
     40          Content.Users.ItemsRemoved -= new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<User>>(Users_ItemsRemoved);
     41        }
    3942      }
    4043    }
     
    4750        userListView.Enabled = true;
    4851        userListView.Content = Content.Users;
     52        if (Content.Users != null) {
     53          Content.Users.ItemsRemoved += new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<User>>(Users_ItemsRemoved);
     54        }
    4955      }
     56    }
     57
     58    protected override void DeregisterContentEvents() {
     59      if (Content.Users != null) {
     60        Content.Users.ItemsRemoved -= new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<User>>(Users_ItemsRemoved);
     61      }
     62      base.DeregisterContentEvents();
     63    }
     64
     65    void Users_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<Collections.IndexedItem<User>> e) {
     66      foreach (var u in e.Items) {
     67        Content.DeleteUserAsync(u.Value, PluginInfrastructure.ErrorHandling.ShowErrorDialog);
     68      }
     69    }
     70
     71    private void storeButton_Click(object sender, EventArgs e) {
     72      Content.StoreUsersAsync(PluginInfrastructure.ErrorHandling.ShowErrorDialog);
    5073    }
    5174  }
  • branches/ClientUserManagement/HeuristicLab.Clients.Access.Administration/3.3/Views/UserGroupView.Designer.cs

    r7635 r7637  
    5656      this.groupNameTextBox.Size = new System.Drawing.Size(282, 20);
    5757      this.groupNameTextBox.TabIndex = 2;
     58      this.groupNameTextBox.TextChanged += new System.EventHandler(this.groupNameTextBox_TextChanged);
    5859      //
    5960      // idTextBox
     
    6162      this.idTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    6263            | System.Windows.Forms.AnchorStyles.Right)));
     64      this.idTextBox.Enabled = false;
    6365      this.idTextBox.Location = new System.Drawing.Point(79, 29);
    6466      this.idTextBox.Name = "idTextBox";
  • branches/ClientUserManagement/HeuristicLab.Clients.Access.Administration/3.3/Views/UserGroupView.cs

    r7635 r7637  
    4747      }
    4848    }
     49
     50    private void groupNameTextBox_TextChanged(object sender, System.EventArgs e) {
     51      if (Content.Name != this.groupNameTextBox.Text)
     52        Content.Name = this.groupNameTextBox.Text;
     53    }
    4954  }
    5055}
  • branches/ClientUserManagement/HeuristicLab.Clients.Access.Administration/3.3/Views/UserView.Designer.cs

    r7614 r7637  
    5050      // userNameTextBox
    5151      //
    52       this.userNameTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    53                   | System.Windows.Forms.AnchorStyles.Right)));
     52      this.userNameTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     53            | System.Windows.Forms.AnchorStyles.Right)));
     54      this.userNameTextBox.Enabled = false;
    5455      this.userNameTextBox.Location = new System.Drawing.Point(72, 3);
    5556      this.userNameTextBox.Name = "userNameTextBox";
    5657      this.userNameTextBox.Size = new System.Drawing.Size(289, 20);
    5758      this.userNameTextBox.TabIndex = 2;
     59      this.userNameTextBox.TextChanged += new System.EventHandler(this.userNameTextBox_TextChanged);
    5860      //
    5961      // fullNameTextBox
    6062      //
    61       this.fullNameTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    62                   | System.Windows.Forms.AnchorStyles.Right)));
     63      this.fullNameTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
     64            | System.Windows.Forms.AnchorStyles.Right)));
    6365      this.fullNameTextBox.Location = new System.Drawing.Point(72, 29);
    6466      this.fullNameTextBox.Name = "fullNameTextBox";
    6567      this.fullNameTextBox.Size = new System.Drawing.Size(289, 20);
    6668      this.fullNameTextBox.TabIndex = 3;
     69      this.fullNameTextBox.TextChanged += new System.EventHandler(this.fullNameTextBox_TextChanged);
    6770      //
    6871      // UserView
  • branches/ClientUserManagement/HeuristicLab.Clients.Access.Administration/3.3/Views/UserView.cs

    r7614 r7637  
    4747      }
    4848    }
     49
     50    private void fullNameTextBox_TextChanged(object sender, System.EventArgs e) {
     51      if (Content.FullName != fullNameTextBox.Text)
     52        Content.FullName = fullNameTextBox.Text;
     53    }
     54
     55    private void userNameTextBox_TextChanged(object sender, System.EventArgs e) {
     56      if (Content.UserName != userNameTextBox.Text)
     57        Content.UserName = userNameTextBox.Text;
     58    }
    4959  }
    5060}
  • branches/ClientUserManagement/HeuristicLab.Clients.Access/3.3/ServiceClients/AccessItem.cs

    r7368 r7637  
    6565    }
    6666
     67    public void SetUnmodified() {
     68      Modified = false;
     69    }
     70
    6771    protected AccessItem(AccessItem original, Cloner cloner) {
    6872      cloner.RegisterClonedObject(original, this);
  • branches/ClientUserManagement/HeuristicLab.Clients.Access/3.3/ServiceClients/UserGroup.cs

    r7436 r7637  
    2020#endregion
    2121
     22using System;
    2223using System.Drawing;
     24using System.Runtime.Serialization;
    2325using HeuristicLab.Common;
    2426using HeuristicLab.Core;
    2527namespace HeuristicLab.Clients.Access {
    2628  [Item("UserGroup", "A group.")]
    27   public partial class UserGroup {
     29  public partial class UserGroup : IDisposable {
    2830    protected UserGroup(UserGroup original, Cloner cloner)
    2931      : base(original, cloner) {
     
    3537    }
    3638
    37     public UserGroup() { }
     39    public UserGroup() {
     40      this.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(UserGroup_PropertyChanged);
     41    }
     42
     43    [OnDeserialized]
     44    private void RegisterNamePropertyChangedEvent(StreamingContext c) {
     45      this.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(UserGroup_PropertyChanged);
     46    }
     47
     48    void UserGroup_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) {
     49      //this is a workaround as we can't overide the Name property and fire directly
     50      if (e.PropertyName == "Name") {
     51        OnToStringChanged();
     52      }
     53    }
    3854
    3955    public override IDeepCloneable Clone(Cloner cloner) {
     
    4460      return Name;
    4561    }
     62
     63    #region IDisposable Members
     64    public void Dispose() {
     65      this.PropertyChanged -= new System.ComponentModel.PropertyChangedEventHandler(UserGroup_PropertyChanged);
     66    }
     67    #endregion
    4668  }
    4769}
  • branches/ClientUserManagement/HeuristicLab.Services.Access/3.3/AccessService.cs

    r7619 r7637  
    644644    public Guid AddUserGroup(DT.UserGroup group) {
    645645      using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
    646         //because id is not automatically set because of user, we have to do it here manually for group
     646        //because id is not automatically set because of user, we have to do it here manually for group   
    647647        group.Id = Guid.NewGuid();
     648
    648649        context.UserGroupBases.InsertOnSubmit(Convert.ToEntity(group));
    649650        context.SubmitChanges();
     
    653654
    654655    public void UpdateUserGroup(DT.UserGroup group) {
    655       AddUserGroup(group);
     656      using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
     657        DA.UserGroup entity = context.UserGroupBases.OfType<DA.UserGroup>().FirstOrDefault(x => x.Id == group.Id);
     658        Convert.ToEntity(group, entity);
     659        context.SubmitChanges();
     660      }
    656661    }
    657662
    658663    public void DeleteUserGroup(DT.UserGroup group) {
    659664      RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
    660 
    661       using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
    662         context.UserGroupBases.DeleteOnSubmit(Convert.ToEntity(group));
    663         context.SubmitChanges();
     665      var g = group; //linq does not like vars called group
     666
     667      using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
     668        var query = from ug in context.UserGroupBases.OfType<DA.UserGroup>()
     669                    where ug.Id == g.Id
     670                    select ug;
     671        if (query.Count() > 0) {
     672          context.UserGroupBases.DeleteOnSubmit(query.First());
     673          context.SubmitChanges();
     674        } else {
     675          throw new Exception("UserGroup with id " + g.Id + " does not exist.");
     676        }
    664677      }
    665678    }
  • branches/ClientUserManagement/HeuristicLab.Services.Access/3.3/Convert.cs

    r7614 r7637  
    283283      };
    284284    }
     285
     286    public static void ToEntity(DT.UserGroup source, DA.UserGroup target) {
     287      target.Name = source.Name;
     288    }
    285289    #endregion
    286290
Note: See TracChangeset for help on using the changeset viewer.