⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ituser.cs

📁 BugNET is an issue tracking and project issue management solution built using the ASP.NET web applic
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Data;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using BugNET.DataAccessLayer;
using BugNET.UserInterfaceLayer;
using System.Web.Security;
using System.Web.Profile;
using System.Web;
using BugNET.Providers.MembershipProviders;

namespace BugNET.BusinessLogicLayer
{
	/// <summary>
	/// BugNET user class for working with the membership provider
	/// </summary>
	public class ITUser
	{
        private Guid _Id;
        private string _UserName;
        private string _Email;
        private string _DisplayName;
        private string _FirstName;
        private string _LastName;
        private DateTime _CreationDate;
        private DateTime _LastLoginDate;
        private bool _IsApproved;

        /// <summary>
        /// Gets the id.
        /// </summary>
        /// <value>The id.</value>
        public Guid Id
        {
            get { return _Id; }
        }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is approved.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is approved; otherwise, <c>false</c>.
        /// </value>
        public bool IsApproved
        {
            get { return _IsApproved; }
            set { _IsApproved = value; }
        }
        /// <summary>
        /// Gets or sets the last login date.
        /// </summary>
        /// <value>The last login date.</value>
        public DateTime LastLoginDate
        {
            get { return _LastLoginDate; }
            set { _LastLoginDate = value; }
        }

        /// <summary>
        /// Gets or sets the creation date.
        /// </summary>
        /// <value>The creation date.</value>
        public DateTime CreationDate
        {
            get { return _CreationDate; }
            set { _CreationDate = value; }
        }
        /// <summary>
        /// Gets or sets the name of the user.
        /// </summary>
        /// <value>The name of the user.</value>
        public string UserName
        {
            get { return _UserName; }
            set { _UserName = value; }
        }


        /// <summary>
        /// Gets or sets the display name.
        /// </summary>
        /// <value>The display name.</value>
        public string DisplayName
        {
            get
            {
                if (_DisplayName == string.Empty)
                    return _UserName;
                else
                    return _DisplayName;
            }
            set { _DisplayName = value; }
        }


		#region Constructors
            /// <summary>
            /// Initializes a new instance of the <see cref="T:ITUser"/> class.
            /// </summary>
			private ITUser() 
			{ }

            /// <summary>
            /// Initializes a new instance of the <see cref="ITUser"/> class.
            /// </summary>
            /// <param name="userId">The user id.</param>
            /// <param name="userName">Name of the user.</param>
            /// <param name="displayName">The display name.</param>
            public ITUser(Guid userId, string userName,string firstName, string lastName, string displayName, DateTime creationDate,DateTime lastLoginDate,bool isApproved)
            {
                _Id = userId;
                _UserName = userName;
                _DisplayName = displayName;
                _CreationDate = creationDate;
                _FirstName = firstName;
                _LastName = lastName;
                _IsApproved = isApproved;
                _LastLoginDate = lastLoginDate;
            }

            /// <summary>
            /// Initializes a new instance of the <see cref="ITUser"/> class.
            /// </summary>
            /// <param name="userId">The user id.</param>
            /// <param name="userName">Name of the user.</param>
            /// <param name="displayName">The display name.</param>
            public ITUser(Guid userId, string userName, string displayName)
                : this(userId, userName, string.Empty, string.Empty, displayName, DateTime.MinValue, DateTime.MinValue, true)
            { }

        
        #endregion

        #region Static Methods

            /// <summary>
            /// Creates a new user.
            /// </summary>
            /// <param name="userName"></param>
            /// <param name="password"></param>
            /// <param name="email"></param>
            public static void CreateUser(string userName, string password, string email)
            {
                MembershipUser user = Membership.CreateUser(userName,password,email);
            }

            /// <summary>
            /// Gets the user.
            /// </summary>
            /// <param name="userProviderKey">The user provider key.</param>
            /// <returns></returns>
            public static MembershipUser GetUser(object userProviderKey)
            {
                if (userProviderKey == null)
                    throw (new ArgumentOutOfRangeException("userProviderKey"));
                return Membership.GetUser(userProviderKey);
            }

            /// <summary>
            /// Gets the user.
            /// </summary>
            /// <param name="userName">Name of the user.</param>
            /// <returns></returns>
            public static MembershipUser GetUser(string userName)
            {
                if (String.IsNullOrEmpty(userName))
                    throw (new ArgumentOutOfRangeException("userName"));


                return Membership.GetUser(userName);
            }
           
            /// <summary>
            /// Gets all users in the application
            /// </summary>
            /// <returns>Collection of membership users</returns>
			public static List<CustomMembershipUser> GetAllUsers()
			{
                //return Membership.GetAllUsers();

                List<CustomMembershipUser> userList = new List<CustomMembershipUser>();
                foreach(CustomMembershipUser u in Membership.GetAllUsers())
                {
                    userList.Add(u);
                }
                return userList;
			}

            /// <summary>
            /// Gets all users.
            /// </summary>
            /// <returns>Authorized Users Only</returns>
            public static List<CustomMembershipUser> GetAllAuthorizedUsers()
            {
                List<CustomMembershipUser> users = ITUser.GetAllUsers();
                List<CustomMembershipUser> AuthenticatedUsers = new List<CustomMembershipUser>();
                foreach (CustomMembershipUser user in users)
                {
                    if (user.IsApproved)
                        AuthenticatedUsers.Add(user);
                }
                users = AuthenticatedUsers;
                return users;
            }

            /// <summary>
            /// Finds users by name
            /// </summary>
            /// <param name="userNameToMatch">The user name to match.</param>
            /// <returns></returns>
            public static List<CustomMembershipUser> FindUsersByName(string userNameToMatch)
            {
                List<CustomMembershipUser> userList = new List<CustomMembershipUser>();
                foreach (CustomMembershipUser u in Membership.FindUsersByName(userNameToMatch))
                {
                    userList.Add(u);
                }
                return userList;
            }

            /// <summary>
            /// Finds the users by email.
            /// </summary>
            /// <param name="emailToMatch">The email to match.</param>
            /// <returns></returns>
            public static List<CustomMembershipUser> FindUsersByEmail(string emailToMatch)
            {
                List<CustomMembershipUser> userList = new List<CustomMembershipUser>();
                foreach (CustomMembershipUser u in Membership.FindUsersByEmail(emailToMatch))
                {
                    userList.Add(u);
                }
                return userList;
            }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -