public static SRPUser FetchByUsername(string pUsername)
        {
            var arrParams = new SqlParameter[1];

            arrParams[0] = new SqlParameter("@Username", pUsername);
            var     reader = SqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, "cbspSRPUser_GetByUsername", arrParams);
            SRPUser u      = GetFromReader(reader);

            return(u);
        }
        public static SRPUser Fetch(int pUid)
        {
            var arrParams = new SqlParameter[1];

            arrParams[0] = new SqlParameter("@UID", pUid);
            var     reader = SqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, "cbspSRPUser_Get", arrParams);
            SRPUser u      = GetFromReader(reader);

            return(u);
        }
        protected override bool CheckBusinessRules(BusinessRulesValidationMode validationMode)
        {
            // Remove any old error Codes
            ClearErrorCodes();

            ClearErrorCodes();
            if (validationMode == BusinessRulesValidationMode.INSERT)
            {
                SRPUser obj = FetchByUsername(Username);
                if (obj != null)
                {
                    AddErrorCode(new BusinessRulesValidationMessage("Username", "Username", "Username already exists.",
                                                                    BusinessRulesValidationCode.UNSPECIFIED));
                }
            }
            return(ErrorCodes.Count == 0);
            //return true;
        }
        public static List <SRPUser> FetchAll()
        {
            var            reader   = SqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, "cbspSRPUser_GetAll");
            List <SRPUser> retValue = new List <SRPUser>();

            while (reader.Read())
            {
                SRPUser aUser = new SRPUser();
                aUser.Uid               = (int)reader["UID"];
                aUser.Username          = (string)reader["Username"];
                aUser.Password          = (string)reader["Password"];
                aUser.FirstName         = (string)reader["FirstName"];
                aUser.LastName          = (string)reader["LastName"];
                aUser.EmailAddress      = (string)reader["EmailAddress"];
                aUser.Division          = (string)reader["Division"];
                aUser.Department        = (string)reader["Department"];
                aUser.Title             = (string)reader["Title"];
                aUser.IsActive          = (bool)reader["IsActive"];
                aUser.MustResetPassword = (bool)reader["MustResetPassword"];
                aUser.IsDeleted         = (bool)reader["IsDeleted"];
                aUser.LastPasswordReset = reader.IsDBNull(reader.GetOrdinal("LastPasswordReset"))
                                              ? null
                                              : (DateTime?)reader["LastPasswordReset"];
                aUser.DeletedDate = reader.IsDBNull(reader.GetOrdinal("DeletedDate"))
                                        ? null
                                        : (DateTime?)reader["DeletedDate"];
                aUser.LastModDate = reader.IsDBNull(reader.GetOrdinal("LastModDate"))
                                        ? null
                                        : (DateTime?)reader["LastModDate"];
                aUser.AddedDate = reader.IsDBNull(reader.GetOrdinal("AddedDate"))
                                      ? null
                                      : (DateTime?)reader["AddedDate"];
                aUser.LastModUser = (string)reader["LastModUser"];
                aUser.AddedUser   = (string)reader["AddedUser"];
                retValue.Add(aUser);
            }
            return(retValue);
        }
        public static int Insert(SRPUser u)
        {
            if (u == null)
            {
                return(-1);
            }
            var arrParams = new SqlParameter[12];

            arrParams[0]            = new SqlParameter("@Username", u.Username);
            arrParams[1]            = new SqlParameter("@Password", u.Password);
            arrParams[2]            = new SqlParameter("@FirstName", u.FirstName);
            arrParams[3]            = new SqlParameter("@LastName", u.LastName);
            arrParams[4]            = new SqlParameter("@EmailAddress", u.EmailAddress);
            arrParams[5]            = new SqlParameter("@Division", u.Division);
            arrParams[6]            = new SqlParameter("@Department", u.Department);
            arrParams[7]            = new SqlParameter("@Title", u.Title);
            arrParams[8]            = new SqlParameter("@IsActive", u.IsActive);
            arrParams[9]            = new SqlParameter("@MustResetPassword", u.MustResetPassword);
            arrParams[10]           = new SqlParameter("@ActionUsername", ((SRPUser)HttpContext.Current.Session[SessionData.UserProfile.ToString()]).Username);
            arrParams[11]           = new SqlParameter("@Return_Value", -1);
            arrParams[11].Direction = ParameterDirection.ReturnValue;
            u.Uid = Convert.ToInt32(SqlHelper.ExecuteScalar(conn, CommandType.StoredProcedure, "dbo.cbspSRPUser_Insert", arrParams));
            return((int)u.Uid);
        }