//Create User Profile and Scope ProfileID public int CreateProfile(ViewProfileDO create) { int profileID = 0; //Try(catch) to open a connection and access the server database try { using (SqlConnection sqlConnect = new SqlConnection(connectionString)) using (SqlCommand sqlCommand = new SqlCommand("CREATE_PROFILE", sqlConnect)) { sqlCommand.CommandType = CommandType.StoredProcedure; sqlConnect.Open(); sqlCommand.Parameters.AddWithValue("@Bio", create.Bio); sqlCommand.Parameters.AddWithValue("@JobTitle", create.JobTitle); sqlCommand.Parameters.AddWithValue("@Achievements", create.Achievements); sqlCommand.Parameters.AddWithValue("@Posts", create.Posts); profileID = (int)sqlCommand.ExecuteScalar(); sqlCommand.ExecuteNonQuery(); } } catch (Exception error) { Logger Error = new Logger(); Error.logErrors(error); } finally { } return(profileID); }
// User Profiles Database Procdures ------------------------------------------------------------------------------------------------------------------------ //Reading all the Profile Information in the database table "UserProfiles" into a List. public ViewProfileDO ViewProfiles(int profileID) { ViewProfileDO userProfile = new ViewProfileDO(); //Try(catch) to open a connection and access the server database try { using (SqlConnection sqlConnect = new SqlConnection(connectionString)) using (SqlCommand sqlCommand = new SqlCommand("VIEW_PROFILE", sqlConnect)) { sqlCommand.CommandType = CommandType.StoredProcedure; sqlConnect.Open(); sqlCommand.Parameters.AddWithValue("@ProfileID", profileID); using (SqlDataReader dataReader = sqlCommand.ExecuteReader()) { //Reads all the data in the UserProfile table by ProfileID. while (dataReader.Read()) { userProfile.ProfileID = (int)dataReader["ProfileID"]; userProfile.UserFirstName = (string)dataReader["UserFirstName"]; userProfile.UserLastName = (string)dataReader["UserLastName"]; userProfile.Email = (string)dataReader["Email"]; userProfile.UserName = (string)dataReader["UserName"]; userProfile.Bio = (string)dataReader["Bio"]; userProfile.JobTitle = (string)dataReader["JobTitle"]; userProfile.Achievements = (string)dataReader["Achievements"]; userProfile.Posts = (string)dataReader["Posts"]; } } } } catch (Exception error) { Logger Error = new Logger(); Error.logErrors(error); } finally { } return(userProfile); }