Index: branches/UserManagement/HeuristicLab.Services.Authentication/AuthenticationService.cs
===================================================================
--- branches/UserManagement/HeuristicLab.Services.Authentication/AuthenticationService.cs	(revision 4590)
+++ branches/UserManagement/HeuristicLab.Services.Authentication/AuthenticationService.cs	(revision 4647)
@@ -6,4 +6,5 @@
 using HeuristicLab.Services.Authentication.DataAccess;
 using System.Data.Linq;
+using System.Diagnostics;
 
 namespace HeuristicLab.Services.Authentication
@@ -16,139 +17,728 @@
         public DataTransfer.User GetUser(Guid id)
         {
-
-            using (UserManagementDataContext db = new UserManagementDataContext())
-            {
-                Table<aspnet_User> UserTable = db.GetTable<aspnet_User>();
-
-                var User = from item in UserTable
-                           where item.UserId == id
-                          select item;
-               return Convert.ToDataTransfer((aspnet_User)User);
-            }
-         
+            using (UserManagementDataContext db = new UserManagementDataContext())
+            {
+                try
+                {
+                    Table<aspnet_User> UserTable = db.GetTable<aspnet_User>();
+
+                    var User = from item in UserTable
+                               where item.UserId == id
+                               select item;
+                    User user = Convert.ToDataTransfer((aspnet_User)User.Single());
+
+                    if (user == null) { return null; }
+
+                    Table<aspnet_Membership> MembershipTable = db.GetTable<aspnet_Membership>();
+
+                    var Membership = from item in MembershipTable
+                                     where item.UserId == id
+                                     select item;
+
+                    Membership membership = Convert.ToDataTransfer((aspnet_Membership)Membership.Single());
+
+                    if (membership == null) { return null; }
+                    user.Membership = membership;
+
+                    return user;
+
+
+                }
+                catch (Exception ex)
+                {
+                    Debug.WriteLine(ex.InnerException);
+                    return null;
+                }
+            }
+        }
+
+        public DataTransfer.User GetUser(Guid applicationId, string userName)
+        {
+            using (UserManagementDataContext db = new UserManagementDataContext())
+            {
+                try
+                {
+                    Table<aspnet_User> UserTable = db.GetTable<aspnet_User>();
+
+                    var User = from item in UserTable
+                               where item.UserName == userName && item.ApplicationId == applicationId
+                               select item;
+
+                    User user = Convert.ToDataTransfer((aspnet_User)User.Single());
+
+                    if (user == null) { return null; }
+
+                    Table<aspnet_Membership> MembershipTable = db.GetTable<aspnet_Membership>();
+
+                    var Membership = from item in MembershipTable
+                                     where item.UserId == user.UserId
+                                     select item;
+
+                    Membership membership = Convert.ToDataTransfer((aspnet_Membership)Membership.Single());
+
+                    if (membership == null) { return null; }
+                    user.Membership = membership;
+
+                    return user;
+
+
+
+
+                }
+                catch (Exception ex)
+                {
+                    Debug.WriteLine(ex.InnerException);
+                    return null;
+                }
+               }
+        }
+
+        public IEnumerable<DataTransfer.User> GetUsers(Guid applicationId)
+        {
+            List<DataTransfer.User> UserList = new List<DataTransfer.User>();
+            using (UserManagementDataContext db = new UserManagementDataContext())
+            {
+                try
+                {
+                    Table<aspnet_User> UserTable = db.GetTable<aspnet_User>();
+                    var Users = from item in UserTable
+                                where item.ApplicationId == applicationId
+                                select item;
+                    foreach (var eUser in Users)
+                    {
+
+                        User user = Convert.ToDataTransfer(eUser);
+
+                        if (user== null) { return null; }
+
+                        Table<aspnet_Membership> MembershipTable = db.GetTable<aspnet_Membership>();
+
+                        var Membership = from item in MembershipTable
+                                         where item.UserId == user.UserId
+                                         select item;
+
+                        Membership membership = Convert.ToDataTransfer((aspnet_Membership)Membership.Single());
+
+                        if (membership == null) { return null; }
+                        user.Membership = membership;
+
+                        UserList.Add(user);
+                    }
+                }
+                catch (Exception ex)
+                {
+                    Debug.WriteLine(ex.InnerException);
+                    return new List<User>();
+                }
+            }
+
+            return UserList;
+        }
+        public bool InsertUser(User user)
+        {
+            if (user != null)
+            {
+                using (UserManagementDataContext db = new UserManagementDataContext())
+                {
+                    try
+                    {
+
+                        Guid? userId = null;
+                        Application application = GetApplication(user.ApplicationId);
+                        if(application == null){return false;}
+                        if (user.Membership == null) { return false; }
+    
+                        int? passwordFormat = 1;
+                        int? uniqueEmail = null;
+                        int result = db.aspnet_Membership_CreateUser(application.ApplicationName, user.UserName, user.Membership.Password, user.Membership.PasswordSalt, user.Membership.Email, user.Membership.PasswordQuestion, user.Membership.PasswordAnswer, user.Membership.IsApproved, DateTime.UtcNow, DateTime.Now, uniqueEmail, passwordFormat, ref userId);
+                                                   
+                        if (result != 0)
+                        {
+                            return false;
+                        }
+
+                        if (userId != null)
+                        {
+                            return true;
+                        }
+                        else
+                        {
+                            return false;
+                        }
+                    }
+                    catch (Exception ex)
+                    {
+                        Debug.WriteLine(ex.InnerException);
+                        return false;
+                    }
+                }
+           
+            }
+            return false;
+        }
+        public bool DeleteUser(Guid id)
+        {
+
+            User user = GetUser(id);
+            if (user != null)
+            {
+
+                using (UserManagementDataContext db = new UserManagementDataContext())
+                {
+                    try
+                    {
+                        Application application = GetApplication(user.ApplicationId);
+                        if (application == null)
+                        {
+                            return false;
+                        }
+
+                        int? tablesToDeleteFrom = 99;
+                        int? numTablesDeletedFrom = null;
+                        db.aspnet_Users_DeleteUser(application.ApplicationName, user.UserName, tablesToDeleteFrom, ref numTablesDeletedFrom);
+                       
+                        if (numTablesDeletedFrom != null)
+                        {
+                            return true;
+                        }
+                        else
+                        {
+                            return false;
+                        }
+                    }
+                    catch (Exception ex)
+                    {
+                        Debug.WriteLine(ex.InnerException);
+                        return false;
+                    }
+                }
+            }
+            return false;
+        }
+
+        public bool UpdateUser(User user)
+        {
+           
+            if (user != null)
+            {
+
+                using (UserManagementDataContext db = new UserManagementDataContext())
+                {
+                    try
+                    {
+                        if (user.Membership == null)
+                        {
+                            return false;
+                        }
+
+                        Table<aspnet_User> UserTable = db.GetTable<aspnet_User>();
+
+                        var User = from item in UserTable
+                                   where item.UserId == user.UserId
+                                   select item;
+                       aspnet_User eUser = ((aspnet_User)User.Single());
+
+
+                       Table<aspnet_Membership> MembershipTable = db.GetTable<aspnet_Membership>();
+
+                       var Membership = from item in MembershipTable
+                                        where item.UserId == user.UserId
+                                        select item;
+
+                       aspnet_Membership eMembership = ((aspnet_Membership)Membership.Single());
+
+                        Convert.ToEntity(user, eUser);
+                        
+                        Convert.ToEntity(user.Membership, eMembership);
+                        if (eUser == null)
+                        {
+                           return false;
+                        }
+                        if (eMembership == null)
+                        {
+                            return false;
+                        }
+                        db.SubmitChanges();
+                    }
+                    catch (Exception ex)
+                    {
+                        Debug.WriteLine(ex.InnerException);
+                        return false;
+                    }
+                }
+            } return false;
+        }
+
+        #endregion
+
+
+        #region Role
+
+        public Role GetRole(Guid id)
+        {
+            using (UserManagementDataContext db = new UserManagementDataContext())
+            {
+                try
+                {
+                    Table<aspnet_Role> RoleTable = db.GetTable<aspnet_Role>();
+
+                    var Role = from item in RoleTable
+                               where item.RoleId == id
+                               select item;
+                    return Convert.ToDataTransfer((aspnet_Role)Role.Single());
+                }
+                catch (Exception ex)
+                {
+                    Debug.WriteLine(ex.InnerException);
+                    return null;
+                }
+            }
+        }
+
+        public Role GetRole(Guid applicationId, string roleName)
+        {
+            using (UserManagementDataContext db = new UserManagementDataContext())
+            {
+                try
+                {
+                    Table<aspnet_Role> RoleTable = db.GetTable<aspnet_Role>();
+
+                    var Role = from item in RoleTable
+                               where item.RoleName == roleName && item.ApplicationId == applicationId
+                               select item;
+                    return Convert.ToDataTransfer((aspnet_Role)Role.Single());
+                }
+                catch (Exception ex)
+                {
+                    Debug.WriteLine(ex.InnerException);
+                    return null;
+                }
+            }
+        }
+
+        public bool RoleExists(Guid roleId)
+        {
+            if (roleId != null)
+            {
+                using (UserManagementDataContext db = new UserManagementDataContext())
+                {
+                    try
+                    {
+                        Role role = GetRole(roleId);
+                        if (role == null)
+                        {
+                            return false;
+                        }
+                        Application application = GetApplication(role.ApplicationId);
+                        if (application == null)
+                        {
+                            return false;
+                        }
+
+                        int result = db.aspnet_Roles_RoleExists(application.ApplicationName, role.RoleName);
+                        
+                        return (result == 0);
+                    }
+                    catch (Exception ex)
+                    {
+                        Debug.Write(ex.InnerException);
+                        return false;
+                    }
+                }
+
+            } return false;
+        }
+
+        public IEnumerable<Role> GetRoles(Guid applicationId)
+        {
+            List<Role> RoleList = new List<Role>();
+
+            using (UserManagementDataContext db = new UserManagementDataContext())
+            {
+                try
+                {
+                   // db.aspnet_Roles_GetAllRoles(applicationName);
+                    Table<aspnet_Role> RoleTable = db.GetTable<aspnet_Role>();
+
+                    var Roles = from item in RoleTable
+                                where item.ApplicationId == applicationId
+                                select item;
+                    foreach (var Role in Roles)
+                    {
+                        RoleList.Add(Convert.ToDataTransfer((aspnet_Role)Role));
+                    }
+                }
+                catch (Exception ex)
+                {
+                    Debug.WriteLine(ex.InnerException);
+                    return new List<Role>();
+                }
+            }
+
+            return RoleList;
+        }
+        
+        public bool InsertRole(Role role)
+        {
+            if (role != null)
+            {
+                using (UserManagementDataContext db = new UserManagementDataContext())
+                {
+                    try
+                    {
+                        Application application = GetApplication(role.ApplicationId);
+                        if (application == null)
+                        {
+                            return false;
+                        }
+                        int result = db.aspnet_Roles_CreateRole(application.ApplicationName, role.RoleName);
+                       
+                        return (result == 0); // checken, welchen rückgabewert (in db, procedure)
+                      
+                    }
+                    catch (Exception ex)
+                    {
+                        Debug.WriteLine(ex.InnerException);
+                        return false;
+                    }
+                }
+              
+            }
+            return false;
+        }
+        public bool UpdateRole(Role role)
+        {
+
+            if (role != null)
+            {
+
+                using (UserManagementDataContext db = new UserManagementDataContext())
+                {
+                    try
+                    {
+
+                        Table<aspnet_Role> RoleTable = db.GetTable<aspnet_Role>();
+
+                        var Role = from item in RoleTable
+                                   where item.RoleId == role.RoleId
+                                   select item;
+                        aspnet_Role eRole = ((aspnet_Role)Role.Single());
+
+
+                        Convert.ToEntity(role, eRole);
+
+                        if (eRole != null)
+                        {
+                            db.SubmitChanges();
+                        }
+                        else
+                        {
+                            return false;
+                        }
+                    }
+                    catch (Exception ex)
+                    {
+                        Debug.WriteLine(ex.InnerException);
+                        return false;
+                    }
+                }
+            } return false;
+        }
+
+        public bool DeleteRole(Guid id)
+        {
+            if (id != null)
+            {
+                using (UserManagementDataContext db = new UserManagementDataContext())
+                {
+                    try
+                    {
+                        Role role = GetRole(id);
+
+                        bool deleteOnlyIfRoleIsEmpty = true;
+                        if (role == null)
+                        {
+                            return false;
+                        }
+                        Application application = GetApplication(role.ApplicationId);
+                        if (application == null)
+                        {
+                            return false;
+                        }
+                        db.aspnet_Roles_DeleteRole(application.ApplicationName, role.RoleName, deleteOnlyIfRoleIsEmpty);
+
+                      
+
+                        return true;
+                    }
+                    catch (Exception ex)
+                    {
+                        Debug.WriteLine(ex.InnerException);
+                        return false;
+                    }
+                }
+              
+            }
+            return false;
+        }
+
+        public bool IsUserInRole(Guid roleId, Guid userId)
+        {
+            if (roleId != null && userId != null)
+            {
+                using (UserManagementDataContext db = new UserManagementDataContext())
+                {
+
+                    try
+                    {
+                        User user = GetUser(userId);
+                        if (user == null) { return false; }
+
+                        Application application = GetApplication(user.ApplicationId);
+                        if (application == null) { return false; }
+
+                        Role role = GetRole(roleId);
+                        if (role == null) { return false; }
+
+                        int result = db.aspnet_UsersInRoles_IsUserInRole(application.ApplicationName, user.UserName, role.RoleName);
+                       
+                        return (result == 0);
+                    }
+                    catch (Exception ex)
+                    {
+                        Debug.WriteLine(ex.InnerException);
+                        return false;
+
+                    }
+
+                }
+
+            } return false;
+        }
+
+        public bool AddUserToRole(Guid roleId, Guid userId)
+        {
+            using (UserManagementDataContext db = new UserManagementDataContext())
+            {
+                try
+                {
+                    Role role = GetRole(roleId);
+                    if (role == null)
+                    {
+                        return false;
+                    }
+                    Application application = GetApplication(role.ApplicationId);
+                    if (application == null)
+                    {
+                        return false;
+                    }
+                    User user = GetUser(userId);
+                    if (user == null)
+                    {
+                        return false;
+                    }
+
+                    db.aspnet_UsersInRoles_AddUsersToRoles(application.ApplicationName, user.UserName, role.RoleName,DateTime.Now);
+                    return true;
+                }
+                catch (Exception ex)
+                {
+                    Debug.WriteLine(ex.InnerException);
+                    return false;
+                }
+            }
+        
+        }
+        public bool RemoveUserFromRole(Guid roleId, Guid userId)
+        {
+            using (UserManagementDataContext db = new UserManagementDataContext())
+            {
+                try
+                {
+                    Role role = GetRole(roleId);
+                    if (role == null)
+                    {
+                        return false;
+                    }
+                    Application application = GetApplication(role.ApplicationId);
+                    if (application == null)
+                    {
+                        return false;
+                    }
+                    User user = GetUser(userId);
+                    if (user == null)
+                    {
+                        return false;
+                    }
+
+                   db.aspnet_UsersInRoles_RemoveUsersFromRoles(application.ApplicationName, user.UserName, role.RoleName);
+                    return true;
+                   
+                }
+                catch (Exception ex)
+                {
+                    Debug.WriteLine(ex.InnerException);
+                    return false;
+                }
+            }
+           
+        }
+        public IEnumerable<Role> GetRolesForUser(Guid userId)
+        {
+            List<Role> roles = new List<Role>();
+            using (UserManagementDataContext db = new UserManagementDataContext())
+            {
+                try
+                {
+                    User user = GetUser(userId);
+                    if (user == null)
+                    {
+                        return roles;
+                    }
+                    Application application = GetApplication(user.ApplicationId);
+                    if (application == null)
+                    {
+                        return roles;
+                    }
+                    
+
+                    ISingleResult<aspnet_UsersInRoles_GetRolesForUserResult> results = db.aspnet_UsersInRoles_GetRolesForUser(application.ApplicationName,user.UserName);
+                    foreach (aspnet_UsersInRoles_GetRolesForUserResult userInRole in results)
+                    {
+                        roles.Add(GetRole(application.ApplicationId,userInRole.RoleName));
+                    }
+                }
+                catch (Exception ex)
+                {
+                    Debug.WriteLine(ex.InnerException);
+                    return new List<Role>();
+                }
+            }
             
-        }
-        public IEnumerable<DataTransfer.User> GetUsers()
-        {
-            List<DataTransfer.User> UserList = new List<DataTransfer.User>();
-
-            using (UserManagementDataContext db = new UserManagementDataContext())
-            {
-                Table<aspnet_User> UserTable = db.GetTable<aspnet_User>();
-
-                var Users = from item in UserTable
-                           select item;
-                foreach (var User in Users)
-                {
-                    UserList.Add( Convert.ToDataTransfer((aspnet_User)User));
-                }
-            }
-
-
-            return UserList;
-        }
-        public bool InsertUser(User user)
-        {
-            // insert user
-            if (user != null)
-            {
-                using (UserManagementDataContext db = new UserManagementDataContext())
-                {
-                    try
-                    {
-                        aspnet_User userDa = Convert.ToEntity(user);
-                        db.aspnet_Users.InsertOnSubmit(userDa);
-                        db.SubmitChanges();
-                    }
-                    catch (Exception e)
-                    {
-                        return false;
-                    }
-                }
-                return true;
-            }
+            return roles;
+        }
+
+        public IEnumerable<User> GetUsersInRole(Guid roleId)
+        {
+            List<User> users = new List<User>();
+
+            using(UserManagementDataContext db = new UserManagementDataContext()){
+                try
+                {
+                    Role role = GetRole(roleId);
+
+                    if (role != null)
+                    {
+                        Application application = GetApplication(role.ApplicationId);
+
+                        if (application != null)
+                        {
+
+
+                            ISingleResult<aspnet_UsersInRoles_GetUsersInRolesResult> result = db.aspnet_UsersInRoles_GetUsersInRoles(application.ApplicationName, role.RoleName);
+                            foreach (aspnet_UsersInRoles_GetUsersInRolesResult usersInRole in result)
+                            {
+                                users.Add(GetUser(application.ApplicationId,usersInRole.UserName));
+                            }
+                        }
+                    }
+                }
+                catch (Exception ex)
+                {
+                    Debug.WriteLine(ex.InnerException);
+                    return new List<User>();
+                }
+            }
+
+            return users;
+        }
+
+        #endregion
+
+        #region Application
+
+        public Application InsertApplication(Application application)
+        {
+            if (application != null)
+            {
+                using (UserManagementDataContext db = new UserManagementDataContext())
+                {
+                    try
+                    {
+                        Guid? applicationId = null;
+                        int result = db.aspnet_Applications_CreateApplication(application.ApplicationName, ref applicationId);
+                        Console.WriteLine("result=" + result);
+                        if (applicationId != null)
+                        {
+                            application.ApplicationId = (Guid)applicationId;
+                            return application;
+                        }
+                        else
+                        {
+                            return null;
+                        }
+                    }
+                    catch (Exception ex)
+                    {
+                        Debug.WriteLine(ex.InnerException);
+                        return null;
+                    }
+                }
+              
+            }
+            return null;
+        }
+
+        public bool DeleteApplication(Application application)
+        {
             return false;
         }
-        public bool DeleteUser(Guid id)
-        {
-
-            return false;
-        }
-        public bool UpdateUser(User user)
-        {
-            return false;
+
+        public Application GetApplication(Guid id)
+        {
+            using (UserManagementDataContext db = new UserManagementDataContext())
+            {
+                try
+                {
+                    Table<aspnet_Application> ApplicationTable = db.GetTable<aspnet_Application>();
+
+                    var Application = from item in ApplicationTable
+                                      where item.ApplicationId == id
+                                      select item;
+                    return Convert.ToDataTransfer((aspnet_Application)Application.Single());
+                }
+                catch (Exception ex)
+                {
+                    Debug.WriteLine(ex.InnerException);
+                    return null;
+                }
+            }
         }
 
         #endregion
 
-
-        #region Role
-
-        public Role GetRole(Guid id)
-        {
-            Role role = new Role();
-            // ...
-
-            return role;
-        }
-        public IEnumerable<Role> GetRoles()
-        {
-            List<Role> RoleList = new List<Role>();
-
-            using (UserManagementDataContext db = new UserManagementDataContext())
-            {
-                Table<aspnet_Role> RoleTable = db.GetTable<aspnet_Role>();
-
-                var Roles = from item in RoleTable
-                            select item;
-                foreach (var Role in Roles)
-                {
-                    RoleList.Add(Convert.ToDataTransfer((aspnet_Role)Role));
-                }
-            }
-
-            return RoleList;
-        }
-        public bool InsertRole(Role role)
-        {
-            if (role != null)
-            {
-                using (UserManagementDataContext db = new UserManagementDataContext())
-                {
-                    try
-                    {
-                        aspnet_Role roleDa = Convert.ToEntity(role);
-                        db.aspnet_Roles.InsertOnSubmit(roleDa);
-                        db.SubmitChanges();
-                    }
-                    catch (Exception e)
-                    {
-                        return false;
-                    }
-                }
-                return true;
-            }
-            return false;
-        }
-        public bool UpdateRole(Role role)
-        {
-            return false;
-        }
-        public bool DeleteRole(Guid id)
-        {
-            return false;
-        }
-        public bool AddRoleToUser(Guid roleId, Guid userId)
-        {
-            return false;
-        }
-        public bool RemoveRoleFromUser(Guid roleId, Guid userId)
-        {
-            return false;
-        }
-        public IEnumerable<Role> GetRolesForUser(Guid userId)
-        {
-            List<Role> roles = new List<Role>();
-            return roles;
+        #region Membership
+
+        public Membership InsertMembership(Membership membership)
+        {
+
+            if (membership != null)
+            {
+                using (UserManagementDataContext db = new UserManagementDataContext())
+                {
+                    try
+                    {
+                        Application application = GetApplication(membership.ApplicationId);
+                        if (application == null) { return null; }
+
+                    }
+                    catch (Exception ex)
+                    {
+                        Debug.WriteLine(ex.InnerException);
+                        return null;
+                    }
+                }
+            }
+            return null;
         }
 
Index: branches/UserManagement/HeuristicLab.Services.Authentication/Convert.cs
===================================================================
--- branches/UserManagement/HeuristicLab.Services.Authentication/Convert.cs	(revision 4590)
+++ branches/UserManagement/HeuristicLab.Services.Authentication/Convert.cs	(revision 4647)
@@ -139,4 +139,8 @@
                 UserId = source.UserId,
                 Password = source.Password,
+                PasswordAnswer = source.PasswordAnswer,
+                PasswordSalt = source.PasswordSalt,
+                PasswordQuestion = source.PasswordQuestion,
+               
                 Email = source.Email,
                 LoweredEmail = source.LoweredEmail,
@@ -149,4 +153,5 @@
                 Comment = source.Comment
 
+                
             };
         }
@@ -165,4 +170,8 @@
                 UserId = source.UserId,
                 Password = source.Password,
+                PasswordAnswer = source.PasswordAnswer,
+                PasswordSalt = source.PasswordSalt,
+                PasswordQuestion = source.PasswordQuestion,
+               
                 Email = source.Email,
                 LoweredEmail = source.LoweredEmail,
@@ -189,4 +198,8 @@
                 target.UserId = source.UserId;
                 target.Password = source.Password;
+                target.PasswordAnswer = source.PasswordAnswer;
+                target.PasswordSalt = source.PasswordSalt;
+                target.PasswordQuestion = source.PasswordQuestion;
+               
                 target.Email = source.Email;
                 target.LoweredEmail = source.LoweredEmail;
Index: branches/UserManagement/HeuristicLab.Services.Authentication/HeuristicLab.Services.Authentication.csproj
===================================================================
--- branches/UserManagement/HeuristicLab.Services.Authentication/HeuristicLab.Services.Authentication.csproj	(revision 4590)
+++ branches/UserManagement/HeuristicLab.Services.Authentication/HeuristicLab.Services.Authentication.csproj	(revision 4647)
@@ -60,4 +60,7 @@
     </ProjectReference>
   </ItemGroup>
+  <ItemGroup>
+    <WCFMetadata Include="Service References\" />
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
Index: branches/UserManagement/HeuristicLab.Services.Authentication/Interfaces/IAuthenticationService.cs
===================================================================
--- branches/UserManagement/HeuristicLab.Services.Authentication/Interfaces/IAuthenticationService.cs	(revision 4590)
+++ branches/UserManagement/HeuristicLab.Services.Authentication/Interfaces/IAuthenticationService.cs	(revision 4647)
@@ -16,5 +16,8 @@
 
         [OperationContract]
-        IEnumerable<User> GetUsers();
+        User GetUser(Guid applicationId, string userName);
+
+        [OperationContract]
+        IEnumerable<User> GetUsers(Guid applicationId);
 
         [OperationContract]
@@ -27,4 +30,13 @@
         bool UpdateUser(User user);
 
+        [OperationContract]
+        bool AddUserToRole(Guid roleId, Guid userId);
+
+        [OperationContract]
+        bool RemoveUserFromRole(Guid roleId, Guid userId);
+
+        [OperationContract]
+        IEnumerable<Role> GetRolesForUser(Guid userId);
+
         #endregion
 
@@ -33,8 +45,17 @@
         [OperationContract]
         Role GetRole(Guid id);
+        
+        [OperationContract]
+        Role GetRole(Guid applicationId, string roleName);
 
         [OperationContract]
-        IEnumerable<Role> GetRoles();
+        IEnumerable<Role> GetRoles(Guid applicationId);
 
+        [OperationContract]
+        bool RoleExists(Guid roleId);
+
+        [OperationContract]
+        bool IsUserInRole(Guid roleId, Guid userId);
+        
         [OperationContract]
         bool InsertRole(Role role);
@@ -47,11 +68,24 @@
 
         [OperationContract]
-        bool AddRoleToUser(Guid roleId, Guid userId);
+        IEnumerable<User> GetUsersInRole(Guid roleId);
+       
+        #endregion
+
+        #region Application
 
         [OperationContract]
-        bool RemoveRoleFromUser(Guid roleId, Guid userId);
+        Application GetApplication(Guid id);
 
         [OperationContract]
-        IEnumerable<Role> GetRolesForUser(Guid userId);
+        Application InsertApplication(Application application);
+
+        [OperationContract]
+        bool DeleteApplication(Application application);
+        #endregion
+
+        #region Membership
+
+        [OperationContract]
+        Membership InsertMembership(Membership membership);
 
         #endregion
