public bool Delete(string applicationName, string userName)
 {
     String stmtId = "Sys_User.Delete";
     Sys_User user = new Sys_User();
     user.ApplicationName = applicationName;
     user.Name = userName;
     if (SqlMapper.Update(stmtId, user) > 0) {
         return true;
     }
     else return false;
 }
        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            ValidatePasswordEventArgs args =
              new ValidatePasswordEventArgs(username, password, true);

            OnValidatingPassword(args);

            if (args.Cancel) {
                status = MembershipCreateStatus.InvalidPassword;
                return null;
            }

            if (RequiresUniqueEmail && GetUserNameByEmail(email) != "") {
                status = MembershipCreateStatus.DuplicateEmail;
                return null;
            }

            MembershipUser u = GetUser(username, false);

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

                if (providerUserKey == null) {
                    providerUserKey = Guid.NewGuid();
                }
                else {
                    if (!(providerUserKey is Guid)) {
                        status = MembershipCreateStatus.InvalidProviderUserKey;
                        return null;
                    }
                }
                Sys_User user = new Sys_User();
                user.Id = providerUserKey.ToString();
                user.Name = username;
                user.DisplayName = username;
                user.PasswordKey = GenerateSalt();
                user.Password = EncodePassword(password, user.PasswordKey);
                user.Email = email;
                user.PasswordQuestion = passwordQuestion;
                user.PasswordAnswer = passwordAnswer == null ? null : EncodePassword(passwordAnswer, user.PasswordKey);
                user.IsApproved = isApproved == true ? short.Parse("1") : short.Parse("0");
                user.Comment = string.Empty;
                user.CreationDate = createDate;
                user.LastPasswordChangedDate = createDate;
                user.LastActivityDate = createDate;
                user.LastLoginDate = createDate;
                user.ApplicationName = _ApplicationName;
                user.IsLockedOut = 0;
                user.LastLockedOutDate = createDate;
                user.FailedPasswordAttemptCount = 0;
                user.FailedPasswordAttemptWindowStart = createDate;
                user.FailedPasswordAnswerAttemptCount = 0;
                user.FailedPasswordAnswerAttemptWindowStart = createDate;

                bool result = _userRepository.Insert(user);
                if (result) {
                    status = MembershipCreateStatus.Success;
                }
                else {
                    status = MembershipCreateStatus.UserRejected;
                }
                return GetUser(username, false);
            }
            else {
                status = MembershipCreateStatus.DuplicateUserName;
            }

            return null;
        }
 public int GetCount(string applicationName)
 {
     String stmtId = "Sys_User.GetCount";
     Sys_User user = new Sys_User();
     user.ApplicationName = applicationName;
     int result = SqlMapper.QueryForObject<int>(stmtId, user);
     return result;
 }
 public bool ValidateUser(string applicationName, string userName, string password)
 {
     String stmtId = "Sys_User.ValidateUser";
     Sys_User user = new Sys_User();
     user.ApplicationName = applicationName;
     user.Name = userName;
     user.Password = password;
     int result = SqlMapper.QueryForObject<int>(stmtId, user);
     if (result == 1) {
         return true;
     }
     else {
         return false;
     }
 }
 public void Delete(Sys_User obj)
 {
     throw new NotImplementedException();
 }
 public bool UpdatePasswordQuestionAndAnswer(string applicationName, string userName, string passwordQuestion, string passwordAnswer)
 {
     String stmtId = "Sys_User.UpdatePasswordQuestionAndAnswer";
     Sys_User user = new Sys_User();
     user.ApplicationName = applicationName;
     user.Name = userName;
     user.PasswordQuestion = passwordQuestion;
     user.PasswordAnswer = passwordAnswer;
     if (SqlMapper.Update(stmtId, user) > 0) {
         return true;
     }
     else return false;
 }
 public void UpdateLogonDate(string applicationName, string userName, DateTime LastLoginDate, DateTime LastActivityDate)
 {
     String stmtId = "Sys_User.UpdateLogonDate";
     Sys_User user = new Sys_User();
     user.ApplicationName = applicationName;
     user.Name = userName;
     user.LastLoginDate = LastLoginDate;
     user.LastActivityDate = LastActivityDate;
     SqlMapper.Update(stmtId, user);
 }
 public string GetUserNameByEmail(string applicationName, string email)
 {
     String stmtId = "Sys_User.GetUserNameByEmail";
     Sys_User user = new Sys_User();
     user.ApplicationName = applicationName;
     user.Email = email;
     Sys_User result = SqlMapper.QueryForObject<Sys_User>(stmtId, user);
     if (result != null)
         return result.Name;
     else return string.Empty;
 }
 public bool UpdateFailedPasswordAnswer(string applicationName, string userName, int FailedPasswordAnswerAttemptCount, DateTime FailedPasswordAnswerAttemptWindowStart)
 {
     String stmtId = "Sys_User.UpdateFailedPasswordAnswer";
     Sys_User user = new Sys_User();
     user.ApplicationName = applicationName;
     user.Name = userName;
     user.FailedPasswordAnswerAttemptCount = FailedPasswordAnswerAttemptCount;
     user.FailedPasswordAnswerAttemptWindowStart = FailedPasswordAnswerAttemptWindowStart;
     if (SqlMapper.Update(stmtId, user) > 0) {
         return true;
     }
     else return false;
 }
 public bool UpdateForMembershipUser(Sys_User obj)
 {
     String stmtId = "Sys_User.UpdateForMembershipUser";
     if (SqlMapper.Update(stmtId, obj) > 0) {
         return true;
     }
     else return false;
 }
 public bool Update(Sys_User obj)
 {
     if (obj == null) throw new ArgumentNullException("obj");
     String stmtId = "Sys_User.Update";
     if (SqlMapper.Update(stmtId, obj) > 0) {
         return true;
     }
     else return false;
 }
 public bool UnlockUser(string applicationName, string userName, DateTime LastLockedOutDate)
 {
     String stmtId = "Sys_User.UnlockUser";
     Sys_User user = new Sys_User();
     user.ApplicationName = applicationName;
     user.Name = userName;
     user.LastLockedOutDate = LastLockedOutDate;
     if (SqlMapper.Update(stmtId, user) > 0) {
         return true;
     }
     else return false;
 }
 public Sys_User GetUser_IsNotLockedOut(string applicationName, string userName)
 {
     String stmtId = "Sys_User.GetUser_IsNotLockedOut";
     Sys_User user = new Sys_User();
     user.ApplicationName = applicationName;
     user.Name = userName;
     Sys_User result = SqlMapper.QueryForObject<Sys_User>(stmtId, user);
     return result;
 }
 public override void UpdateUser(MembershipUser user)
 {
     Sys_User u = new Sys_User();
     u.Email = user.Email;
     u.Comment = user.Comment;
     u.IsApproved = user.IsApproved == true ? short.Parse("1") : short.Parse("0");
     u.ApplicationName = ApplicationName;
     u.Name = user.UserName;
     bool result = _userRepository.UpdateForMembershipUser(u);
 }
 public bool UpdatePassword(string applicationName, string userName, string Password, string passwordKey, DateTime LastPasswordChangedDate)
 {
     String stmtId = "Sys_User.UpdatePassword";
     Sys_User user = new Sys_User();
     user.ApplicationName = applicationName;
     user.Name = userName;
     user.Password = Password;
     user.PasswordKey = passwordKey;
     user.LastPasswordChangedDate = LastPasswordChangedDate;
     if (SqlMapper.Update(stmtId, user) > 0) {
         return true;
     }
     else return false;
 }
 private MembershipUser GetUserFromSys_User(Sys_User user)
 {
     if (user == null) return null;
     MembershipUser u = new MembershipUser(this.Name,
         user.Name, user.Id, user.Email, user.PasswordQuestion,
         user.Comment, user.IsApproved == 1 ? true : false, user.IsLockedOut == 1 ? true : false, user.CreationDate,
         user.LastLoginDate, user.LastActivityDate, user.LastPasswordChangedDate, user.LastLockedOutDate);
     return u;
 }
 public int GetNumberOfUsersOnline(string applicationName, DateTime LastActivityDate)
 {
     String stmtId = "Sys_User.GetNumberOfUsersOnline";
     Sys_User user = new Sys_User();
     user.ApplicationName = applicationName;
     user.LastActivityDate = LastActivityDate;
     int result = SqlMapper.QueryForObject<int>(stmtId, user);
     return result;
 }