Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6858


Ignore:
Timestamp:
09/30/11 15:44:34 (13 years ago)
Author:
ascheibe
Message:

#1648 worked on webservice and added more unit tests

Location:
branches/ClientUserManagement
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/ClientUserManagement/HeuristicLab.Services.Access-3.3.Tests/App.config

    r6840 r6858  
    22<configuration>
    33  <connectionStrings>
    4     <add name="HeuristicLab.Services.Directoy.DataAccess.Properties.Settings.HeuristicLab_AuthenticationConnectionString"
     4    <add name="HeuristicLab.Authentication"
    55        connectionString="Data Source=.;Initial Catalog=HeuristicLab.Authentication;Integrated Security=True"
    66        providerName="System.Data.SqlClient" />
     
    99        providerName="System.Data.SqlClient" />
    1010  </connectionStrings>
     11  <system.web>
     12    <membership defaultProvider="AspNetSqlMembershipProvider" userIsOnlineTimeWindow="20">
     13      <providers>
     14        <clear />
     15        <add name="AspNetSqlMemberShipProvider"
     16          type="System.Web.Security.SqlMembershipProvider"
     17          connectionStringName="HeuristicLab.Authentication"
     18          enablePasswordRetrieval="false"
     19          enablePasswordReset="true"
     20          requiresQuestionAndAnswer="false"
     21          passwordFormat="Hashed"
     22          applicationName="HeuristicLab.Authentication"
     23          requiresUniqueEmail="false"
     24          minRequiredPasswordLength="1"
     25          minRequiredNonalphanumericCharacters="0"
     26          maxInvalidPasswordAttempts="50" />         
     27      </providers>
     28    </membership>
     29    <authentication mode="Windows" />
     30    <roleManager enabled="true" defaultProvider="AspNetSqlRoleProvider">
     31      <providers>
     32        <clear />
     33        <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
     34             connectionStringName="HeuristicLab.Authentication" applicationName="HeuristicLab.Authentication" />
     35      </providers>
     36    </roleManager>
     37  </system.web>
    1138</configuration>
  • branches/ClientUserManagement/HeuristicLab.Services.Access-3.3.Tests/UnitTest.cs

    r6852 r6858  
    3535      using (DA.ClientManagementDataContext context = new DA.ClientManagementDataContext()) {
    3636        context.ExecuteCommand("DELETE FROM dbo.ResourceResourceGroup");
     37        context.ExecuteCommand("DELETE FROM dbo.ClientLog");
    3738        context.ExecuteCommand("DELETE FROM dbo.Resource");
    3839        context.ExecuteCommand("DELETE FROM dbo.ClientConfiguration");
    3940        context.ExecuteCommand("DELETE FROM dbo.ClientError");
    40         context.ExecuteCommand("DELETE FROM dbo.ClientLog");
    4141        context.ExecuteCommand("DELETE FROM dbo.ClientType");
    4242        context.ExecuteCommand("DELETE FROM dbo.Country");
     
    5050
    5151    [TestMethod]
    52     public void AddClientTest() {
     52    public void AddClientGroupTest() {
    5353      ClearDB();
    5454      AccessService service = new AccessService();
     
    138138    }
    139139
    140 
     140    [TestMethod]
     141    public void AddUser() {
     142      ClearDB();
     143      AccessService service = new AccessService();
     144
     145      DT.User user = new DT.User();
     146      user.FullName = "Max Mustermann";
     147      user.UserName = "max";
     148      user.IsApproved = true;
     149      user.Comment = "this is a comment";
     150      user.Email = "max@mail.com";
     151
     152      DT.User newUser = service.AddUser(user);
     153      var users = service.GetAllUsers();
     154      Assert.AreEqual(1, users.Where(x => x.UserName == newUser.UserName).Count());
     155      service.DeleteUser(newUser);
     156      users = service.GetAllUsers();
     157      Assert.AreEqual(0, users.Where(x => x.UserName == newUser.UserName).Count());
     158    }
     159
     160    [TestMethod]
     161    public void AddUserGroup() {
     162      ClearDB();
     163      AccessService service = new AccessService();
     164
     165      DT.User user = new DT.User();
     166      user.FullName = "Max Mustermann";
     167      user.UserName = "max";
     168      user.IsApproved = true;
     169      user.Comment = "this is a comment";
     170      user.Email = "max@mail.com";
     171
     172      DT.User user2 = new DT.User();
     173      user2.FullName = "Franz Fritz";
     174      user2.UserName = "Franz";
     175      user2.IsApproved = true;
     176      user2.Comment = "this is a franz comment";
     177      user2.Email = "franz@mail.com";
     178
     179      DT.User newUser = service.AddUser(user);
     180      DT.User newUser2 = service.AddUser(user2);
     181
     182      DT.UserGroup userGroup = new DT.UserGroup();
     183      userGroup.Name = "testGroup";
     184      userGroup.Id = service.AddUserGroup(userGroup);
     185      Assert.AreEqual(1, service.GetAllUserGroups().Count());
     186
     187      service.AddUserGroupBaseToGroup(newUser, userGroup);
     188      service.AddUserGroupBaseToGroup(newUser2, userGroup);
     189      Assert.AreEqual(2, service.GetUserGroupMapping().Count());
     190
     191      DT.Role role = service.AddRole(new DT.Role() { Name = "NewGroup" });
     192      Assert.AreEqual(1, service.GetRoles().Where(x => x.Name == role.Name).Count());
     193
     194      service.AddRoleToGroup(userGroup, role);
     195      Assert.AreEqual(1, service.GetUserRoles(newUser).Count());
     196      Assert.AreEqual(1, service.GetUserRoles(newUser2).Count());
     197
     198      service.RemoveRoleFromGroup(userGroup, role);
     199
     200      Assert.AreEqual(0, service.GetUserRoles(newUser).Count());
     201      Assert.AreEqual(0, service.GetUserRoles(newUser2).Count());
     202
     203      service.DeleteUser(newUser);
     204      service.DeleteUser(newUser2);
     205      var users = service.GetAllUsers();
     206      Assert.AreEqual(0, users.Where(x => x.UserName == newUser.UserName).Count());
     207
     208      service.DeleteRole(role);
     209      Assert.AreEqual(0, service.GetRoles().Where(x => x.Name == role.Name).Count());
     210    }
     211
     212    [TestMethod]
     213    public void AddClientError() {
     214      ClearDB();
     215      AccessService service = new AccessService();
     216
     217      DT.ClientError error = new DT.ClientError();
     218      error.Timestamp = DateTime.Now;
     219      error.UserComment = "this happend when i clicked on...";
     220      error.Exception = "Exception";
     221      error.ConfigDump = "config";
     222
     223      service.ReportError(error);
     224      Assert.AreEqual(1, service.GetClientErrors().Count());
     225      service.DeleteError(service.GetClientErrors().First());
     226      Assert.AreEqual(0, service.GetClientErrors().Count());
     227    }
    141228  }
    142229}
  • branches/ClientUserManagement/HeuristicLab.Services.Access.DataAccess/3.3/ClientManagement.dbml

    r6852 r6858  
    22  <Connection Mode="AppSettings" ConnectionString="Data Source=.;Initial Catalog=HeuristicLab.ClientManagement;Integrated Security=True" SettingsObjectName="HeuristicLab.Services.Access.DataAccess.Properties.Settings" SettingsPropertyName="HeuristicLab_ClientManagementConnectionString" Provider="System.Data.SqlClient" />
    33  <Table Name="dbo.Resource" Member="Resources">
    4     <Type Name="Resource" InheritanceCode="Resource">
     4    <Type Name="Resource" InheritanceCode="Resource" IsInheritanceDefault="true">
    55      <Column Name="Id" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />
    66      <Column Name="Name" Type="System.String" DbType="NVarChar(MAX) NOT NULL" CanBeNull="false" />
     
    1010      <Association Name="Resource_ResourceResourceGroup1" Member="ResourceResourceGroupsParents" Storage="_ResourceResourceGroups1" ThisKey="Id" OtherKey="ResourceId" Type="ResourceResourceGroup" />
    1111      <Association Name="Resource_ClientLog" Member="ClientLogs" ThisKey="Id" OtherKey="ResourceId" Type="ClientLog" />
    12       <Association Name="Resource_ClientError" Member="ClientErrors" ThisKey="Id" OtherKey="ClientId" Type="ClientError" />
    1312      <Association Name="Resource_ResourcePlugin" Member="ResourcePlugins" ThisKey="Id" OtherKey="ResourceId" Type="ResourcePlugin" />
    14       <Type Name="Client" InheritanceCode="Client" IsInheritanceDefault="true">
     13      <Type Name="Client" InheritanceCode="Client">
    1514        <Column Name="HeuristicLabVersion" Type="System.String" DbType="NVarChar(MAX)" CanBeNull="false" />
    1615        <Column Name="MemorySize" Type="System.Int32" DbType="Int" CanBeNull="true" />
     
    5554      <Column Name="ClientId" Type="System.Guid" DbType="UniqueIdentifier" CanBeNull="true" />
    5655      <Column Name="UserId" Type="System.Guid" DbType="UniqueIdentifier" CanBeNull="true" />
    57       <Association Name="Resource_ClientError" Member="Resource" ThisKey="ClientId" OtherKey="Id" Type="Resource" IsForeignKey="true" />
    58       <Association Name="UserGroupBase_ClientError" Member="UserGroupBase" ThisKey="UserId" OtherKey="Id" Type="UserGroupBase" IsForeignKey="true" />
    5956    </Type>
    6057  </Table>
    6158  <Table Name="dbo.UserGroup" Member="UserGroupBases">
    62     <Type Name="UserGroupBase" InheritanceCode="UserGroupBase">
    63       <Column Name="Id" AutoSync="Never" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />
     59    <Type Name="UserGroupBase" InheritanceCode="UserGroupBase" IsInheritanceDefault="true">
     60      <Column Name="Id" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
    6461      <Column Name="Type" Type="System.String" DbType="NVarChar(10) NOT NULL" CanBeNull="false" IsDiscriminator="true" />
    65       <Association Name="UserGroupBase_ClientError" Member="ClientErrors" ThisKey="Id" OtherKey="UserId" Type="ClientError" />
    6662      <Association Name="UserGroupBase_UserGroupUserGroup" Member="UserGroupUserGroupsChilds" Storage="_UserGroupUserGroups" ThisKey="Id" OtherKey="UserGroupId" Type="UserGroupUserGroup" />
    6763      <Association Name="UserGroupBase_UserGroupUserGroup1" Member="UserGroupUserGroupsParents" Storage="_UserGroupUserGroups1" ThisKey="Id" OtherKey="UserGroupUserGroupId" Type="UserGroupUserGroup" />
  • branches/ClientUserManagement/HeuristicLab.Services.Access.DataAccess/3.3/ClientManagement.dbml.layout

    r6852 r6858  
    7272      </nestedChildShapes>
    7373    </classShape>
    74     <associationConnector edgePoints="[(6.625 : 1.84699625651042); (10.375 : 1.84699625651042)]" fixedFrom="NotFixed" fixedTo="NotFixed">
    75       <AssociationMoniker Name="/ClientManagementDataContext/Resource/Resource_ClientError" />
    76       <nodes>
    77         <classShapeMoniker Id="20c6e07e-aa12-43dc-87d6-dae5bf173da4" />
    78         <classShapeMoniker Id="5e8ae5e1-4026-47e5-91fb-9607de024aad" />
    79       </nodes>
    80     </associationConnector>
    8174    <classShape Id="452ce94a-9bd2-4968-9a5f-a0ab1dba6b2e" absoluteBounds="7.875, 3.875, 2, 1.1939925130208327">
    8275      <DataClassMoniker Name="/ClientManagementDataContext/UserGroupBase" />
     
    165158      </nodes>
    166159    </inheritanceConnector>
    167     <associationConnector edgePoints="[(9.875 : 3.90625); (10.53125 : 3.90625); (10.53125 : 2.65549967447917)]" fixedFrom="NotFixed" fixedTo="NotFixed">
    168       <AssociationMoniker Name="/ClientManagementDataContext/UserGroupBase/UserGroupBase_ClientError" />
    169       <nodes>
    170         <classShapeMoniker Id="452ce94a-9bd2-4968-9a5f-a0ab1dba6b2e" />
    171         <classShapeMoniker Id="5e8ae5e1-4026-47e5-91fb-9607de024aad" />
    172       </nodes>
    173     </associationConnector>
    174160    <associationConnector edgePoints="[(9.875 : 4.53449625651042); (10.75 : 4.53449625651042)]" fixedFrom="NotFixed" fixedTo="NotFixed">
    175161      <AssociationMoniker Name="/ClientManagementDataContext/UserGroupBase/UserGroupBase_UserGroupUserGroup" />
  • branches/ClientUserManagement/HeuristicLab.Services.Access.DataAccess/3.3/ClientManagement.designer.cs

    r6852 r6858  
    197197 
    198198  [global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.Resource")]
    199   [global::System.Data.Linq.Mapping.InheritanceMappingAttribute(Code="Resource", Type=typeof(Resource))]
    200   [global::System.Data.Linq.Mapping.InheritanceMappingAttribute(Code="Client", Type=typeof(Client), IsDefault=true)]
     199  [global::System.Data.Linq.Mapping.InheritanceMappingAttribute(Code="Resource", Type=typeof(Resource), IsDefault=true)]
     200  [global::System.Data.Linq.Mapping.InheritanceMappingAttribute(Code="Client", Type=typeof(Client))]
    201201  [global::System.Data.Linq.Mapping.InheritanceMappingAttribute(Code="ClientGroup", Type=typeof(ClientGroup))]
    202202  public partial class Resource : INotifyPropertyChanging, INotifyPropertyChanged
     
    218218   
    219219    private EntitySet<ClientLog> _ClientLogs;
    220    
    221     private EntitySet<ClientError> _ClientErrors;
    222220   
    223221    private EntitySet<ResourcePlugin> _ResourcePlugins;
     
    242240      this._ResourceResourceGroups1 = new EntitySet<ResourceResourceGroup>(new Action<ResourceResourceGroup>(this.attach_ResourceResourceGroups1), new Action<ResourceResourceGroup>(this.detach_ResourceResourceGroups1));
    243241      this._ClientLogs = new EntitySet<ClientLog>(new Action<ClientLog>(this.attach_ClientLogs), new Action<ClientLog>(this.detach_ClientLogs));
    244       this._ClientErrors = new EntitySet<ClientError>(new Action<ClientError>(this.attach_ClientErrors), new Action<ClientError>(this.detach_ClientErrors));
    245242      this._ResourcePlugins = new EntitySet<ResourcePlugin>(new Action<ResourcePlugin>(this.attach_ResourcePlugins), new Action<ResourcePlugin>(this.detach_ResourcePlugins));
    246243      OnCreated();
     
    366363    }
    367364   
    368     [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Resource_ClientError", Storage="_ClientErrors", ThisKey="Id", OtherKey="ClientId")]
    369     public EntitySet<ClientError> ClientErrors
    370     {
    371       get
    372       {
    373         return this._ClientErrors;
    374       }
    375       set
    376       {
    377         this._ClientErrors.Assign(value);
    378       }
    379     }
    380    
    381365    [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Resource_ResourcePlugin", Storage="_ResourcePlugins", ThisKey="Id", OtherKey="ResourceId")]
    382366    public EntitySet<ResourcePlugin> ResourcePlugins
     
    443427   
    444428    private void detach_ClientLogs(ClientLog entity)
    445     {
    446       this.SendPropertyChanging();
    447       entity.Resource = null;
    448     }
    449    
    450     private void attach_ClientErrors(ClientError entity)
    451     {
    452       this.SendPropertyChanging();
    453       entity.Resource = this;
    454     }
    455    
    456     private void detach_ClientErrors(ClientError entity)
    457429    {
    458430      this.SendPropertyChanging();
     
    11581130    private System.Nullable<System.Guid> _UserId;
    11591131   
    1160     private EntityRef<Resource> _Resource;
    1161    
    1162     private EntityRef<UserGroupBase> _UserGroupBase;
    1163    
    11641132    #region Extensibility Method Definitions
    11651133    partial void OnLoaded();
     
    11841152    public ClientError()
    11851153    {
    1186       this._Resource = default(EntityRef<Resource>);
    1187       this._UserGroupBase = default(EntityRef<UserGroupBase>);
    11881154      OnCreated();
    11891155    }
     
    13001266        if ((this._ClientId != value))
    13011267        {
    1302           if (this._Resource.HasLoadedOrAssignedValue)
    1303           {
    1304             throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
    1305           }
    13061268          this.OnClientIdChanging(value);
    13071269          this.SendPropertyChanging();
     
    13241286        if ((this._UserId != value))
    13251287        {
    1326           if (this._UserGroupBase.HasLoadedOrAssignedValue)
    1327           {
    1328             throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
    1329           }
    13301288          this.OnUserIdChanging(value);
    13311289          this.SendPropertyChanging();
     
    13371295    }
    13381296   
    1339     [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Resource_ClientError", Storage="_Resource", ThisKey="ClientId", OtherKey="Id", IsForeignKey=true)]
    1340     public Resource Resource
    1341     {
    1342       get
    1343       {
    1344         return this._Resource.Entity;
    1345       }
    1346       set
    1347       {
    1348         Resource previousValue = this._Resource.Entity;
    1349         if (((previousValue != value)
    1350               || (this._Resource.HasLoadedOrAssignedValue == false)))
    1351         {
    1352           this.SendPropertyChanging();
    1353           if ((previousValue != null))
    1354           {
    1355             this._Resource.Entity = null;
    1356             previousValue.ClientErrors.Remove(this);
    1357           }
    1358           this._Resource.Entity = value;
    1359           if ((value != null))
    1360           {
    1361             value.ClientErrors.Add(this);
    1362             this._ClientId = value.Id;
    1363           }
    1364           else
    1365           {
    1366             this._ClientId = default(Nullable<System.Guid>);
    1367           }
    1368           this.SendPropertyChanged("Resource");
    1369         }
    1370       }
    1371     }
    1372    
    1373     [global::System.Data.Linq.Mapping.AssociationAttribute(Name="UserGroupBase_ClientError", Storage="_UserGroupBase", ThisKey="UserId", OtherKey="Id", IsForeignKey=true)]
    1374     public UserGroupBase UserGroupBase
    1375     {
    1376       get
    1377       {
    1378         return this._UserGroupBase.Entity;
    1379       }
    1380       set
    1381       {
    1382         UserGroupBase previousValue = this._UserGroupBase.Entity;
    1383         if (((previousValue != value)
    1384               || (this._UserGroupBase.HasLoadedOrAssignedValue == false)))
    1385         {
    1386           this.SendPropertyChanging();
    1387           if ((previousValue != null))
    1388           {
    1389             this._UserGroupBase.Entity = null;
    1390             previousValue.ClientErrors.Remove(this);
    1391           }
    1392           this._UserGroupBase.Entity = value;
    1393           if ((value != null))
    1394           {
    1395             value.ClientErrors.Add(this);
    1396             this._UserId = value.Id;
    1397           }
    1398           else
    1399           {
    1400             this._UserId = default(Nullable<System.Guid>);
    1401           }
    1402           this.SendPropertyChanged("UserGroupBase");
    1403         }
    1404       }
    1405     }
    1406    
    14071297    public event PropertyChangingEventHandler PropertyChanging;
    14081298   
     
    14271317 
    14281318  [global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.UserGroup")]
    1429   [global::System.Data.Linq.Mapping.InheritanceMappingAttribute(Code="UserGroupBase", Type=typeof(UserGroupBase))]
     1319  [global::System.Data.Linq.Mapping.InheritanceMappingAttribute(Code="UserGroupBase", Type=typeof(UserGroupBase), IsDefault=true)]
    14301320  [global::System.Data.Linq.Mapping.InheritanceMappingAttribute(Code="User", Type=typeof(User))]
    14311321  [global::System.Data.Linq.Mapping.InheritanceMappingAttribute(Code="UserGroup", Type=typeof(UserGroup))]
     
    14381328   
    14391329    private string _Type;
    1440    
    1441     private EntitySet<ClientError> _ClientErrors;
    14421330   
    14431331    private EntitySet<UserGroupUserGroup> _UserGroupUserGroups;
     
    14571345    public UserGroupBase()
    14581346    {
    1459       this._ClientErrors = new EntitySet<ClientError>(new Action<ClientError>(this.attach_ClientErrors), new Action<ClientError>(this.detach_ClientErrors));
    14601347      this._UserGroupUserGroups = new EntitySet<UserGroupUserGroup>(new Action<UserGroupUserGroup>(this.attach_UserGroupUserGroups), new Action<UserGroupUserGroup>(this.detach_UserGroupUserGroups));
    14611348      this._UserGroupUserGroups1 = new EntitySet<UserGroupUserGroup>(new Action<UserGroupUserGroup>(this.attach_UserGroupUserGroups1), new Action<UserGroupUserGroup>(this.detach_UserGroupUserGroups1));
     
    14631350    }
    14641351   
    1465     [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Id", DbType="UniqueIdentifier NOT NULL", IsPrimaryKey=true, IsDbGenerated=true)]
     1352    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Id", DbType="UniqueIdentifier NOT NULL", IsPrimaryKey=true)]
    14661353    public System.Guid Id
    14671354    {
     
    15031390    }
    15041391   
    1505     [global::System.Data.Linq.Mapping.AssociationAttribute(Name="UserGroupBase_ClientError", Storage="_ClientErrors", ThisKey="Id", OtherKey="UserId")]
    1506     public EntitySet<ClientError> ClientErrors
    1507     {
    1508       get
    1509       {
    1510         return this._ClientErrors;
    1511       }
    1512       set
    1513       {
    1514         this._ClientErrors.Assign(value);
    1515       }
    1516     }
    1517    
    15181392    [global::System.Data.Linq.Mapping.AssociationAttribute(Name="UserGroupBase_UserGroupUserGroup", Storage="_UserGroupUserGroups", ThisKey="Id", OtherKey="UserGroupId")]
    15191393    public EntitySet<UserGroupUserGroup> UserGroupUserGroupsChilds
     
    15601434        this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    15611435      }
    1562     }
    1563    
    1564     private void attach_ClientErrors(ClientError entity)
    1565     {
    1566       this.SendPropertyChanging();
    1567       entity.UserGroupBase = this;
    1568     }
    1569    
    1570     private void detach_ClientErrors(ClientError entity)
    1571     {
    1572       this.SendPropertyChanging();
    1573       entity.UserGroupBase = null;
    15741436    }
    15751437   
  • branches/ClientUserManagement/HeuristicLab.Services.Access/3.3/AccessService.cs

    r6852 r6858  
    9696                    select c;
    9797        if (query.Count() > 0) {
     98
     99          //delete affiliation first
     100          var queryMapping = context.ResourceResourceGroups.Where(x => x.ResourceId == client.Id);
     101          if (queryMapping.Count() > 0) {
     102            context.ResourceResourceGroups.DeleteAllOnSubmit(queryMapping);
     103          }
     104
    98105          context.Resources.DeleteOnSubmit(query.First());
    99106          context.SubmitChanges();
     
    349356    public void DeleteUser(DT.User user) {
    350357      if (user.Id != null && user.Id != Guid.Empty) {
     358        //delete asp.net user
    351359        Membership.DeleteUser(user.UserName);
    352360        using (DA.ClientManagementDataContext context = new DA.ClientManagementDataContext()) {
    353           context.UserGroupBases.DeleteOnSubmit(Convert.ToEntity(user));
    354           context.SubmitChanges();
     361          var query = context.UserGroupBases.OfType<DA.User>().Where(x => x.Id == user.Id);
     362          if (query.Count() > 0) {
     363
     364            //delete affiliation first
     365            var queryMapping = context.UserGroupUserGroups.Where(x => x.UserGroupId == user.Id);
     366            if (queryMapping.Count() > 0) {
     367              context.UserGroupUserGroups.DeleteAllOnSubmit(queryMapping);
     368            }
     369
     370            //delete user from access db
     371            context.UserGroupBases.DeleteOnSubmit(query.First());
     372            context.SubmitChanges();
     373          }
    355374        }
    356375      }
     
    405424    public Guid AddUserGroup(DT.UserGroup group) {
    406425      using (DA.ClientManagementDataContext context = new DA.ClientManagementDataContext()) {
     426        //because id is not automatically set because of user, we have to do it here manually for group
     427        group.Id = Guid.NewGuid();
    407428        context.UserGroupBases.InsertOnSubmit(Convert.ToEntity(group));
    408429        context.SubmitChanges();
     
    464485    #region Roles
    465486    public IEnumerable<DT.Role> GetRoles() {
    466       throw new System.NotImplementedException();
     487      using (DA.ASPNETAuthenticationDataContext context = new DA.ASPNETAuthenticationDataContext()) {
     488        var query = from u in context.aspnet_Roles
     489                    select Convert.ToDto(u);
     490        return query.ToList();
     491      }
    467492    }
    468493
    469494    public DT.Role AddRole(DT.Role role) {
    470       throw new System.NotImplementedException();
    471     }
    472 
    473     public void UpdateRole(DT.Role role) {
    474       throw new System.NotImplementedException();
     495      Roles.CreateRole(role.Name);
     496      return role;
    475497    }
    476498
    477499    public void DeleteRole(DT.Role role) {
    478       throw new System.NotImplementedException();
     500      Roles.DeleteRole(role.Name);
    479501    }
    480502
    481503    public IEnumerable<DT.Role> GetUserRoles(DT.User user) {
    482       throw new System.NotImplementedException();
     504      var roles = Roles.GetRolesForUser(user.UserName);
     505      return roles.Select(x => new DT.Role() { Name = x });
     506    }
     507
     508    public void AddRoleToGroup(DT.UserGroup userGroup, DT.Role role) {
     509      Guid[] userIds;
     510      string[] aspUsers;
     511
     512      using (DA.ClientManagementDataContext accessContext = new DA.ClientManagementDataContext()) {
     513        userIds = (from u in accessContext.UserGroupUserGroups
     514                   where u.UserGroupUserGroupId == userGroup.Id
     515                   select u.UserGroupId).ToArray();
     516      }
     517
     518      using (DA.ASPNETAuthenticationDataContext aspContext = new DA.ASPNETAuthenticationDataContext()) {
     519        aspUsers = (from u in aspContext.aspnet_Users
     520                    where userIds.Contains(u.UserId)
     521                    select u.UserName).ToArray();
     522      }
     523
     524      Roles.AddUsersToRole(aspUsers, role.Name);
     525
     526    }
     527
     528    public void RemoveRoleFromGroup(DT.UserGroup userGroup, DT.Role role) {
     529      Guid[] userIds;
     530      string[] aspUsers;
     531
     532      using (DA.ClientManagementDataContext accessContext = new DA.ClientManagementDataContext()) {
     533        userIds = (from u in accessContext.UserGroupUserGroups
     534                   where u.UserGroupUserGroupId == userGroup.Id
     535                   select u.UserGroupId).ToArray();
     536      }
     537
     538      using (DA.ASPNETAuthenticationDataContext aspContext = new DA.ASPNETAuthenticationDataContext()) {
     539        aspUsers = (from u in aspContext.aspnet_Users
     540                    where userIds.Contains(u.UserId)
     541                    select u.UserName).ToArray();
     542      }
     543
     544      Roles.RemoveUsersFromRole(aspUsers.ToArray(), role.Name);
    483545    }
    484546    #endregion
     
    486548    #region Error Reporting
    487549    public void ReportError(DT.ClientError error) {
    488       throw new System.NotImplementedException();
     550      using (DA.ClientManagementDataContext context = new DA.ClientManagementDataContext()) {
     551        context.ClientErrors.InsertOnSubmit(Convert.ToEntity(error));
     552        context.SubmitChanges();
     553      }
    489554    }
    490555
    491556    public IEnumerable<DT.ClientError> GetClientErrors() {
    492       throw new System.NotImplementedException();
     557      using (DA.ClientManagementDataContext context = new DA.ClientManagementDataContext()) {
     558        var query = from c in context.ClientErrors
     559                    select Convert.ToDto(c);
     560        return query.ToList();
     561      }
    493562    }
    494563
    495564    public IEnumerable<DT.ClientError> GetLastClientErrors(DateTime startDate) {
    496       throw new System.NotImplementedException();
     565      using (DA.ClientManagementDataContext context = new DA.ClientManagementDataContext()) {
     566        var query = from c in context.ClientErrors
     567                    where c.Timestamp >= startDate
     568                    select Convert.ToDto(c);
     569        return query.ToList();
     570      }
    497571    }
    498572
    499573    public void DeleteError(DT.ClientError error) {
    500       throw new System.NotImplementedException();
     574      using (DA.ClientManagementDataContext context = new DA.ClientManagementDataContext()) {
     575        var query = context.ClientErrors.Where(x => x.Id == error.Id);
     576        if (query.Count() > 0) {
     577          context.ClientErrors.DeleteOnSubmit(query.First());
     578          context.SubmitChanges();
     579        }
     580      }
    501581    }
    502582    #endregion
  • branches/ClientUserManagement/HeuristicLab.Services.Access/3.3/App.config

    r6815 r6858  
    1111        <clear />
    1212        <add name="AspNetSqlMemberShipProvider"
    13           type="System.Web.Security.SqlMembershipProvider"
    14           connectionStringName="HeuristicLab.Authentication"
    15           enablePasswordRetrieval="false"
    16           enablePasswordReset="true"
    17           requiresQuestionAndAnswer="false"
    18           passwordFormat="Hashed"
    19           applicationName="HeuristicLab.Authentication" />
     13              type="System.Web.Security.SqlMembershipProvider"
     14              connectionStringName="HeuristicLab.Authentication"
     15              enablePasswordRetrieval="false"
     16              enablePasswordReset="true"
     17              requiresQuestionAndAnswer="false"
     18              passwordFormat="Hashed"
     19              applicationName="HeuristicLab.Authentication"
     20              requiresUniqueEmail="false"
     21              minRequiredPasswordLength="1"
     22              minRequiredNonalphanumericCharacters="0"
     23              maxInvalidPasswordAttempts="50" />
    2024      </providers>
    2125    </membership>
  • branches/ClientUserManagement/HeuristicLab.Services.Access/3.3/Convert.cs

    r6852 r6858  
    360360    }
    361361    #endregion
     362
     363    #region Role
     364    public static DT.Role ToDto(DA.aspnet_Role r) {
     365      return new DT.Role() {
     366        Name = r.RoleName
     367      };
     368    }
     369    public static DA.aspnet_Role ToEntity(DT.Role r) {
     370      return new DA.aspnet_Role() {
     371        RoleName = r.Name
     372      };
     373    }
     374    #endregion
    362375  }
    363376}
  • branches/ClientUserManagement/HeuristicLab.Services.Access/3.3/IAccessService.cs

    r6852 r6858  
    172172    Role AddRole(Role role);
    173173
    174     [OperationContract]
    175     void UpdateRole(Role role);
     174    /*[OperationContract]
     175    void UpdateRole(Role role);*/
    176176
    177177    [OperationContract]
     
    180180    [OperationContract]
    181181    IEnumerable<Role> GetUserRoles(User user);
     182
     183    [OperationContract]
     184    void AddRoleToGroup(UserGroup userGroup, Role role);
     185
     186    [OperationContract]
     187    void RemoveRoleFromGroup(UserGroup userGroup, Role role);
    182188    #endregion
    183189
Note: See TracChangeset for help on using the changeset viewer.