public override void UpdateUser(MembershipUser user)
        {
            using (var transaction = new TransactionScope(_mConfiguration))
            {
                var  dataStore = new UserDataStore(transaction);
                User dbUser    = dataStore.FindByName(ApplicationName, user.UserName);
                if (dbUser == null)
                {
                    throw new UserNotFoundException(user.UserName);
                }

                //Check email
                if (RequiresUniqueEmail)
                {
                    if (string.IsNullOrEmpty(user.Email))
                    {
                        throw new EmailNotValidException(user.Email);
                    }

                    IList <User> emailUsers = dataStore.FindByEmail(ApplicationName, user.Email);
                    if (emailUsers.Count > 0 && emailUsers[0].Id != dbUser.Id)
                    {
                        throw new EmailDuplicatedException(user.Email);
                    }
                }

                dbUser.Comment = user.Comment;
                dbUser.Email   = user.Email;
                dbUser.Enabled = user.IsApproved;

                transaction.Commit();
            }
        }
        public override string GetUserNameByEmail(string email)
        {
            using (var transaction = new TransactionScope(_mConfiguration))
            {
                var          dataStore = new UserDataStore(transaction);
                IList <User> users     = dataStore.FindByEmail(ApplicationName, email);
                if (users.Count == 0)
                {
                    return(null);
                }

                return(users[0].Name);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="email"></param>
        /// <param name="passwordQuestion"></param>
        /// <param name="passwordAnswer"></param>
        /// <param name="isApproved"></param>
        /// <param name="providerUserKey">Not used</param>
        /// <param name="status"></param>
        /// <returns></returns>
        public override MembershipUser CreateUser(string username, string password,
                                                  string email, string passwordQuestion,
                                                  string passwordAnswer, bool isApproved,
                                                  object providerUserKey,
                                                  out MembershipCreateStatus status)
        {
            try
            {
                //Validate password
                ValidatePassword(username, password, true);

                using (var transaction = new TransactionScope(_mConfiguration))
                {
                    var dataStore = new UserDataStore(transaction);

                    //Check name
                    if (dataStore.FindByName(ApplicationName, username) != null)
                    {
                        status = MembershipCreateStatus.DuplicateUserName;
                        return(null);
                    }

                    //Check email
                    if (RequiresUniqueEmail)
                    {
                        if (string.IsNullOrEmpty(email))
                        {
                            status = MembershipCreateStatus.InvalidEmail;
                            return(null);
                        }
                        if (dataStore.FindByEmail(ApplicationName, email).Count > 0)
                        {
                            status = MembershipCreateStatus.DuplicateEmail;
                            return(null);
                        }
                    }


                    var user = new User(ApplicationName, username);
                    user.Email = email;
                    user.ChangePassword(password);
                    user.ChangePasswordQuestionAnswer(passwordQuestion, passwordAnswer);
                    user.Enabled = isApproved;

                    dataStore.Insert(user);

                    transaction.Commit();

                    status = MembershipCreateStatus.Success;
                    return(UserToMembershipUser(user));
                }
            }
            catch (CodeInvalidCharsException ex) //this exception is caused by an invalid user Name
            {
                LogException(ex, "CreateUser");
                status = MembershipCreateStatus.InvalidUserName;
                return(null);
            }
            catch (MembershipPasswordException ex)
            {
                LogException(ex, "CreateUser");
                status = MembershipCreateStatus.InvalidPassword;
                return(null);
            }
            catch (Exception ex)
            {
                LogException(ex, "CreateUser");
                status = MembershipCreateStatus.ProviderError;
                return(null);
            }
        }