コード例 #1
0
 /*
  * Add User to Session
  */
 public void setCurrentUser(UserModel user)
 {
     if (user == null)
         throw new ArgumentNullException("The user object is invalid");
     else
     {
         Session.Add(Resources.USER_SESSION_STATE, user);
     }
 }
コード例 #2
0
        public string getCssClass(int senderID)
        {
            if (user == null)
            {
                userManager = new BLLUserMngr();
                user = userManager.BLLGetCurrentUser(Session);
            }

            if (user.ID.Equals(senderID))
                return sentCss;
            else
                return receivedCss;
        }
コード例 #3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         userManager = new BLLUserMngr();
         user = userManager.BLLGetCurrentUser(Session);
         if (!IsPostBack && user!=null)
         {
             txtEmail.Text = user.Email;
         }
     }
     catch (Exception)
     {
         //Log error
         Response.Redirect("404.aspx", false);
     }
 }
コード例 #4
0
ファイル: LogIn.cs プロジェクト: joeLloyd/OOP_v3
        private void LoginValidate()
        {
            // Local Variables //
            string pass;
            string user;
            string passHash;
            bool isValid;

            pass = txtPassword.Text;
            user = txtUser.Text;

            // Calling Encryption method from the BLL, this takes a password and returns the encrypted string
            BLLMngr bllMngr = new BLLMngr();
            passHash = bllMngr.PassEncrypt(pass);

            //Instanciating a user
            UserModel userDetails = new UserModel(user, passHash);

            //Sending details (UserName and password) through BLL and DAL for validation at the database
            isValid = bllMngr.IsValidLogin(userDetails);

            //If it comes back as a valid user allow access and go to main DataGrid
            if (isValid)
            {
                MessageBox.Show("Welcome To DBS Credit Union");
                using (DGMain dgm = new DGMain())
                {
                    this.Hide();
                    dgm.ShowDialog();
                }
                this.Show();
                txtPassword.Clear();
                txtUser.Clear();
            }
            else
            {
                MessageBox.Show("Invalid Login");
            }
        }
コード例 #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
            userManager = new BLLUserMngr();
            user = userManager.BLLGetCurrentUser(Session);
            }
            catch (Exception)
            {
                //Log error
                Response.Redirect("404.aspx", false);
            }
            if (!IsPostBack)
            {
                /*Retrieve and load the values of each attribute*/
                attManager = new BLLAttributeMngr();
                hobbies = attManager.BLLGetHobbiesTable();

                attributes = attManager.BLLGetBuild();
                ddlBuild.DataSource = attributes;
                ddlBuild.DataBind();

                attributes = attManager.BLLGetCounty();
                ddlCounty.DataSource = attributes;
                ddlCounty.DataBind();

                attributes = attManager.BLLGetEthnicity();
                ddlEthnicity.DataSource = attributes;
                ddlEthnicity.DataBind();

                attributes = attManager.BLLGetEyeColor();
                ddlEyeColor.DataSource = attributes;
                ddlEyeColor.DataBind();

                attributes = attManager.BLLGetGenders();
                ddlGender.DataSource = attributes;
                ddlGender.DataBind();

                attributes = attManager.BLLGetHairColor();
                ddlHairColor.DataSource = attributes;
                ddlHairColor.DataBind();

                attributes = attManager.BLLGetHeight();
                ddlHeight.DataSource = attributes;
                ddlHeight.DataBind();

                attributes = attManager.BLLGetRelationshipStatus();
                ddlRelationshipStatus.DataSource = attributes;
                ddlRelationshipStatus.DataBind();

                attributes = attManager.BLLGetSexualOrientation();
                ddlOrientation.DataSource = attributes;
                ddlOrientation.DataBind();

                cblHobbies.DataSource = hobbies;
                cblHobbies.DataValueField = Resources.HOBBIES_ID_COLUMN;
                cblHobbies.DataTextField = Resources.HOBBIES_NAME_COLUMN;
                cblHobbies.DataBind();

                if (user != null)
                {
                    if (user.Age != null && user.Age > 0) txtAge.Text = user.Age.ToString();
                    if (user.IdealDate!=null && user.IdealDate.Length > 0) txtIdealDate.Text = user.IdealDate;
                    if (user.Profession != null && user.Profession.Length > 0) txtProfession.Text = user.Profession;
                    if (user.Town != null && user.Town.Length > 0) txtTown.Text = user.Town;
                    if (user.Comments != null && user.Comments.Length > 0) txtComments.Text = user.Comments;

                    if (user.Build != null && user.Build.Length > 0) ddlBuild.Items.FindByValue(user.Build).Selected = true;
                    if (user.County != null && user.County.Length > 0) ddlCounty.Items.FindByValue(user.County).Selected = true;
                    if (user.Ethnicity != null && user.Ethnicity.Length > 0) ddlEthnicity.Items.FindByValue(user.Ethnicity).Selected = true;
                    if (user.EyeColor != null && user.EyeColor.Length > 0) ddlEyeColor.Items.FindByValue(user.EyeColor).Selected = true;
                    if (user.Gender != null && user.Gender.Length > 0) ddlGender.Items.FindByValue(user.Gender).Selected = true;
                    if (user.HairColor != null && user.HairColor.Length > 0) ddlHairColor.Items.FindByValue(user.HairColor).Selected = true;
                    if (user.Height != null && user.Height.Length > 0) ddlHeight.Items.FindByValue(user.Height).Selected = true;
                    if (user.RelationshipStatus != null && user.RelationshipStatus.Length > 0) ddlRelationshipStatus.Items.FindByValue(user.RelationshipStatus).Selected = true;
                    if (user.SexualOrientation != null && user.SexualOrientation.Length > 0) ddlOrientation.Items.FindByValue(user.SexualOrientation).Selected = true;

                    // Populate the CheckBoxList items only when it's not a postback.
                    foreach (int i in user.Hobbies)
                    {
                        cblHobbies.Items[i].Selected = true;
                    }
                }
            }
        }
コード例 #6
0
ファイル: BLLMngr.cs プロジェクト: joeLloyd/OOP_v3
 public bool IsValidLogin(UserModel userDetails)
 {
     bool isValid;
     bool valid;
     DALMngr dalMngr = new DALMngr();
     valid = dalMngr.IsValidLogin(userDetails);
     if(valid)
     {
         isValid = true;
     }
     else
     {
         isValid = false;
     }
     return isValid;
 }
コード例 #7
0
        /* Sets the hobbies for the user with the given id - as a dictionary*/
        public void DALSetHobbies(UserModel user)
        {
            int rowsAffected;

            if(user == null)
                return;
            if(user.Hobbies.Count <= 0)
                return;
            
            string sql = "INSERT INTO "+Resources.USER_HOBBIES_TABLE + " VALUES ";
            foreach (int hobbyID in user.Hobbies)
            {
                sql += "(" + user.ID + ",'" + hobbyID + "')";
            }

            using (SqlConnection con = new SqlConnection(conString))
            {
                using (SqlCommand cmd = new SqlCommand(sql, con))
                {
                    cmd.CommandType = CommandType.Text;

                    con.Open();
                    try
                    {
                        rowsAffected = cmd.ExecuteNonQuery();

                    }
                    catch (SqlException e)
                    {
                        throw;
                    }
                    finally
                    {
                        con.Close();
                    }
                }
            }
        }
コード例 #8
0
        /* Returns a user with the given username */
        public UserModel DALGetUser(string username)
        {
            UserModel user = null;
            SqlDataReader reader;
            using (SqlConnection con = new SqlConnection(conString))
            {
                using (SqlCommand cmd = new SqlCommand(Resources.USER_PROFILE_USERNAME_PROC, con))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(Resources.USERNAME_PARAM, SqlDbType.NVarChar).Value = username;

                    try
                    {
                        con.Open();
                        reader = cmd.ExecuteReader();
                        if (reader.Read())
                        {
                            user = new UserModel();
                            user.Username = username;
                            if (!reader.IsDBNull((int)UserProfile.User)) user.ID = reader.GetInt32((int)UserProfile.User);
                            if (!reader.IsDBNull((int)UserProfile.Age)) user.Age = reader.GetInt32((int)UserProfile.Age);
                            if (!reader.IsDBNull((int)UserProfile.Build)) user.Build = reader.GetString((int)UserProfile.Build);
                            if (!reader.IsDBNull((int)UserProfile.County)) user.County = reader.GetString((int)UserProfile.County);
                            if (!reader.IsDBNull((int)UserProfile.Email)) user.Email = reader.GetString((int)UserProfile.Email);
                            if (!reader.IsDBNull((int)UserProfile.Ethnicity)) user.Ethnicity = reader.GetString((int)UserProfile.Ethnicity);
                            if (!reader.IsDBNull((int)UserProfile.EyeColor)) user.EyeColor = reader.GetString((int)UserProfile.EyeColor);
                            if (!reader.IsDBNull((int)UserProfile.Gender)) user.Gender = reader.GetString((int)UserProfile.Gender);
                            if (!reader.IsDBNull((int)UserProfile.HairColor)) user.HairColor = reader.GetString((int)UserProfile.HairColor);
                            if (!reader.IsDBNull((int)UserProfile.Height)) user.Height = reader.GetString((int)UserProfile.Height);
                            //images - parse xml
                            if (!reader.IsDBNull((int)UserProfile.IdealDate)) user.IdealDate = reader.GetString((int)UserProfile.IdealDate);
                            if (!reader.IsDBNull((int)UserProfile.Profession)) user.Profession = reader.GetString((int)UserProfile.Profession);
                            if (!reader.IsDBNull((int)UserProfile.RelationshipStatus)) user.RelationshipStatus = reader.GetString((int)UserProfile.RelationshipStatus);
                            if (!reader.IsDBNull((int)UserProfile.SexualOrientation)) user.SexualOrientation = reader.GetString((int)UserProfile.SexualOrientation);
                            if (!reader.IsDBNull((int)UserProfile.Town)) user.Town = reader.GetString((int)UserProfile.Town);
                            if (!reader.IsDBNull((int)UserProfile.ProfilePicturePath)) user.ProfilePicturePath = reader.GetString((int)UserProfile.ProfilePicturePath);
                            if (!reader.IsDBNull((int)UserProfile.Comments)) user.Comments = reader.GetString((int)UserProfile.Comments);
                        }
                        reader.Close();

                        cmd.Parameters.Clear();
                        cmd.CommandText = Resources.GET_USER_HOBBIES_PROC;
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add(Resources.USERID_PARAM, SqlDbType.Int).Value = user.ID;

                        reader = cmd.ExecuteReader();
                        while (reader.Read())
                        {
                            user.Hobbies.Add(reader.GetInt32(0));
                        }
                        reader.Close();
                    }
                    catch (SqlException e)
                    {
                        // go to error page
                        throw;
                    }
                    finally
                    {
                        con.Close();
                    }

                }

            }
            return user;
        }
コード例 #9
0
 public void BLLUpdateUserEmail(UserModel selectedUser)
 {
     DalUserManager.DALUpdateUserEmail(selectedUser);
 }
コード例 #10
0
        /*Returns users that match any of the specified criteria*/
        public List<UserModel> SearchForUsersAny(string ageRange, string build, string county, string gender, string height, string profession, string relationshipStatus, string sexualOrientation, string town, List<string> hobbies)
        {
            List<UserModel> users = null;

            using (SqlConnection con = new SqlConnection(conString))
            {
                using (SqlCommand cmd = new SqlCommand(Resources.SEARCH_FOR_ANY_PROC, con))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(Resources.AGE_RANGE_PARAM, SqlDbType.NVarChar).Value = ageRange;
                    cmd.Parameters.Add(Resources.BUILD_PARAM, SqlDbType.NVarChar).Value = build;
                    cmd.Parameters.Add(Resources.COUNTY_PARAM, SqlDbType.NVarChar).Value = county;
                    cmd.Parameters.Add(Resources.GENDER_PARAM, SqlDbType.NVarChar).Value = gender;
                    cmd.Parameters.Add(Resources.HEIGHT_PARAM, SqlDbType.NVarChar).Value = height;
                    cmd.Parameters.Add(Resources.PROFESSION_PARAM, SqlDbType.NVarChar).Value = profession;
                    cmd.Parameters.Add(Resources.RELATIONSHIP_STATUS_PARAM, SqlDbType.NVarChar).Value = relationshipStatus;
                    cmd.Parameters.Add(Resources.SEXUAL_ORIENTATION_PARAM, SqlDbType.NVarChar).Value = sexualOrientation;
                    cmd.Parameters.Add(Resources.TOWN_PARAM, SqlDbType.NVarChar).Value = town;

                    try
                    {
                        con.Open();
                        using (SqlDataReader dr = cmd.ExecuteReader())
                        {
                            users = new List<UserModel>();
                            while (dr.Read())
                            {
                                UserModel user = new UserModel(dr.GetInt32((int)UserProfile.User), dr.GetString(1));
                                user.Age = dr.GetInt32((int)UserProfile.Age);
                                user.Build = dr.GetString((int)UserProfile.Build);
                                user.County = dr.GetString((int)UserProfile.County);
                                user.Ethnicity = dr.GetString((int)UserProfile.Ethnicity);
                                user.EyeColor = dr.GetString((int)UserProfile.EyeColor);
                                user.Gender = dr.GetString((int)UserProfile.Gender);
                                user.HairColor = dr.GetString((int)UserProfile.HairColor);
                                user.Height = dr.GetString((int)UserProfile.Height);
                                user.IdealDate = dr.GetString((int)UserProfile.IdealDate);
                                user.RelationshipStatus = dr.GetString((int)UserProfile.RelationshipStatus);
                                user.Profession = dr.GetString((int)UserProfile.Profession);
                                user.SexualOrientation = dr.GetString((int)UserProfile.SexualOrientation);
                                user.Town = dr.GetString((int)UserProfile.Town);
                                user.ProfilePicturePath = dr.GetString((int)UserProfile.ProfilePicturePath);
                                user.Comments = dr.GetString((int)UserProfile.Comments);

                                users.Add(user);
                            }
                        }

                    }
                    catch (SqlException)
                    {
                        throw;
                    }
                    finally
                    {
                        con.Close();
                    }
                }
            }
            return users;
        }
コード例 #11
0
ファイル: DALMngr.cs プロジェクト: joeLloyd/OOP_v3
        public bool IsValidLogin(UserModel userDetails)
        {
            bool isValid;
            try
            {
                using (SqlConnection cxn = new SqlConnection(cxnString))
                {
                    SqlCommand cmd = new SqlCommand("spValidateUser", cxn);
                    cmd.CommandType = CommandType.StoredProcedure;

                    SqlParameter userNameParam = new SqlParameter("@UserName", SqlDbType.NVarChar, 50);
                    userNameParam.Value = userDetails.UserName;

                    SqlParameter passwordParam = new SqlParameter("@usrPassword", SqlDbType.NVarChar, 50);
                    passwordParam.Value = userDetails.Password;

                    cmd.Parameters.Add(userNameParam);
                    cmd.Parameters.Add(passwordParam);
                    cxn.Open();
                    SqlDataReader dr = cmd.ExecuteReader();

                    if(dr.Read())
                    {
                        isValid = true;
                    }
                    else
                    {
                        isValid = false;
                    }
                    dr.Close();
                    cxn.Close();
                }
                return isValid;
            }
            catch(Exception ex)
            {
                throw ex;
            }
        }
コード例 #12
0
 /*
  * Perform Registration
  */
 protected void btnRegister_Click(object sender, EventArgs e)
 {
     int id = userManager.BLLCreateUser(txtUserName.Text, txtEmail.Text, txtCreatePwd.Text);
     if (id > 0)
     {
         UserModel user = new UserModel(id, txtUserName.Text);
         user.SexualOrientation = ddlOrientation.SelectedValue;
         user.Gender = ddlGender.SelectedValue;
         user.County = ddlCounty.SelectedValue;
         userManager.BLLUpdateUser(user);
         setCurrentUser(user);
         Response.Write("User Created");
         Response.Redirect("DashboardPersonal.aspx",false);
     }
     else
     {
         Response.Write("Failed to create user");
     }
 }
コード例 #13
0
 public void BLLSetHobbies(UserModel user)
 {
     DalUserManager.DALSetHobbies(user);
 }
コード例 #14
0
 public void BLLUpdateUserPassword(UserModel user, String password)
 {
     DalUserManager.DALUpdateUserPassword(user, password);
 }
コード例 #15
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // Instantiate selectedConversation, if required.
                if (selectedConversation == null)
                {
                    selectedConversation = new Conversation();
                }

                // Check if query string contains ConversationID value
                String selectedConvoID = Request.ServerVariables["QUERY_STRING"];

                if (selectedConvoID.Length > 0 && conversationList.Count > 0)
                {
                    /* If a conversation was selected, retreive the selected conversation
                     * according to its ID in conversation<List> and present its messages to the user.
                     * */
                    int selectedIDasInt;
                    if (int.TryParse(selectedConvoID, out selectedIDasInt))
                    {
                        for (int i = 0; i < conversationList.Count; i++)
                        {
                            if (conversationList.ElementAt(i).ConversationID.Equals(selectedIDasInt))
                            {
                                selectedConversation = conversationList.ElementAt(i);
                                break;
                            }
                        }

                        mySummaries.Visible = false;
                        MessageThread.Visible = true;
                        PopulateMessageThread(selectedConversation);
                    }
                }
            try
            {
                userManager = new BLLUserMngr();
                user = userManager.BLLGetCurrentUser(Session);

                messageManager = new BLLMessageMngr(user.ID);
                getMessages();
            }
            catch (Exception)
            {
                //Log error
                Response.Redirect("404.aspx");
            }
        }
コード例 #16
0
        /* Updates a user in the the UserInformation Table */
        public void DALUpdateUserDetails(UserModel user)
        {
            string addHobbiesQuery = string.Empty;

            if (user.Hobbies != null && user.Hobbies.Count > 0)
            {
                addHobbiesQuery = "INSERT " + Resources.USER_HOBBIES_TABLE + " VALUES ";
                foreach (int hobbyID in user.Hobbies)
                {
                    addHobbiesQuery += string.Format("({0},{1}),", user.ID, hobbyID);
                }
                addHobbiesQuery = addHobbiesQuery.Substring(0, addHobbiesQuery.Length - 1);
            }
            using (SqlConnection con = new SqlConnection(conString))
            {
                using (SqlCommand cmd = new SqlCommand(Resources.USER_DETAILS_UPDATE_PROC, con))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    if (user.ID > 0)
                        cmd.Parameters.Add(Resources.USERID_PARAM, SqlDbType.Int).Value = user.ID;
                    else
                        return;

                    if (user.Profession != null)
                        cmd.Parameters.Add(Resources.PROFESSION_PARAM, SqlDbType.NVarChar).Value = user.Profession;
                    if (user.Town != null)
                        cmd.Parameters.Add(Resources.TOWN_PARAM, SqlDbType.NVarChar).Value = user.Town;
                    if (user.County != null)
                        cmd.Parameters.Add(Resources.COUNTY_PARAM, SqlDbType.NVarChar).Value = user.County;
                    if (user.Gender != null)
                        cmd.Parameters.Add(Resources.GENDER_PARAM, SqlDbType.NVarChar).Value = user.Gender;
                    if (user.SexualOrientation != null)
                        cmd.Parameters.Add(Resources.SEXUAL_ORIENTATION_PARAM, SqlDbType.NVarChar).Value = user.SexualOrientation;
                    if (user.Age > 0)
                        cmd.Parameters.Add(Resources.AGE_PARAM, SqlDbType.Int).Value = user.Age;
                    if (user.HairColor != null)
                        cmd.Parameters.Add(Resources.HAIR_COLOR_PARAM, SqlDbType.NVarChar).Value = user.HairColor;
                    if (user.EyeColor != null)
                        cmd.Parameters.Add(Resources.EYE_COLOR_PARAM, SqlDbType.NVarChar).Value = user.EyeColor;
                    if (user.Height != null)
                        cmd.Parameters.Add(Resources.HEIGHT_PARAM, SqlDbType.NVarChar).Value = user.Height;
                    if (user.Build != null)
                        cmd.Parameters.Add(Resources.BUILD_PARAM, SqlDbType.NVarChar).Value = user.Build;
                    if (user.Ethnicity != null)
                        cmd.Parameters.Add(Resources.ETHNICITY_PARAM, SqlDbType.NVarChar).Value = user.Ethnicity;
                    if (user.RelationshipStatus != null)
                        cmd.Parameters.Add(Resources.RELATIONSHIP_STATUS_PARAM, SqlDbType.NVarChar).Value = user.RelationshipStatus;
                    if (user.IdealDate != null)
                        cmd.Parameters.Add(Resources.IDEAL_DATE_PARAM, SqlDbType.NVarChar).Value = user.IdealDate;
                    if (user.Comments != null)
                        cmd.Parameters.Add(Resources.COMMENT_PARAM, SqlDbType.NVarChar).Value = user.Comments;
                    try
                    {
                        con.Open();
                        int rowsAffected = cmd.ExecuteNonQuery();

                        if (addHobbiesQuery != null && addHobbiesQuery.Length > 0)
                        {
                            cmd.Parameters.Clear();
                            cmd.CommandType = CommandType.Text;
                            cmd.CommandText = addHobbiesQuery;
                            rowsAffected = cmd.ExecuteNonQuery();
                        }
                    }
                    catch (SqlException e)
                    {
                        throw new Exception("Error Adding Attributes to User: " + e.Message);
                    }
                    finally
                    {
                        con.Close();
                    }
                }
            }
        }
コード例 #17
0
        /* Updates the user's password*/
        public void DALUpdateUserPassword(UserModel user, string password)
        {
            using (SqlConnection con = new SqlConnection(conString))
            {
                using (SqlCommand cmd = new SqlCommand(Resources.USER_ACCOUNT_UPDATE_PROC, con))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(Resources.USERID_PARAM, SqlDbType.Int).Value = user.ID;
                    cmd.Parameters.Add(Resources.PASSWORD_PARAM, SqlDbType.NVarChar).Value = password;
                                        
                    try
                    {
                        con.Open();
                        int rowsAffected = cmd.ExecuteNonQuery();

                    }
                    catch (SqlException e)
                    {
                        throw new Exception("Error Updating User Account: " + e.Message);
                    }
                    finally
                    {
                        con.Close();
                    }
                }
            }
        }
コード例 #18
0
        /*Returns users that match the specified criteria exactly*/
        public List<UserModel> DALSearchForUsersExact(string ageRange, string build, string county, string gender, string height, string profession, string relationshipStatus, string sexualOrientation, string town, List<int> hobbies)
        {
            bool isAgeRange = ageRange != null && ageRange.Length > 0;
            bool isBuild = build != null && build.Length > 0;
            bool isCounty = county != null && county.Length > 0;
            bool isGender = gender != null && gender.Length > 0;
            bool isHeight = height != null && height.Length > 0;
            bool isProfession = profession != null && profession.Length > 0;
            bool isRelationshipStatus = relationshipStatus != null && relationshipStatus.Length > 0;
            bool isSexualOrientation = sexualOrientation != null && sexualOrientation.Length > 0;
            bool isTown = town != null && town.Length > 0;
            bool isHobbies = hobbies != null && hobbies.Count > 0;

            bool selectAll = !(
                isAgeRange
                || isBuild
                || isCounty
                || isGender
                || isHeight
                || isProfession
                || isRelationshipStatus
                || isSexualOrientation
                || isTown
                || isHobbies);

            string query;
            if (!selectAll)
            {
                int paramVal = 0;
                query = "SELECT Users.UserID, Users.Username, Age, Build, County, Ethnicity, EyeColor, Gender, HairColor, Height, IdealDate, RelationshipStatus, Profession, SexualOrientation, Town, ProfilePicturePath, Comments "
                    + " FROM " + Resources.USER_INFORMATION_TABLE
                    + " INNER JOIN dbo.Users ON UserInformation.UserID = Users.UserID"
                    + " INNER JOIN UserHobbies ON UserInformation.UserID = UserHobbies.UserID"
                    + " WHERE ";

                if (isAgeRange) query += Resources.AGE_RANGE_COLUMN + "=@"+paramVal++.ToString() + " AND ";
                if (isBuild) query += " " + Resources.BUILD_COLUMN + "=@" + paramVal++.ToString() + " AND ";
                if (isCounty) query += " " + Resources.COUNTY_COLUMN + "=@" + paramVal++.ToString() + " AND ";
                if (isGender) query += Resources.GENDER_COLUMN + "=@" + paramVal++.ToString() + " AND ";
                if (isHeight) query += Resources.HEIGHT_COLUMN + "=@" + paramVal++.ToString() + " AND ";
                if (isProfession) query += Resources.PROFESSION_COLUMN + "=@" + paramVal++.ToString() + " AND ";
                if (isRelationshipStatus) query += Resources.RELATIONSHIP_STATUS_COLUMN + "=@" + paramVal++.ToString() + " AND ";
                if (isSexualOrientation) query += Resources.SEXUAL_ORIENTATION_COLUMN + "=@" + paramVal++.ToString() + " AND ";
                if (isTown) query += Resources.TOWN_COLUMN + "=@" + paramVal++.ToString() + " AND ";

                if (hobbies != null && hobbies.Count > 0)
                {
                    query += "(";

                    foreach(int hobbyID in hobbies)
                    {
                        query += string.Format("UserHobbies.HobbyID = @{0} OR ", paramVal++);
                    }
                    query = query.Substring(0, query.Length - 3);
                    query += ")";
                }

                else
                    query = query.Substring(0, query.Length - 5);

            }
            else
            {
                query = Resources.GET_ALL_USERS_PROC;
            }

            List<UserModel> users = null;

            using (SqlConnection con = new SqlConnection(conString))
            {
                using (SqlCommand cmd = new SqlCommand(query, con))
                {
                    if (!selectAll)
                    {
                        cmd.CommandType = CommandType.Text;
                        int paramVal = 0;
                        if (isAgeRange) cmd.Parameters.Add(paramVal++.ToString(), SqlDbType.NVarChar).Value = ageRange;
                        if (isBuild) cmd.Parameters.Add(paramVal++.ToString(), SqlDbType.NVarChar).Value = build;
                        if (isCounty) cmd.Parameters.Add(paramVal++.ToString(), SqlDbType.NVarChar).Value = county;
                        if (isGender) cmd.Parameters.Add(paramVal++.ToString(), SqlDbType.NVarChar).Value = gender;
                        if (isHeight) cmd.Parameters.Add(paramVal++.ToString(), SqlDbType.NVarChar).Value = height;
                        if (isProfession) cmd.Parameters.Add(paramVal++.ToString(), SqlDbType.NVarChar).Value = profession;
                        if (isRelationshipStatus) cmd.Parameters.Add(paramVal++.ToString(), SqlDbType.NVarChar).Value = relationshipStatus;
                        if (isSexualOrientation) cmd.Parameters.Add(paramVal++.ToString(), SqlDbType.NVarChar).Value = sexualOrientation;
                        if (isTown) cmd.Parameters.Add(paramVal++.ToString(), SqlDbType.NVarChar).Value = town;

                        if (hobbies != null && hobbies.Count > 0)
                        {
                            foreach (int hobbyID in hobbies)
                            {
                                cmd.Parameters.Add(paramVal++.ToString(), SqlDbType.Int).Value = hobbyID;
                            }
                        }
                    }
                    else
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                    }

                    try
                    {
                        con.Open();
                        using (SqlDataReader dr = cmd.ExecuteReader())
                        {
                            users = new List<UserModel>();
                            while (dr.Read())
                            {
                                UserModel user = new UserModel(dr.GetInt32((int)UserProfile.User), dr.GetString(1));
                                if (!dr.IsDBNull((int)UserProfile.Age)) user.Age = dr.GetInt32((int)UserProfile.Age);
                                if (!dr.IsDBNull((int)UserProfile.Build)) user.Build = dr.GetString((int)UserProfile.Build);
                                if (!dr.IsDBNull((int)UserProfile.County)) user.County = dr.GetString((int)UserProfile.County);
                                if (!dr.IsDBNull((int)UserProfile.Ethnicity)) user.Ethnicity = dr.GetString((int)UserProfile.Ethnicity);
                                if (!dr.IsDBNull((int)UserProfile.EyeColor)) user.EyeColor = dr.GetString((int)UserProfile.EyeColor);
                                if (!dr.IsDBNull((int)UserProfile.Gender)) user.Gender = dr.GetString((int)UserProfile.Gender);
                                if (!dr.IsDBNull((int)UserProfile.HairColor)) user.HairColor = dr.GetString((int)UserProfile.HairColor);
                                if (!dr.IsDBNull((int)UserProfile.Height)) user.Height = dr.GetString((int)UserProfile.Height);
                                if (!dr.IsDBNull((int)UserProfile.IdealDate)) user.IdealDate = dr.GetString((int)UserProfile.IdealDate);
                                if (!dr.IsDBNull((int)UserProfile.RelationshipStatus)) user.RelationshipStatus = dr.GetString((int)UserProfile.RelationshipStatus);
                                if (!dr.IsDBNull((int)UserProfile.Profession)) user.Profession = dr.GetString((int)UserProfile.Profession);
                                if (!dr.IsDBNull((int)UserProfile.SexualOrientation)) user.SexualOrientation = dr.GetString((int)UserProfile.SexualOrientation);
                                if (!dr.IsDBNull((int)UserProfile.Town)) user.Town = dr.GetString((int)UserProfile.Town);
                                //if (!dr.IsDBNull((int)UserProfile.ProfilePicturePath)) user.ProfilePicturePath = dr.GetString((int)UserProfile.ProfilePicturePath);
                                //if (!dr.IsDBNull((int)UserProfile.Comments)) user.Comments = dr.GetString((int)UserProfile.Comments);

                                users.Add(user);
                            }
                        }

                    }
                    catch (SqlException)
                    {
                        throw;
                    }
                    finally
                    {
                        con.Close();
                    }
                }
            }
            return users;
        }
コード例 #19
0
 public void BLLUpdateUser(UserModel user)
 {
     DalUserManager.DALUpdateUserDetails(user);
 }