Index: branches/UserManagement/HeuristicLab.Services.Authentication/AuthenticationService.cs
===================================================================
--- branches/UserManagement/HeuristicLab.Services.Authentication/AuthenticationService.cs	(revision 4979)
+++ branches/UserManagement/HeuristicLab.Services.Authentication/AuthenticationService.cs	(revision 5257)
@@ -1,3 +1,24 @@
-﻿using System;
+﻿#region License Information
+/* HeuristicLab 
+ * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 
+ * 
+ * This file is part of HeuristicLab. 
+ * 
+ * HeuristicLab is free software: you can redistribute it and/or modify 
+ * it under the terms of the GNU General Public License as published by 
+ * the Free Software Foundation, either version 3 of the License, or 
+ * (at your option) any later version. 
+ * 
+ * HeuristicLab is distributed in the hope that it will be useful, 
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of 
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
+ * GNU General Public License for more details. 
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 
+ */
+#endregion
+
+using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -8,540 +29,273 @@
 using System.Diagnostics;
 
-namespace HeuristicLab.Services.Authentication
-{
-    [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
-    public class AuthenticationService : IAuthenticationService
-    {
-
-        #region User
-
-
-        public DataTransfer.User GetUser(Guid id)
-        {
-            using (UserManagementDataContext db = new UserManagementDataContext())
-            {
-                var user = db.aspnet_Users.Where(x => x.UserId == id).FirstOrDefault();
-                var membership = db.aspnet_Memberships.Where(x => x.UserId == id).FirstOrDefault();
-
-
-                return Convert.ToDataTransfer(user, membership);
-
-
-            }
-        }
-
-        public IEnumerable<DataTransfer.User> GetAllUsers() {
-          List<DataTransfer.User> userList = new List<DataTransfer.User>();
-          using (UserManagementDataContext db = new UserManagementDataContext()) {
-            var users = db.aspnet_Users.ToList<aspnet_User>();
-            foreach (aspnet_User user in users) {
-              var membership = db.aspnet_Memberships.Where(x => x.UserId == user.UserId).FirstOrDefault();
-              userList.Add(Convert.ToDataTransfer(user, membership));
-            }
-          }
-
-          return userList;
-        }
-
-        public IEnumerable<DataTransfer.User> GetUsers(Guid applicationId)
-        {
-            List<DataTransfer.User> userList = new List<DataTransfer.User>();
-            using (UserManagementDataContext db = new UserManagementDataContext())
-            {
-                var users = db.aspnet_Users.Where(x => x.ApplicationId == applicationId).ToList<aspnet_User>();
-
-                foreach (aspnet_User user in users)
-                {
-                    var membership = db.aspnet_Memberships.Where(x => x.UserId == user.UserId).FirstOrDefault();
-
-                    userList.Add(Convert.ToDataTransfer(user, membership));
-
-                }
-
-
-
-            }
-            return userList;
-        }
-
-        public Guid AddUser(User user)
-        {
-            if (user != null)
-            {
-                using (UserManagementDataContext db = new UserManagementDataContext())
-                {
-
-                    aspnet_User eUser = new aspnet_User();
-                    aspnet_Membership eMembership = new aspnet_Membership();
-
-                    Convert.ToEntity(user, eUser, eMembership);
-                    try
-                    {
-                        db.aspnet_Users.InsertOnSubmit(eUser);
-                        db.aspnet_Memberships.InsertOnSubmit(eMembership);
-                        db.SubmitChanges();
-                    }
-                    catch (Exception ex)
-                    {
-                        return Guid.Empty;
-                    }
-
-                    return user.Id;
-
-
-                }
-
-            }
-            return Guid.Empty;
-        }
-
-        public bool DeleteUser(Guid id)
-        {
-
-            using (UserManagementDataContext db = new UserManagementDataContext())
-            {
-                var user = db.aspnet_Users.Where(x => x.UserId == id).FirstOrDefault();
-                var membership = db.aspnet_Memberships.Where(x => x.UserId == id).FirstOrDefault();
-                var userinroles = db.aspnet_UsersInRoles.Where(x => x.UserId == id).ToList<aspnet_UsersInRole>();
-                try
-                {
-                    db.aspnet_UsersInRoles.DeleteAllOnSubmit(userinroles);
-                    db.aspnet_Memberships.DeleteOnSubmit(membership);
-                    db.aspnet_Users.DeleteOnSubmit(user);
-                    db.SubmitChanges();
-                }
-                catch (Exception ex)
-                {
-                    return false;
-                }
-                return true;
-
-            }
-            return false;
-        }
-
-
-        public bool UpdateUser(User user)
-        {
-            if (user != null)
-            {
-                using (UserManagementDataContext db = new UserManagementDataContext())
-                {
-
-                    var eUser = db.aspnet_Users.Where(x => x.UserId == user.Id).FirstOrDefault();
-                    var eMembership = db.aspnet_Memberships.Where(x => x.UserId == user.Id).FirstOrDefault();
-                    Convert.ToEntity(user, eUser, eMembership);
-                    try
-                    {
-
-                        db.SubmitChanges();
-                    }
-                    catch (Exception ex)
-                    {
-                        return false;
-                    }
-
-                    return true;
-
-                }
-
-            }
-            return false;
-        }
-
-
-        public bool AddUserToRole(Guid roleId, Guid userId) {
-          using (UserManagementDataContext db = new UserManagementDataContext()) {
-            try {
-              aspnet_UsersInRole r = new aspnet_UsersInRole();
-              r.RoleId = roleId;
-              r.UserId = userId;
-              db.aspnet_UsersInRoles.InsertOnSubmit(r);
-              db.SubmitChanges();
-              return true;
-            }
-            catch (Exception ex) {
-              Debug.WriteLine(ex.InnerException);
-              return false;
-            }
-          }
-        }
-
-        public IEnumerable<Guid> GetUsersInRole(Guid roleId) {
-          List<Guid> userList = new List<Guid>();
-          using (UserManagementDataContext db = new UserManagementDataContext()) {
-            try {
-              var users = db.aspnet_UsersInRoles.Where(x => x.RoleId == roleId).ToList<aspnet_UsersInRole>();
-
-              foreach (aspnet_UsersInRole u in users) {
-                userList.Add(GetUser(u.UserId).Id);
-              }
-
-            }
-            catch (Exception ex) {
-              Debug.WriteLine(ex.InnerException);
-              return new List<Guid>();
-
-            }
-
-          }
-
-          return userList;
-        }
-
-      /*
-        public IEnumerable<User> GetUsersInRole(Guid roleId) {
-          List<User> userList = new List<User>();
-          using (UserManagementDataContext db = new UserManagementDataContext()) {
-            try {
-              var users = db.aspnet_UsersInRoles.Where(x => x.RoleId == roleId).ToList<aspnet_UsersInRole>();
-
-              foreach (aspnet_UsersInRole u in users) {
-                userList.Add(GetUser(u.UserId));
-
-              }
-
-            }
-            catch (Exception ex) {
-              Debug.WriteLine(ex.InnerException);
-              return new List<User>();
-            }
-          }
-
-          return userList;
-        }
-       */
-
-        public bool IsUserInRole(Guid userId, Guid roleId) {
-          bool isInRole = false;
-          using (UserManagementDataContext db = new UserManagementDataContext()) {
-            var users = db.aspnet_UsersInRoles.Where(x => x.RoleId == roleId && x.UserId == userId).ToList<aspnet_UsersInRole>();
-            foreach (aspnet_UsersInRole u in users) {
-              isInRole = true;
-            }
-          }
-          return isInRole;
-
-        }
-
-
-        public bool RemoveUserFromRole(Guid roleId, Guid userId) {
-          using (UserManagementDataContext db = new UserManagementDataContext()) {
-            try {
-              var role = db.aspnet_UsersInRoles.Where(x => x.RoleId == roleId && x.UserId == userId).FirstOrDefault();
-
-              db.aspnet_UsersInRoles.DeleteOnSubmit(role);
-              db.SubmitChanges();
-              return true;
-
-            }
-            catch (Exception ex) {
-              Debug.WriteLine(ex.InnerException);
-              return false;
-            }
-          }
-
-        }
-
-
-
-
-        #endregion
-
-
-
-        #region Role
-
-        public Role GetRole(Guid id)
-        {
-            using (UserManagementDataContext db = new UserManagementDataContext())
-            {
-                var role = db.aspnet_Roles.Where(x => x.RoleId == id).FirstOrDefault();
-                return Convert.ToDataTransfer(role);
-            }
-        }
-
-        public IEnumerable<Role> GetAllRoles() {
-          List<DataTransfer.Role> roleList = new List<DataTransfer.Role>();
-          using (UserManagementDataContext db = new UserManagementDataContext()) {
-            var roles = db.aspnet_Roles.ToList<aspnet_Role>();
-            foreach (aspnet_Role role in roles) {
-              roleList.Add(Convert.ToDataTransfer(role));
-            }
-          }
-          return roleList;
-        }
-
-        public IEnumerable<Role> GetRoles(Guid applicationId)
-        {
-            List<DataTransfer.Role> roleList = new List<DataTransfer.Role>();
-            using (UserManagementDataContext db = new UserManagementDataContext())
-            {
-                var roles = db.aspnet_Roles.Where(x => x.ApplicationId == applicationId).ToList<aspnet_Role>();
-
-                foreach (aspnet_Role role in roles)
-                {
-                    roleList.Add(Convert.ToDataTransfer(role));
-                }
-
-            }
-            return roleList;
-        }
-
-        public Guid AddRole(Role role)
-        {
-
-            if (role != null)
-            {
-                using (UserManagementDataContext db = new UserManagementDataContext())
-                {
-
-                    aspnet_Role eRole = new aspnet_Role();
-
-                    Convert.ToEntity(role, eRole);
-                    try
-                    {
-                        db.aspnet_Roles.InsertOnSubmit(eRole);
-                        db.SubmitChanges();
-                    }
-                    catch (Exception ex)
-                    {
-                        return Guid.Empty;
-                    }
-
-                    return role.Id;
-                }
-
-            }
-            return Guid.Empty;
-        }
-
-        public bool DeleteRole(Guid id)
-        {
-            using (UserManagementDataContext db = new UserManagementDataContext())
-            {
-                var role = db.aspnet_Roles.Where(x => x.RoleId == id).FirstOrDefault();
-
-
-                try
-                {
-                    db.aspnet_Roles.DeleteOnSubmit(role);
-                    db.SubmitChanges();
-                }
-                catch (Exception ex)
-                {
-                    return false;
-                }
-                return true;
-
-
-            }
-        }
-
-        public IEnumerable<Guid> GetRolesForUser(Guid userId) {
-          List<Guid> roleList = new List<Guid>();
-          using (UserManagementDataContext db = new UserManagementDataContext()) {
-            try {
-              var roles = db.aspnet_UsersInRoles.Where(x => x.UserId == userId).ToList<aspnet_UsersInRole>();
-              foreach (aspnet_UsersInRole r in roles) {
-                roleList.Add(GetRole(r.RoleId).Id);
-              }
-            }
-            catch (Exception ex) {
-              Debug.WriteLine(ex.InnerException);
-              return new List<Guid>();
-            }
-          }
-
-          return roleList;
-
-        }
-
-       /*
-        public IEnumerable<Role> GetRolesForUser(Guid userId)
-        {
-            List<Role> roleList = new List<Role>();
-            using (UserManagementDataContext db = new UserManagementDataContext())
-            {
-                try
-                {
-                    var roles = db.aspnet_UsersInRoles.Where(x => x.UserId == userId).ToList<aspnet_UsersINRole>();
-
-                    foreach (aspnet_UsersInRole r in roles)
-                    {
-                        roleList.Add(GetRole(r.RoleId));
-
-                    }
-
-                }
-                catch (Exception ex)
-                {
-                    Debug.WriteLine(ex.InnerException);
-                    return new List<Role>();
-                }
-            }
-
-            return roleList;
-        }
-         */
-
-
-
-        public bool UpdateRole(Role role)
-        {
-            if (role != null)
-            {
-                using (UserManagementDataContext db = new UserManagementDataContext())
-                {
-
-                    var eRole = db.aspnet_Roles.Where(x => x.RoleId == role.Id).FirstOrDefault();
-
-                    Convert.ToEntity(role, eRole);
-                    try
-                    {
-
-                        db.SubmitChanges();
-                    }
-                    catch (Exception ex)
-                    {
-                        return false;
-                    }
-
-                    return true;
-
-                }
-
-            }
-            return false;
-        }
-
-
-
-        #endregion
-
-
-
-        #region Application
-
-        public Guid AddApplication(Application application)
-        {
-            if (application != null)
-            {
-                using (UserManagementDataContext db = new UserManagementDataContext())
-                {
-
-                    aspnet_Application eApplication = new aspnet_Application();
-
-                    Convert.ToEntity(application, eApplication);
-                    try
-                    {
-                        db.aspnet_Applications.InsertOnSubmit(eApplication);
-                        db.SubmitChanges();
-                    }
-                    catch (Exception ex)
-                    {
-                        return Guid.Empty;
-                    }
-
-                    return application.Id;
-
-                }
-
-            }
-            return Guid.Empty;
-        }
-
-        public bool UpdateApplication(Application application)
-        {
-            if (application != null)
-            {
-                using (UserManagementDataContext db = new UserManagementDataContext())
-                {
-
-                    var eApplication = db.aspnet_Applications.Where(x => x.ApplicationId == application.Id).FirstOrDefault();
-
-                    Convert.ToEntity(application, eApplication);
-                    try
-                    {
-
-                        db.SubmitChanges();
-                    }
-                    catch (Exception ex)
-                    {
-                        return false;
-                    }
-
-                    return true;
-
-                }
-
-            }
-            return false;
-        }
-
-
-        public bool DeleteApplication(Guid applicationId)
-        {
-            using (UserManagementDataContext db = new UserManagementDataContext())
-            {
-                var users = db.aspnet_Users.Where(x => x.ApplicationId == applicationId).ToList<aspnet_User>();
-                var memberships = db.aspnet_Memberships.Where(x => x.ApplicationId == applicationId).ToList<aspnet_Membership>();
-
-                var roles = db.aspnet_Roles.Where(x => x.ApplicationId == applicationId).ToList<aspnet_Role>();
-                var application = db.aspnet_Applications.Where(x => x.ApplicationId == applicationId).FirstOrDefault();
-
-                try
-                {
-                    foreach (aspnet_User u in users)
-                    {
-                        var userinroles = db.aspnet_UsersInRoles.Where(x => x.UserId == u.UserId).ToList<aspnet_UsersInRole>();
-                        db.aspnet_UsersInRoles.DeleteAllOnSubmit(userinroles);
-                    }
-
-                    db.aspnet_Memberships.DeleteAllOnSubmit(memberships);
-                    db.aspnet_Users.DeleteAllOnSubmit(users);
-                    db.aspnet_Roles.DeleteAllOnSubmit(roles);
-                    db.aspnet_Applications.DeleteOnSubmit(application);
-                    db.SubmitChanges();
-                }
-                catch (Exception ex)
-                {
-                    return false;
-                }
-                return true;
-
-
-            }
-            return false;
-        }
-
-        public Application GetApplication(Guid id)
-        {
-            using (UserManagementDataContext db = new UserManagementDataContext())
-            {
-                var application = db.aspnet_Applications.Where(x => x.ApplicationId == id).FirstOrDefault();
-                return Convert.ToDataTransfer(application);
-            }
-        }
-
-        public IEnumerable<DataTransfer.Application> GetApplications()
-        {
-            List<DataTransfer.Application> applicationList = new List<DataTransfer.Application>();
-            using (UserManagementDataContext db = new UserManagementDataContext())
-            {
-                var apps = db.aspnet_Applications.ToList<aspnet_Application>();
-
-                foreach (aspnet_Application app in apps)
-                {
-                    applicationList.Add(Convert.ToDataTransfer(app));
-                }
-
-            }
-            return applicationList;
-        }
-
-        #endregion
-    }
-
+namespace HeuristicLab.Services.Authentication {
+  [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
+  public class AuthenticationService : IAuthenticationService {
+
+    #region User
+
+    public DataTransfer.User GetUser(Guid id) {
+      using (UserManagementDataContext db = new UserManagementDataContext()) {
+        var user = db.aspnet_Users.FirstOrDefault(x => x.UserId == id);
+        var membership = db.aspnet_Memberships.Where(x => x.UserId == id).FirstOrDefault();
+        return Convert.ToDto(user, membership);
+      }
+    }
+
+    public IEnumerable<User> GetUsers() {
+      using (UserManagementDataContext db = new UserManagementDataContext()) {
+        var users = db.aspnet_Users.OrderBy(x => x.UserId).ToList().Zip(db.aspnet_Memberships.OrderBy(x => x.UserId), (x, y) => Convert.ToDto(x, y));
+        return users;
+      }
+    }
+
+
+    public IEnumerable<User> GetUsersForApplication(Guid applicationId) {
+      using (UserManagementDataContext db = new UserManagementDataContext()) {
+        var users = db.aspnet_Users.Where(x => x.ApplicationId == applicationId).OrderBy(x => x.UserId).ToList().Zip(db.aspnet_Memberships.Where(x => x.ApplicationId == applicationId).OrderBy(x => x.UserId), (x, y) => Convert.ToDto(x, y)).ToArray();
+        return users;
+      }
+    }
+
+
+    public Guid AddUser(User user) {
+      if (user != null) {
+        using (UserManagementDataContext db = new UserManagementDataContext()) {
+          aspnet_User eUser;
+          aspnet_Membership eMembership;
+          user.Id = Guid.NewGuid();
+          Convert.ToEntity(user, out eUser, out  eMembership);
+          db.aspnet_Users.InsertOnSubmit(eUser);
+          db.aspnet_Memberships.InsertOnSubmit(eMembership);
+          db.SubmitChanges();
+          return user.Id;
+        }
+      }
+      return Guid.Empty;
+
+    }
+
+    public void DeleteUser(Guid id) {
+      using (UserManagementDataContext db = new UserManagementDataContext()) {
+        var user = db.aspnet_Users.Where(x => x.UserId == id).FirstOrDefault();
+        var membership = db.aspnet_Memberships.Where(x => x.UserId == id).FirstOrDefault();
+        var userinroles = db.aspnet_UsersInRoles.Where(x => x.UserId == id).ToList<aspnet_UsersInRole>();
+        db.aspnet_UsersInRoles.DeleteAllOnSubmit(userinroles);
+        db.aspnet_Memberships.DeleteOnSubmit(membership);
+        db.aspnet_Users.DeleteOnSubmit(user);
+        db.SubmitChanges();
+      }
+
+    }
+
+
+    public void UpdateUser(User user) {
+      using (UserManagementDataContext db = new UserManagementDataContext()) {
+        var eUser = db.aspnet_Users.Where(x => x.UserId == user.Id).FirstOrDefault();
+        var eMembership = db.aspnet_Memberships.Where(x => x.UserId == user.Id).FirstOrDefault();
+        Convert.ToEntity(user, eUser, eMembership);
+        db.SubmitChanges();
+      }
+    }
+
+
+    public void AddUserToRole(Guid roleId, Guid userId) {
+      using (UserManagementDataContext db = new UserManagementDataContext()) {
+        aspnet_UsersInRole r = new aspnet_UsersInRole();
+        r.RoleId = roleId;
+        r.UserId = userId;
+        db.aspnet_UsersInRoles.InsertOnSubmit(r);
+        db.SubmitChanges();
+      }
+    }
+
+
+
+    public IEnumerable<Guid> GetUsersInRole(Guid roleId) {
+      using (UserManagementDataContext db = new UserManagementDataContext()) {
+        List<Guid> userList = new List<Guid>();
+        var users = db.aspnet_UsersInRoles.Where(x => x.RoleId == roleId).ToList<aspnet_UsersInRole>();
+        foreach (aspnet_UsersInRole u in users) {
+          userList.Add(GetUser(u.UserId).Id);
+        }
+        return userList;
+      }
+    }
+
+
+    public bool IsUserInRole(Guid userId, Guid roleId) {
+      using (UserManagementDataContext db = new UserManagementDataContext()) {
+        bool isInRole = false;
+        var users = db.aspnet_UsersInRoles.Where(x => x.RoleId == roleId && x.UserId == userId).ToList<aspnet_UsersInRole>();
+        foreach (aspnet_UsersInRole u in users) {
+          isInRole = true;
+        }
+        return isInRole;
+      }
+    }
+
+
+    public void RemoveUserFromRole(Guid roleId, Guid userId) {
+      using (UserManagementDataContext db = new UserManagementDataContext()) {
+        var role = db.aspnet_UsersInRoles.Where(x => x.RoleId == roleId && x.UserId == userId).FirstOrDefault();
+        db.aspnet_UsersInRoles.DeleteOnSubmit(role);
+        db.SubmitChanges();
+      }
+    }
+
+
+    // TODO !!!
+    public User ResetPassword(string applicationName, string userName, string password) {
+
+      string salt = "";
+      string answer = "";
+
+      using (UserManagementDataContext db = new UserManagementDataContext()) {
+        db.aspnet_Membership_ResetPassword(applicationName, userName, password, null, null, salt, null, null, answer);
+        return null;
+      }
+    }
+
+    #endregion
+
+    #region Role
+
+    public Role GetRole(Guid id) {
+      using (UserManagementDataContext db = new UserManagementDataContext()) {
+        var role = db.aspnet_Roles.Where(x => x.RoleId == id).FirstOrDefault();
+        return Convert.ToDto(role);
+      }
+    }
+
+    public IEnumerable<Role> GetRoles() {
+
+      using (UserManagementDataContext db = new UserManagementDataContext()) {
+        List<DataTransfer.Role> roleList = new List<DataTransfer.Role>();
+        var roles = db.aspnet_Roles.ToList<aspnet_Role>();
+        foreach (aspnet_Role role in roles) {
+          roleList.Add(Convert.ToDto(role));
+        }
+        return roleList;
+      }
+
+    }
+
+    public IEnumerable<Role> GetRolesForApplication(Guid applicationId) {
+      using (UserManagementDataContext db = new UserManagementDataContext()) {
+        List<Role> roleList = new List<Role>();
+        var roles = db.aspnet_Roles.Where(x => x.ApplicationId == applicationId).ToList<aspnet_Role>();
+        foreach (aspnet_Role role in roles) {
+          roleList.Add(Convert.ToDto(role));
+        }
+        return roleList;
+      }
+    }
+
+    public Guid AddRole(Role role) {
+      if (role != null) {
+        using (UserManagementDataContext db = new UserManagementDataContext()) {
+          aspnet_Role eRole = new aspnet_Role();
+          role.Id = Guid.NewGuid();
+          Convert.ToEntity(role, eRole);
+          db.aspnet_Roles.InsertOnSubmit(eRole);
+          db.SubmitChanges();
+          return role.Id;
+        }
+      }
+      return Guid.Empty;
+    }
+
+    public void DeleteRole(Guid id) {
+      using (UserManagementDataContext db = new UserManagementDataContext()) {
+        var role = db.aspnet_Roles.Where(x => x.RoleId == id).FirstOrDefault();
+        var userinroles = db.aspnet_UsersInRoles.Where(x => x.RoleId == id).ToList<aspnet_UsersInRole>();
+        db.aspnet_UsersInRoles.DeleteAllOnSubmit(userinroles);
+        db.aspnet_Roles.DeleteOnSubmit(role);
+        db.SubmitChanges();
+      }
+    }
+
+    public IEnumerable<Guid> GetRolesForUser(Guid userId) {
+      using (UserManagementDataContext db = new UserManagementDataContext()) {
+        List<Guid> roleList = new List<Guid>();
+        var roles = db.aspnet_UsersInRoles.Where(x => x.UserId == userId).ToList<aspnet_UsersInRole>();
+        foreach (aspnet_UsersInRole r in roles) {
+          roleList.Add(GetRole(r.RoleId).Id);
+        }
+        return roleList;
+      }
+    }
+
+    public void UpdateRole(Role role) {
+      using (UserManagementDataContext db = new UserManagementDataContext()) {
+        var eRole = db.aspnet_Roles.Where(x => x.RoleId == role.Id).FirstOrDefault();
+        Convert.ToEntity(role, eRole);
+        db.SubmitChanges();
+      }
+    }
+
+    #endregion
+
+    #region Application
+
+    public Guid AddApplication(Application application) {
+      if (application != null) {
+        using (UserManagementDataContext db = new UserManagementDataContext()) {
+          aspnet_Application eApplication = new aspnet_Application();
+          application.Id = Guid.NewGuid();
+          Convert.ToEntity(application, eApplication);
+          db.aspnet_Applications.InsertOnSubmit(eApplication);
+          db.SubmitChanges();
+          return application.Id;
+        }
+      }
+      return Guid.Empty;
+    }
+
+    public void UpdateApplication(Application application) {
+      using (UserManagementDataContext db = new UserManagementDataContext()) {
+        var eApplication = db.aspnet_Applications.Where(x => x.ApplicationId == application.Id).FirstOrDefault();
+        Convert.ToEntity(application, eApplication);
+        db.SubmitChanges();
+      }
+    }
+
+
+    public void DeleteApplication(Guid applicationId) {
+      using (UserManagementDataContext db = new UserManagementDataContext()) {
+        var users = db.aspnet_Users.Where(x => x.ApplicationId == applicationId).ToList<aspnet_User>();
+        var memberships = db.aspnet_Memberships.Where(x => x.ApplicationId == applicationId).ToList<aspnet_Membership>();
+        var roles = db.aspnet_Roles.Where(x => x.ApplicationId == applicationId).ToList<aspnet_Role>();
+        var application = db.aspnet_Applications.Where(x => x.ApplicationId == applicationId).FirstOrDefault();
+        foreach (aspnet_User u in users) {
+          var userinroles = db.aspnet_UsersInRoles.Where(x => x.UserId == u.UserId).ToList<aspnet_UsersInRole>();
+          db.aspnet_UsersInRoles.DeleteAllOnSubmit(userinroles);
+        }
+        db.aspnet_Memberships.DeleteAllOnSubmit(memberships);
+        db.aspnet_Users.DeleteAllOnSubmit(users);
+        db.aspnet_Roles.DeleteAllOnSubmit(roles);
+        db.aspnet_Applications.DeleteOnSubmit(application);
+        db.SubmitChanges();
+      }
+    }
+
+    public Application GetApplication(Guid id) {
+      using (UserManagementDataContext db = new UserManagementDataContext()) {
+        var application = db.aspnet_Applications.Where(x => x.ApplicationId == id).FirstOrDefault();
+        return Convert.ToDto(application);
+      }
+    }
+
+    public IEnumerable<Application> GetApplications() {
+      List<Application> applicationList = new List<Application>();
+      using (UserManagementDataContext db = new UserManagementDataContext()) {
+        var apps = db.aspnet_Applications.ToList<aspnet_Application>();
+        foreach (aspnet_Application app in apps) {
+          applicationList.Add(Convert.ToDto(app));
+        }
+      }
+      return applicationList;
+    }
+    #endregion
+  }
 }
-
Index: branches/UserManagement/HeuristicLab.Services.Authentication/Convert.cs
===================================================================
--- branches/UserManagement/HeuristicLab.Services.Authentication/Convert.cs	(revision 4979)
+++ branches/UserManagement/HeuristicLab.Services.Authentication/Convert.cs	(revision 5257)
@@ -1,159 +1,171 @@
-﻿using HeuristicLab.Services.Authentication.DataAccess;
+﻿#region License Information
+/* HeuristicLab 
+ * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 
+ * 
+ * This file is part of HeuristicLab. 
+ * 
+ * HeuristicLab is free software: you can redistribute it and/or modify 
+ * it under the terms of the GNU General Public License as published by 
+ * the Free Software Foundation, either version 3 of the License, or 
+ * (at your option) any later version. 
+ * 
+ * HeuristicLab is distributed in the hope that it will be useful, 
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of 
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
+ * GNU General Public License for more details. 
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 
+ */
+#endregion
+using HeuristicLab.Services.Authentication.DataAccess;
 using HeuristicLab.Services.Authentication.DataTransfer;
 
-namespace HeuristicLab.Services.Authentication
-{
-    public class Convert
-    {
+namespace HeuristicLab.Services.Authentication {
+  public class Convert {
 
-        #region User
+    #region User
 
-        /// <summary>
-        /// converts data access object to data transfer object
-        /// </summary>
-        /// <param name="source">data access object</param>
-        /// <returns>data transfer object</returns>
-        public static User ToDataTransfer(aspnet_User userSource, aspnet_Membership membershipSource)
-        {
-            if (userSource == null || membershipSource == null) return null;
-            return new User()
-            {
-                ApplicationId = userSource.ApplicationId,
-                Id = userSource.UserId,
-                Name = userSource.UserName,
-                //LoweredUserName = userSource.LoweredUserName,
-                //IsAnonymous = userSource.IsAnonymous,
-                LastActivityDate = userSource.LastActivityDate,
-                Password = membershipSource.Password,
-                PasswordSalt = membershipSource.PasswordSalt,
-                Email = membershipSource.Email,
-                IsApproved = membershipSource.IsApproved,
-                IsLookedOut = membershipSource.IsApproved,
-                CreateDate = membershipSource.CreateDate,
-                LastLoginDate = membershipSource.LastLoginDate,
-                LastPasswordChangeDate = membershipSource.LastPasswordChangedDate,
-                LastLockoutDate = membershipSource.LastLockoutDate,
-                Comment = membershipSource.Comment
-            };
-        }
+    public static User ToDto(aspnet_User sourceUser, aspnet_Membership sourceMembership) {
+      if (sourceUser == null || sourceMembership == null) return null;
+      return new User() {
+        ApplicationId = sourceUser.ApplicationId,
+        Id = sourceUser.UserId,
+        Name = sourceUser.UserName,
+        LastActivityDate = sourceUser.LastActivityDate,
+        Email = sourceMembership.Email,
+        IsApproved = sourceMembership.IsApproved,
+        IsLookedOut = sourceMembership.IsApproved,
+        CreateDate = sourceMembership.CreateDate,
+        LastLoginDate = sourceMembership.LastLoginDate,
+        LastPasswordChangeDate = sourceMembership.LastPasswordChangedDate,
+        LastLockoutDate = sourceMembership.LastLockoutDate,
+        Description = sourceMembership.Comment
+      };
+    }
 
-        /// <summary>
-        /// converts data transfer object to data access object
-        /// </summary>
-        /// <param name="source">data transfer object</param>
-        /// <param name="target">data access object</param>
-        public static void ToEntity(User source, aspnet_User userTarget, aspnet_Membership membershipTarget)
-        {
-            if ((source != null) && (userTarget != null) && (membershipTarget != null))
-            {
-                userTarget.ApplicationId = source.ApplicationId;
-                membershipTarget.ApplicationId = source.ApplicationId;
-                userTarget.UserId = source.Id;
-                membershipTarget.UserId = source.Id;
-                userTarget.UserName = source.Name;
-                userTarget.LoweredUserName = source.Name;
-                userTarget.IsAnonymous = false;
-                userTarget.LastActivityDate = source.LastActivityDate;
-                membershipTarget.Password = source.Password;
-                membershipTarget.PasswordFormat = 1;
-                membershipTarget.PasswordSalt = source.PasswordSalt;
-                membershipTarget.Email = source.Email;
-                membershipTarget.IsApproved = source.IsApproved;
-                membershipTarget.IsLockedOut = source.IsLookedOut;
-                membershipTarget.CreateDate = source.CreateDate;
-                membershipTarget.LastLoginDate = source.LastLoginDate;
-                membershipTarget.LastPasswordChangedDate = source.LastPasswordChangeDate;
-                membershipTarget.LastLockoutDate = source.LastLockoutDate;
-                membershipTarget.FailedPasswordAttemptCount = 0;
-                membershipTarget.FailedPasswordAttemptWindowStart = new System.DateTime(1900, 01, 01);
-                membershipTarget.FailedPasswordAnswerAttemptCount = 0;
-                membershipTarget.FailedPasswordAnswerAttemptWindowStart = new System.DateTime(1900, 01, 01);
-                membershipTarget.Comment = source.Comment;
+    public static void ToEntity(User sourceUser, aspnet_User targetUser, aspnet_Membership targetMembership) {
+      if ((sourceUser != null) && (targetUser != null) && (targetMembership != null)) {
+        targetUser.ApplicationId = sourceUser.ApplicationId;
+        targetUser.UserId = sourceUser.Id;
+        targetUser.UserName = sourceUser.Name;
+        targetUser.LoweredUserName = sourceUser.Name;
+        targetUser.IsAnonymous = false;
+        targetUser.LastActivityDate = sourceUser.LastActivityDate;
+        targetMembership.UserId = sourceUser.Id;
+        targetMembership.ApplicationId = sourceUser.ApplicationId;
+        targetMembership.PasswordFormat = 1;
+        targetMembership.Email = sourceUser.Email;
+        targetMembership.IsApproved = sourceUser.IsApproved;
+        targetMembership.IsLockedOut = sourceUser.IsLookedOut;
+        targetMembership.CreateDate = sourceUser.CreateDate;
+        targetMembership.LastLoginDate = sourceUser.LastLoginDate;
+        targetMembership.LastPasswordChangedDate = sourceUser.LastPasswordChangeDate;
+        targetMembership.LastLockoutDate = sourceUser.LastLockoutDate;
+        targetMembership.FailedPasswordAttemptCount = 0;
+        targetMembership.FailedPasswordAttemptWindowStart = new System.DateTime(1900, 01, 01);
+        targetMembership.FailedPasswordAnswerAttemptCount = 0;
+        targetMembership.FailedPasswordAnswerAttemptWindowStart = new System.DateTime(1900, 01, 01);
+        targetMembership.Comment = sourceUser.Description;
+      }
+    }
 
-            }
+    public static void ToEntity(User source, out aspnet_User userTarget, out aspnet_Membership membershipTarget) {
+      userTarget = new aspnet_User();
+      membershipTarget = new aspnet_Membership();
 
-        }
+      if ((source != null)) {
+        userTarget.ApplicationId = source.ApplicationId;
+        userTarget.UserId = source.Id;
+        userTarget.UserName = source.Name;
+        userTarget.LoweredUserName = source.Name;
+        userTarget.IsAnonymous = false;
+        userTarget.LastActivityDate = source.LastActivityDate;
+        membershipTarget.UserId = source.Id;
+        membershipTarget.ApplicationId = source.ApplicationId;
+        membershipTarget.PasswordFormat = 1;
+        membershipTarget.Email = source.Email;
+        membershipTarget.IsApproved = source.IsApproved;
+        membershipTarget.IsLockedOut = source.IsLookedOut;
+        membershipTarget.CreateDate = source.CreateDate;
+        membershipTarget.LastLoginDate = source.LastLoginDate;
+        membershipTarget.LastPasswordChangedDate = source.LastPasswordChangeDate;
+        membershipTarget.LastLockoutDate = source.LastLockoutDate;
+        membershipTarget.FailedPasswordAttemptCount = 0;
+        membershipTarget.FailedPasswordAttemptWindowStart = new System.DateTime(1900, 01, 01);
+        membershipTarget.FailedPasswordAnswerAttemptCount = 0;
+        membershipTarget.FailedPasswordAnswerAttemptWindowStart = new System.DateTime(1900, 01, 01);
+        membershipTarget.Comment = source.Description;
+      }
+    }
 
+    #endregion
 
-        #endregion
+    #region Application
 
-        #region Application
+    public static Application ToDto(aspnet_Application sourceApplication) {
+      if (sourceApplication == null) return null;
+      return new Application() {
+        Id = sourceApplication.ApplicationId,
+        Name = sourceApplication.ApplicationName,
+        Description = sourceApplication.Description
+      };
+    }
 
-        /// <summary>
-        /// converts data access object to data transfer object
-        /// </summary>
-        /// <param name="source">data access object</param>
-        /// <returns>data transfer object</returns>
-        public static Application ToDataTransfer(aspnet_Application source)
-        {
-            if (source == null) return null;
-            return new Application()
-            {
-                Id = source.ApplicationId,
-                Name = source.ApplicationName,
-                //LoweredApplicationName = source.LoweredApplicationName,
-                Description = source.Description
-            };
-        }
+    public static void ToEntity(Application sourceApplication, aspnet_Application targetApplication) {
+      if ((sourceApplication != null) && (targetApplication != null)) {
+        targetApplication.ApplicationId = sourceApplication.Id;
+        targetApplication.ApplicationName = sourceApplication.Name;
+        targetApplication.LoweredApplicationName = sourceApplication.Name.ToLower();
+        targetApplication.Description = sourceApplication.Description;
+      }
+    }
 
-        /// <summary>
-        /// converts data transfer object to data access object
-        /// </summary>
-        /// <param name="source">data transfer object</param>
-        /// <param name="target">data access object</param>
-        public static void ToEntity(Application source, aspnet_Application target)
-        {
-            if ((source != null) && (target != null))
-            {
-                target.ApplicationId = source.Id;
-                target.ApplicationName = source.Name;
-                target.LoweredApplicationName = source.Name.ToLower();
-                target.Description = source.Description;
-            }
+    public static aspnet_Application ToEntity(Application sourceApplication) {
+      if (sourceApplication == null) return null;
+      return new aspnet_Application() {
+        ApplicationId = sourceApplication.Id,
+        ApplicationName = sourceApplication.Name,
+        LoweredApplicationName = sourceApplication.Name.ToLower(),
+        Description = sourceApplication.Description
+      };
+    }
 
-        }
+    #endregion
 
-        #endregion
+    #region Role
 
-        #region Role
+    public static Role ToDto(aspnet_Role sourceRole) {
+      if (sourceRole == null) return null;
+      return new Role() {
+        ApplicationId = sourceRole.ApplicationId,
+        Id = sourceRole.RoleId,
+        Name = sourceRole.RoleName,
+        Description = sourceRole.Description,
+      };
+    }
 
-        /// <summary>
-        /// converts data access object to data transfer object
-        /// </summary>
-        /// <param name="source">data access object</param>
-        /// <returns>data transfer object</returns>
-        public static Role ToDataTransfer(aspnet_Role source)
-        {
-            if (source == null) return null;
-            return new Role()
-            {
-                ApplicationId = source.ApplicationId,
-                Id = source.RoleId,
-                Name = source.RoleName,
-                Description = source.Description,
-                //LoweredRoleName = source.LoweredRoleName,
-            };
-        }
+    public static void ToEntity(Role sourceRole, aspnet_Role targetRole) {
+      if ((sourceRole != null) && (targetRole != null)) {
+        targetRole.ApplicationId = sourceRole.ApplicationId;
+        targetRole.RoleId = sourceRole.Id;
+        targetRole.RoleName = sourceRole.Name;
+        targetRole.LoweredRoleName = sourceRole.Name.ToLower();
+        targetRole.Description = sourceRole.Description;
+      }
+    }
 
-        /// <summary>
-        /// converts data transfer object to data access object
-        /// </summary>
-        /// <param name="source">data transfer object</param>
-        /// <param name="target">data access object</param>
-        public static void ToEntity(Role source, aspnet_Role target)
-        {
-            if ((source != null) && (target != null))
-            {
-                target.ApplicationId = source.ApplicationId;
-                target.RoleId = source.Id;
-                target.RoleName = source.Name;
-                target.LoweredRoleName = source.Name.ToLower();
-                target.Description = source.Description;
-            }
+    public static aspnet_Role ToEntity(Role sourceRole) {
+      if (sourceRole == null) return null;
+      return new aspnet_Role() {
+        ApplicationId = sourceRole.ApplicationId,
+        RoleId = sourceRole.Id,
+        RoleName = sourceRole.Name,
+        LoweredRoleName = sourceRole.Name.ToLower(),
+        Description = sourceRole.Description,
+      };
+    }
 
-        }
-
-        #endregion
-
-    }
+    #endregion
+  }
 }
Index: branches/UserManagement/HeuristicLab.Services.Authentication/Interfaces/IAuthenticationService.cs
===================================================================
--- branches/UserManagement/HeuristicLab.Services.Authentication/Interfaces/IAuthenticationService.cs	(revision 4979)
+++ branches/UserManagement/HeuristicLab.Services.Authentication/Interfaces/IAuthenticationService.cs	(revision 5257)
@@ -1,3 +1,23 @@
-﻿using System;
+﻿#region License Information
+/* HeuristicLab 
+ * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 
+ * 
+ * This file is part of HeuristicLab. 
+ * 
+ * HeuristicLab is free software: you can redistribute it and/or modify 
+ * it under the terms of the GNU General Public License as published by 
+ * the Free Software Foundation, either version 3 of the License, or 
+ * (at your option) any later version. 
+ * 
+ * HeuristicLab is distributed in the hope that it will be useful, 
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of 
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
+ * GNU General Public License for more details. 
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 
+ */
+#endregion
+using System;
 using System.Collections.Generic;
 using HeuristicLab.Services.Authentication.DataTransfer;
@@ -5,97 +25,88 @@
 using System.Net.Security;
 
-namespace HeuristicLab.Services.Authentication
-{
-    [ServiceContract(ProtectionLevel = ProtectionLevel.EncryptAndSign)]
-    public interface IAuthenticationService
-    {
-        #region User
+namespace HeuristicLab.Services.Authentication {
+  [ServiceContract(ProtectionLevel = ProtectionLevel.EncryptAndSign)]
+  public interface IAuthenticationService {
 
-        [OperationContract]
-        User GetUser(Guid id);
+    #region User
 
-        [OperationContract]
-        IEnumerable<User> GetAllUsers();
+    [OperationContract]
+    User GetUser(Guid id);
 
-        [OperationContract]
-        IEnumerable<User> GetUsers(Guid applicationId);
+    [OperationContract()]
+    IEnumerable<User> GetUsers();
 
-        [OperationContract]
-        Guid AddUser(User user);       
+    [OperationContract()]
+    IEnumerable<User> GetUsersForApplication(Guid applicationId);
 
-        [OperationContract]
-        bool DeleteUser(Guid id);
+    [OperationContract]
+    Guid AddUser(User user);
 
-        [OperationContract]
-        bool UpdateUser(User user);
+    [OperationContract]
+    void DeleteUser(Guid id);
 
-        [OperationContract]
-        bool AddUserToRole(Guid roleId, Guid userId);
+    [OperationContract]
+    void UpdateUser(User user);
 
-        [OperationContract]
-        IEnumerable<Guid> GetUsersInRole(Guid roleId);
+    [OperationContract]
+    void AddUserToRole(Guid roleId, Guid userId);
 
-        //[OperationContract]
-        //IEnumerable<User> GetUsersInRole(Guid roleId); // return = Guid
+    [OperationContract]
+    IEnumerable<Guid> GetUsersInRole(Guid roleId);
 
-        [OperationContract]
-        bool RemoveUserFromRole(Guid roleId, Guid userId);
+    [OperationContract]
+    void RemoveUserFromRole(Guid roleId, Guid userId);
 
-        [OperationContract]
-        bool IsUserInRole(Guid userId, Guid roleId);
+    [OperationContract]
+    bool IsUserInRole(Guid userId, Guid roleId);
 
-        #endregion
+    [OperationContract]
+    User ResetPassword(string applicationName, string userName, string password);
 
-        #region Role
+    #endregion
 
-        [OperationContract]
-        Role GetRole(Guid id);
+    #region Role
 
-        [OperationContract]
-        IEnumerable<Role> GetAllRoles();
+    [OperationContract]
+    Role GetRole(Guid id);
 
-        [OperationContract]
-        IEnumerable<Role> GetRoles(Guid applicationId);
+    [OperationContract()]
+    IEnumerable<Role> GetRoles();
 
-        [OperationContract]
-        Guid AddRole(Role role); 
+    [OperationContract()]
+    IEnumerable<Role> GetRolesForApplication(Guid applicationId);
 
-        [OperationContract]
-        bool UpdateRole(Role role);
+    [OperationContract]
+    Guid AddRole(Role role);
 
-        [OperationContract]
-        bool DeleteRole(Guid id);
+    [OperationContract]
+    void UpdateRole(Role role);
 
+    [OperationContract]
+    void DeleteRole(Guid id);
 
-        [OperationContract]
-        IEnumerable<Guid> GetRolesForUser(Guid userId);
+    [OperationContract]
+    IEnumerable<Guid> GetRolesForUser(Guid userId);
 
+    #endregion
 
-        //[OperationContract]
-        //IEnumerable<Role> GetRolesForUser(Guid userId);  // returnvalue = GUID
+    #region Application
 
-        #endregion
+    [OperationContract]
+    Application GetApplication(Guid id);
 
-        #region Application
+    [OperationContract]
+    Guid AddApplication(Application application);
 
-        [OperationContract]
-        Application GetApplication(Guid id);
+    [OperationContract]
+    void DeleteApplication(Guid id);
 
-        [OperationContract]
-        Guid AddApplication(Application application); // ADD
+    [OperationContract]
+    IEnumerable<Application> GetApplications();
 
-        [OperationContract]
-        bool DeleteApplication(Guid id);
+    [OperationContract]
+    void UpdateApplication(Application application);
 
-        [OperationContract]
-        IEnumerable<DataTransfer.Application> GetApplications();
-
-
-        [OperationContract]
-        bool UpdateApplication(Application application);
-
-        #endregion
-
-        
-    }
+    #endregion
+  }
 }
