public override Sys.MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out Sys.MembershipCreateStatus status)
        {
            status = Sys.MembershipCreateStatus.Success;

            if (string.IsNullOrEmpty(username)) status = Sys.MembershipCreateStatus.InvalidUserName;
            //if (string.IsNullOrEmpty(email)) status = Sys.MembershipCreateStatus.InvalidEmail;
            if (!ValidPassword(password)) status = Sys.MembershipCreateStatus.InvalidPassword;
            if (RequiresQuestionAndAnswer) {
                if (string.IsNullOrEmpty(passwordQuestion)) status = Sys.MembershipCreateStatus.InvalidQuestion;
                if (string.IsNullOrEmpty(passwordAnswer)) status = Sys.MembershipCreateStatus.InvalidAnswer;
            }

            if (status != Sys.MembershipCreateStatus.Success) return null;

            using (var db = new Context()) {

                try {
                    var user = db.AppUsers<MembershipProvider>().FirstOrDefault(u => u.UserName == username);

                    if (user != null && user.IsDeleted) {
                        db.Users.Remove(user);
                        user = null;
                    }

                    User emailuser = null;
                    if (!string.IsNullOrEmpty(email)) {
                        emailuser = db.AppActiveUsers<MembershipProvider>().FirstOrDefault(u => u.Email == email);
                    }
                    if (user != null) status = Sys.MembershipCreateStatus.DuplicateUserName;
                    if (emailuser != null && RequiresUniqueEmail) status = Sys.MembershipCreateStatus.DuplicateEmail;
                    if (status != Sys.MembershipCreateStatus.Success) return null;

                    User NewUser = new User {
                        UserId = Guid.NewGuid(),
                        UserName = username,
                        IsConfirmed = true,
                        Email = email,
                        ConfirmationToken = null,
                        CreationDate = DateTime.UtcNow,
                        PasswordChangedDate = DateTime.UtcNow,
                        PasswordFailuresSinceLastSuccess = 0,
                        AnswerFailuresSinceLastSuccess = 0,
                        LastPasswordFailureDate = null,
                        LastActivityDate = DateTime.UtcNow,
                        LastLoginDate = null,
                        LastLockoutDate = null,
                        PasswordQuestion = passwordQuestion,
                        PasswordAnswer = passwordAnswer,
                        IsApproved = isApproved,
                        Application = Application.Current<MembershipProvider>(db)
                    };
                    if (providerUserKey is Guid) NewUser.UserId = (Guid)providerUserKey;
                    else NewUser.UserId = Guid.NewGuid();

                    NewUser.SetPassword(this, password);

                    db.Users.Add(NewUser);
                    db.SaveChanges();
                    return NewUser.MembershipUser;
                } catch (Exception ex) {
                    status = Sys.MembershipCreateStatus.DuplicateUserName; return null;
                }
            }
        }
        public override string CreateAccount(string userName, string password, string email, bool requireConfirmationToken)
        {
            if (string.IsNullOrEmpty(userName)) {
                throw new Sys.MembershipCreateUserException(Sys.MembershipCreateStatus.InvalidUserName);
            }
            /*if (string.IsNullOrEmpty(email)) {
                throw new Sys.MembershipCreateUserException(Sys.MembershipCreateStatus.InvalidEmail);
            }*/
            if (!ValidPassword(password)) throw new Sys.MembershipCreateUserException(Sys.MembershipCreateStatus.InvalidPassword);

            using (var db = new Context()) {
                try {
                    var user = db.AppActiveUsers<MembershipProvider>().FirstOrDefault(u => u.UserName == userName);

                    if (user != null && user.IsDeleted) {
                        db.Users.Remove(user);
                        user = null;
                    }

                    User emailuser = null;
                    if (!string.IsNullOrEmpty(email)) {
                        emailuser = db.AppActiveUsers<MembershipProvider>().FirstOrDefault(u => u.Email == email);
                    }
                    if (user != null) {
                        throw new Sys.MembershipCreateUserException(Sys.MembershipCreateStatus.DuplicateUserName);
                    }
                    if (emailuser != null && RequiresUniqueEmail) {
                        throw new Sys.MembershipCreateUserException(Sys.MembershipCreateStatus.DuplicateEmail);
                    }
                    string token = null;
                    if (requireConfirmationToken) {
                        token = Services.Crypto.GenerateToken();
                    }

                    User NewUser = new User {
                        UserId = Guid.NewGuid(),
                        UserName = userName,
                        Application = Application.Current<MembershipProvider>(db),
                        IsConfirmed = !requireConfirmationToken,
                        IsApproved = true,
                        Email = email,
                        ConfirmationToken = token,
                        CreationDate = DateTime.UtcNow,
                        PasswordChangedDate = DateTime.UtcNow,
                        PasswordFailuresSinceLastSuccess = 0,
                        AnswerFailuresSinceLastSuccess = 0,
                        LastPasswordFailureDate = null,
                        LastAnswerFailureDate = null,
                        LastActivityDate = DateTime.UtcNow,
                        LastLoginDate = null,
                        LastLockoutDate = null,
                        Comment = null
                    };

                    NewUser.SetPassword(this, password);

                    db.Users.Add(NewUser);
                    db.SaveChanges();
                    return token;
                } catch {
                    throw new Sys.MembershipCreateUserException(Sys.MembershipCreateStatus.DuplicateUserName);
                }
            }
        }