public override bool DeleteAccount(string userName)
 {
     if (string.IsNullOrEmpty(userName)) {
         throw CreateArgumentNullOrEmptyException("userName");
     }
     using (var db = new Context()) {
         try {
             var user = db.AppUsers<MembershipProvider>().FirstOrDefault(u => u.UserName == userName);
             if (user == null) {
                 return false;
             }
             db.Users.Remove(user);
             db.SaveChanges();
         } catch { }
         return true;
     }
 }
 public override bool DeleteUser(string username, bool deleteAllRelatedData)
 {
     if (string.IsNullOrEmpty(username)) {
         return false;
     }
     using (var db = new Context()) {
         try {
             var user = db.AppUsers<MembershipProvider>().FirstOrDefault(u => u.UserName == username);
             if (user != null) {
                 if (!deleteAllRelatedData) user.IsDeleted = true;
                 else db.Users.Remove(user);
                 db.SaveChanges();
                 return true;
             }
         } catch {
             return true;
         }
         return false;
     }
 }
        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;
                }
            }
        }