public int UpdateMembership(AspnetMembership membership)
 {
     _aspnetMembershipDao.Update(membership);
     if (membership != null)
         return 1;
     return 0;
 }
 public int SaveMembership(AspnetMembership user)
 {
     _aspnetMembershipDao.Save(user);
     if (user != null)
         return 1;
     return 0;
 }
 public void Delete(AspnetMembership membership)
 {
     CurrentSession.Delete(membership);
 }
 public void Update(AspnetMembership membership)
 {
     CurrentSession.Update(membership);
 }
 public Guid Save(AspnetMembership membership)
 {
     return (Guid)CurrentSession.Save(membership);
 }
        /// <summary>
        /// Adds a new membership user to the data source.
        /// </summary>
        /// <param name="username">the user name for the new user.</param>
        /// <param name="password">the password for the new user.</param>
        /// <param name="email">the e-mail address for the new user.</param>
        /// <param name="passwordQuestion">the password question for the new user.</param>
        /// <param name="passwordAnswer">the password answer for the new user.</param>
        /// <param name="isApproved">whether or not the new user is approved to be validated.</param>
        /// <param name="providerUserKey">the unique identifier from the membership data source for the user.</param>
        /// <param name="status">a <see cref="MembershipCreateStatus"/> enumeration value indicating whether the user was created successfully.</param>
        /// <returns>
        /// A <see cref="MembershipUser"/> object populated with the information for the newly created user.
        /// </returns>
        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion,
            string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            // Raise the ValidatingPassword event in case an event handler has been defined.
            ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(username, password, true);
            OnValidatingPassword(args);
            if (args.Cancel)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return null;
            }

            // Validate the e-mail address has not already been specified, if required.
            if (RequiresUniqueEmail && !string.IsNullOrEmpty(GetUserNameByEmail(email)))
            {
                status = MembershipCreateStatus.DuplicateEmail;
                return null;
            }

            ////// Attempt to get the user record associated to the given user name.
            //if (_userService.UserExists(username))
            //{
            //    // Indicate we have found an existing user record.
            //    status = MembershipCreateStatus.DuplicateUserName;
            //    return null;
            //}

            MembershipUser u = GetUser(username, false);

            if (u == null)
            {
                DateTime createDate = DateTime.Now;

                if (providerUserKey == null)
                {
                    //TODO: guid.comb generates auto the key.
                    providerUserKey = Guid.Empty;
                }
                else
                {
                    if (!(providerUserKey is Guid))
                    {
                        status = MembershipCreateStatus.InvalidProviderUserKey;
                        return null;
                    }
                }

                try
                {
                    // Insert user record in the data store.
                    AspnetMembership user = new AspnetMembership();
                    user.UserId = Guid.Empty;
                    user.UserName = username;
                    user.LoweredUserName = username.ToLowerInvariant();
                    user.LastActivityDate = DateTime.Now;
                    user.Password = EncodePassword(password);
                    user.PasswordFormat = (int)PasswordFormat;
                    user.PasswordSalt = machineKey.ValidationKey;
                    user.Email = email;
                    if (passwordQuestion != null)
                        user.PasswordQuestion = passwordQuestion;
                    if (passwordAnswer != null)
                        user.PasswordAnswer = EncodePassword(passwordAnswer);
                    user.IsApproved = isApproved;
                    user.AspnetApplication = application;
                    user.CreateDate = createDate;

                    int recAdded = _aspnetMembershipService.SaveMembership(user);

                    if (recAdded > 0)
                    {
                        status = MembershipCreateStatus.Success;
                    }
                    else
                    {
                        status = MembershipCreateStatus.UserRejected;
                    }

                }
                catch (Exception ex)
                {
                    if (WriteExceptionsToEventLog)
                    {
                        WriteToEventLog(ex, "CreateUser");
                    }
                    //throw ExceptionUtil.NewProviderException(this, Resources.User_UnableToCreate, ex);
                    status = MembershipCreateStatus.ProviderError;
                }

                return GetUser(username, false);

            }
            else
            {
                status = MembershipCreateStatus.DuplicateUserName;
            }
            return null;

            //// Attempt to get the user record associated to the given user name.
            //if (_userService.UserExists(username))
            //{
            //    // Indicate we have found an existing user record.
            //    status = MembershipCreateStatus.DuplicateUserName;
            //}
            //else
            //{
            //    // NOTE: providerUserKey is ignored on purpose. In this implementation it represents the user identifier.

            //    // Insert user record in the data store.
            //    User user = new User();
            //    user.Name = username;
            //    user.Password = EncodePassword(password, machineKey.ValidationKey);
            //    user.PasswordFormat = (int) PasswordFormat;
            //    user.PasswordSalt = machineKey.ValidationKey;
            //    user.Email = email;
            //    user.PasswordQuestion = passwordQuestion;
            //    user.PasswordAnswer = EncodePassword(passwordAnswer, machineKey.ValidationKey);
            //    user.IsApproved = isApproved;
            //    user.Applications.Add(application);
            //    try
            //    {
            //        _userService.UpdateUser(user);
            //        status = MembershipCreateStatus.Success;
            //    }
            //    catch (Exception ex)
            //    {
            //        //status = MembershipCreateStatus.UserRejected;
            //        throw ExceptionUtil.NewProviderException(this, Resources.User_UnableToCreate, ex);
            //    }

            //    // Return the newly created user record.
            //    return GetUser(username, false);
            //}

            //// Indicate we were unable to create the user record.
            //return null;
        }
 private MembershipUser ToMembershipUser(string Name, AspnetMembership membership)
 {
     MembershipUser user = new MembershipUser(Name, membership.UserName, membership.UserId, membership.Email, membership.PasswordQuestion,
         membership.Comment, membership.IsApproved, membership.IsLockedOut, membership.CreateDate, membership.LastLoginDate,
         membership.LastActivityDate, membership.LastPasswordChangedDate, membership.LastLockoutDate);
     return user;
 }