public void Edit(User user)
        {
            MembershipUser membershipUser = Membership.GetUser(user.UserName);
            if(membershipUser != null)
            {
                membershipUser.Email = user.Email;
                Membership.UpdateUser(membershipUser);

                string[] newRoles = user.Roles.ToArray();
                string[] currentRoles = Roles.GetRolesForUser(user.UserName);

                string[] rolesToDelete = currentRoles.Except(newRoles).ToArray();
                string[] rolesToAdd = newRoles.Except(currentRoles).ToArray();

                if(rolesToDelete.Length > 0)
                    Roles.RemoveUserFromRoles(user.UserName, rolesToDelete);

                if (rolesToAdd.Length > 0)
                    Roles.AddUserToRoles(user.UserName, rolesToAdd);
            }
            else
            {
                throw new Exception(string.Format("Unknown user '{0}'.", user.UserName));
            }
        }
        public void Add(User user)
        {
            MembershipCreateStatus createStatus;

            Membership.CreateUser(user.UserName, user.Password, user.Email, user.SecurityQuestion,
                user.SecurityAnswer, true, out createStatus);

            if(createStatus != MembershipCreateStatus.Success)
                throw new Exception(string.Format("Error when creating user: {0}.", createStatus));
            else
            {
                Roles.AddUserToRoles(user.UserName, user.Roles.ToArray());
            }
        }