275 lines
11 KiB
C#
275 lines
11 KiB
C#
using ASPNET.StarterKit.DataAccessLayer;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Security;
|
|
|
|
namespace ASPNET.StarterKit.BusinessLogicLayer
|
|
{
|
|
public class MembershipAppUser : MembershipUser
|
|
{
|
|
private Guid _userId;
|
|
private string _userName;
|
|
private string _EmailAddress;
|
|
private string _FirstName;
|
|
private string _LastName;
|
|
private int _securityLevel;
|
|
private int _status;
|
|
|
|
|
|
public string FirstName { get { return this._FirstName; } }
|
|
public string LastName { get { return this._LastName; } }
|
|
|
|
public int SecurityLevel { get { return this._securityLevel; } }
|
|
public Guid UserID { get { return this._userId; } }
|
|
|
|
public int Status { get { return _status; } }
|
|
public string PasswordAnswer { get; set; }
|
|
public string Password { get; set; }
|
|
public string Title { get; set; }
|
|
public string PasswordSalt { get; set; }
|
|
public int PasswordFormatt { get; set; }
|
|
public string FullName { get { return this.LastName+","+this.FirstName; } }
|
|
public decimal Rate { get; set; }
|
|
public string CreditDepartment {get; set; }
|
|
private string _SecurityLevelName;
|
|
public string SecurityLevelName {
|
|
get { return this._SecurityLevelName; }
|
|
}
|
|
public MembershipAppUser(string providerName, string name, object providerUserKey, string email, string passwordQuestion,
|
|
string comment, bool isApproved, bool isLockedOut, DateTime creationDate, DateTime lastLoginDate,
|
|
DateTime lastActivityDate, DateTime lastPasswordChangedDate, DateTime lastLockoutDate,
|
|
string firstname, string lastname, int securitylevel, string passwordAnswer,string title,Guid userID,
|
|
string EncodedPassword,string salt, int passwordFormatt,
|
|
decimal rate,string creditdept,string securitylvlstring) : base(providerName, name, providerUserKey, email, passwordQuestion,
|
|
comment, isApproved, isLockedOut, creationDate, lastLoginDate,
|
|
lastActivityDate, lastPasswordChangedDate, lastLockoutDate)
|
|
{
|
|
this._FirstName = firstname;
|
|
this._LastName = lastname;
|
|
this._securityLevel = securitylevel;
|
|
PasswordAnswer = passwordAnswer;
|
|
Title = title;
|
|
_userId = userID;
|
|
Password = EncodedPassword;
|
|
PasswordSalt = salt;
|
|
PasswordFormatt = passwordFormatt;
|
|
Rate = rate;
|
|
CreditDepartment = creditdept;
|
|
_SecurityLevelName = securitylvlstring;
|
|
}
|
|
#region methods
|
|
public int Save()
|
|
{
|
|
DataAccess DALLayer = DataAccessHelper.GetDataAccess();
|
|
if (this.UserID == Guid.Empty)
|
|
return (DALLayer.CreateUser(this));
|
|
return (DALLayer.updateUser(this));
|
|
}
|
|
#endregion
|
|
#region override get user methods
|
|
|
|
public static MembershipAppUser GetUser(string username, bool userIsOnline)
|
|
{
|
|
DataAccess DALLayer = DataAccessHelper.GetDataAccess();
|
|
return DALLayer.GetUser(username, userIsOnline);
|
|
}
|
|
|
|
public static List<MembershipAppUser> GetAllUsersBySecurityLevel(int securityLevel)
|
|
{
|
|
DataAccess DALLayer = DataAccessHelper.GetDataAccess();
|
|
List<MembershipAppUser> users = (DALLayer.GetAllUsers(1000000, 0));
|
|
return (users.Where(x => x.SecurityLevel >= securityLevel).ToList());
|
|
}
|
|
|
|
|
|
public static MembershipAppUser GetUser(object providerUserKey, bool userIsOnline)
|
|
{
|
|
DataAccess DALLayer = DataAccessHelper.GetDataAccess();
|
|
return DALLayer.GetUser(providerUserKey, userIsOnline);
|
|
}
|
|
|
|
|
|
public static bool ChangePassword(string username, string pwd,string passwordAnswer)
|
|
{
|
|
DataAccess DALLayer = DataAccessHelper.GetDataAccess();
|
|
return DALLayer.ChangePassword(username, pwd,passwordAnswer);
|
|
|
|
}
|
|
public static bool ChangePasswordQuestionAndAnswer(string username, string newPasswordQuestion,
|
|
string newPasswordAnswer)
|
|
{
|
|
DataAccess DALLayer = DataAccessHelper.GetDataAccess();
|
|
return DALLayer.ChangePasswordQuestionAndAnswer(username, newPasswordQuestion,newPasswordAnswer);
|
|
}
|
|
public static bool CreateUser(object providerUserKey,string username, string password, string email,
|
|
string passwordQuestion, string passwordAnswer,bool isApproved, string comment, DateTime createDate,
|
|
DateTime LastPasswordChangedDate, DateTime LastActivityDate, string ApplicationName,
|
|
bool isLockedOut, DateTime LockOutDate, int FailedPasswordAttemptCount,
|
|
DateTime FailedPasswordAttemptWindowStart,int FailedPasswordAnswerAttemptCount,
|
|
DateTime FailedPasswordAnswerAttemptWindowStart,
|
|
string firstName,string lastName,string title,int securitylevel,string saltValue,int passwordFormatt,decimal rate,
|
|
string creditdept, bool regEmailSent)
|
|
{
|
|
MembershipAppUser newUser = new MembershipAppUser(DefaultValues.GetProviderName(), username, providerUserKey, email, passwordQuestion, comment,
|
|
isApproved, isLockedOut, createDate, createDate, LastActivityDate, LastPasswordChangedDate,
|
|
LockOutDate, firstName, lastName, securitylevel, passwordAnswer, title, Guid.Empty,
|
|
password, saltValue, passwordFormatt,rate, creditdept,"");
|
|
DataAccess DALLayer = DataAccessHelper.GetDataAccess();
|
|
return (DALLayer.CreateUser(newUser) == 0);
|
|
}
|
|
public static bool Delete(string username, bool deleteAllRelatedData)
|
|
{
|
|
DataAccess DALLayer = DataAccessHelper.GetDataAccess();
|
|
return (DALLayer.Delete(username, deleteAllRelatedData));
|
|
}
|
|
public static List<MembershipAppUser> GetAllUsers(int PageSize, int PageIndex)
|
|
{
|
|
DataAccess DALLayer = DataAccessHelper.GetDataAccess();
|
|
return (DALLayer.GetAllUsers(PageSize, PageIndex));
|
|
}
|
|
public static void UpdateFailureCount(string username,string type)
|
|
{
|
|
DataAccess DALLayer = DataAccessHelper.GetDataAccess();
|
|
DALLayer.UpdateFailureCount(username, type);
|
|
|
|
}
|
|
public static string GetUserByEmail(string email)
|
|
{
|
|
|
|
DataAccess DALLayer = DataAccessHelper.GetDataAccess();
|
|
return (DALLayer.GetUserByEmail(email));
|
|
}
|
|
public static bool ResetPassword(string pwd)
|
|
{
|
|
|
|
DataAccess DALLayer = DataAccessHelper.GetDataAccess();
|
|
return (DALLayer.ResetPassword(pwd));
|
|
}
|
|
public static bool UnlockUser(string userName)
|
|
{
|
|
DataAccess DALLayer = DataAccessHelper.GetDataAccess();
|
|
return (DALLayer.UnlockUser(userName));
|
|
}
|
|
|
|
public static bool RegisterUser(string UserName, string pwd, string question, string answer, bool isApproved,
|
|
DateTime CreateDate, Guid UserId,string salt, int pwdFormat)
|
|
{
|
|
|
|
|
|
DataAccess DALLayer = DataAccessHelper.GetDataAccess();
|
|
return (DALLayer.RegisterUser(UserName, pwd, salt, question, answer, isApproved,CreateDate, pwdFormat, UserId));
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
public class AppUser {
|
|
|
|
public bool InActive { get; set; }
|
|
private Guid _UserId;
|
|
public Guid UserId { get { return _UserId; } }
|
|
private string _UserName;
|
|
public string UserName { get { return _UserName; } set { this._UserName = value; } }
|
|
private int _SecurityLevel;
|
|
public int SecurityLevel { get { return _SecurityLevel; } set { this._SecurityLevel = value; } }
|
|
private string _FirstName;
|
|
public string FirstName { get { return _FirstName; } set { this._FirstName = value; } }
|
|
private string _LastName;
|
|
public string LastName { get { return _LastName; } set { this._LastName = value; } }
|
|
private string _Title;
|
|
public string Title { get { return _Title; } set { this._Title = value; } }
|
|
private string _CreditDepartment;
|
|
public string CreditDepartment { get { return _CreditDepartment; } set { this._CreditDepartment = value; } }
|
|
private decimal _Rate;
|
|
public decimal Rate { get { return _Rate; } set { this._Rate = value; } }
|
|
private bool _regEmailSent;
|
|
public bool RegEmailSent
|
|
{
|
|
get { return _regEmailSent; }
|
|
set { _regEmailSent = value; }
|
|
}
|
|
public AppUser(string userName, int securityLevel, string firstName, string lastName, string title, string creditDepartment,
|
|
decimal rate, bool regEmailSent) :this(userName,Guid.Empty,securityLevel,firstName,lastName,title,creditDepartment, rate , regEmailSent)
|
|
{
|
|
|
|
}
|
|
public AppUser(string userName,Guid userId, int securityLevel,string firstName,string lastName,string title, string creditDepartment,
|
|
decimal rate,bool regEmailSent)
|
|
{
|
|
|
|
this._UserName = userName;
|
|
this._UserId = userId;
|
|
this._SecurityLevel = securityLevel;
|
|
this._FirstName = firstName;
|
|
this._LastName = lastName;
|
|
this._Title = title;
|
|
this._CreditDepartment = creditDepartment;
|
|
this._Rate = rate;
|
|
this._regEmailSent = regEmailSent;
|
|
}
|
|
public bool Save(bool islocked)
|
|
{
|
|
if (this._UserId == Guid.Empty)
|
|
{
|
|
DataAccess DALLayer = DataAccessHelper.GetDataAccess();
|
|
Guid id = DALLayer.AddAppUser(this);
|
|
if (id == Guid.Empty)
|
|
return false;
|
|
else
|
|
this._UserId = id;
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
DataAccess DALLayer = DataAccessHelper.GetDataAccess();
|
|
return( DALLayer.UpdateAppUser(this, islocked));
|
|
|
|
}
|
|
}
|
|
public bool Save()
|
|
{
|
|
if (this._UserId == Guid.Empty)
|
|
{
|
|
DataAccess DALLayer = DataAccessHelper.GetDataAccess();
|
|
Guid id = DALLayer.AddAppUser(this);
|
|
if (id == Guid.Empty)
|
|
return false;
|
|
else
|
|
this._UserId = id;
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
DataAccess DALLayer = DataAccessHelper.GetDataAccess();
|
|
return (DALLayer.UpdateAppUser(this));
|
|
|
|
}
|
|
}
|
|
public static List<AppUser> GetAllUsers()
|
|
{
|
|
DataAccess DALLayer = DataAccessHelper.GetDataAccess();
|
|
return (DALLayer.GetAllAppUsers());
|
|
}
|
|
|
|
public static AppUser GetUserByEmail(string email)
|
|
{
|
|
|
|
DataAccess DALLayer = DataAccessHelper.GetDataAccess();
|
|
return (DALLayer.GetAppUserByEmail(email));
|
|
}
|
|
public static AppUser GetUserById(Guid userID)
|
|
{
|
|
|
|
DataAccess DALLayer = DataAccessHelper.GetDataAccess();
|
|
return (DALLayer.GetUserById(userID));
|
|
}
|
|
public static AppUser GetUserByUserName(string userName)
|
|
{
|
|
|
|
DataAccess DALLayer = DataAccessHelper.GetDataAccess();
|
|
return (DALLayer.GetUserByUserName(userName));
|
|
}
|
|
|
|
}
|
|
} |