public static UserProfile GetUserProfileById(long id, string db) { UserProfile user = new UserProfile(); string query = "EXEC [stp_SS_GetUser] @id=" + id; SqlConnection myConnection = new SqlConnection(db); try { myConnection.Open(); using (SqlDataAdapter adp = new SqlDataAdapter(query, myConnection)) { SqlCommand cmd = adp.SelectCommand; cmd.CommandTimeout = 300000; System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { user = GetUserFromSqlReader(dr); } } } finally { myConnection.Close(); } return user; }
public static UserProfile GetUserFromSqlReader(SqlDataReader dr) { UserProfile user = new UserProfile(); user.userId = long.Parse(dr["Id"].ToString()); user.pic = dr["Pic"].ToString(); user.userName = dr["UserName"].ToString(); if (!string.IsNullOrEmpty(dr["Name"].ToString())) { user.name = dr["Name"].ToString(); } //if (!string.IsNullOrEmpty(dr["Points"].ToString())) //{ // user.points = int.Parse(dr["Points"].ToString()); //} if (!string.IsNullOrEmpty(dr["Location"].ToString())) { user.location = dr["Location"].ToString(); } if (!string.IsNullOrEmpty(dr["FacebookId"].ToString())) { user.facebookId = long.Parse(dr["FacebookId"].ToString()); } if (!string.IsNullOrEmpty(dr["FbAccessToken"].ToString())) { user.accessToken = dr["FbAccessToken"].ToString(); } if (ColumnExists(dr, "following") && !string.IsNullOrEmpty(dr["following"].ToString())) { user.IsFollowing = int.Parse(dr["following"].ToString()); } if (ColumnExists(dr, "Email") && !string.IsNullOrEmpty(dr["Email"].ToString())) { user.emailId = dr["Email"].ToString(); } if (ColumnExists(dr, "Bio") && !string.IsNullOrEmpty(dr["Bio"].ToString())) { user.bio = dr["Bio"].ToString(); } if (ColumnExists(dr, "Url") && !string.IsNullOrEmpty(dr["Url"].ToString())) { user.url = dr["Url"].ToString(); } if (ColumnExists(dr, "FbPage") && !string.IsNullOrEmpty(dr["FbPage"].ToString())) { user.fbPage = dr["FbPage"].ToString(); } if (ColumnExists(dr, "TwName") && !string.IsNullOrEmpty(dr["TwName"].ToString())) { user.twitterHandle = dr["TwName"].ToString(); } if (ColumnExists(dr, "PinName") && !string.IsNullOrEmpty(dr["PinName"].ToString())) { user.PinterestHandle = dr["PinName"].ToString(); } if (ColumnExists(dr, "TumName") && !string.IsNullOrEmpty(dr["TumName"].ToString())) { user.TumblrHandle = dr["TumName"].ToString(); } if (ColumnExists(dr, "Createtime") && !string.IsNullOrEmpty(dr["Createtime"].ToString())) { DateTime createTime = DateTime.Parse(dr["Createtime"].ToString()); if (DateTime.UtcNow.Subtract(createTime).TotalMinutes > 1) user.IsNew = false; else user.IsNew = true; } if (ColumnExists(dr, "Flags") && !string.IsNullOrEmpty(dr["Flags"].ToString())) { user.userFlags = (UserFlags) Enum.Parse(typeof(UserFlags), dr["Flags"].ToString()); } return user; }
public static UserProfile UpdateUserInfo(UserProfile user, string db) { UserProfile updatedUser = new UserProfile(); //updatedUser = user; int gender = 0; if (user.gender == Sex.Male) gender = 1; string query = "EXEC [stp_SS_UpdateUserInfo] @id=" + user.userId + ", @pic=N'" + user.pic + "', @name=N'" + user.name.Replace("'", "\"") + "', @sex=" + gender + ", @email=N'" + user.emailId + "', @location=N'" + user.location.Replace("'", "\"") + "', @userName=N'" + user.userName + "', @bio=N'" + user.bio + "', @url=N'" + user.url + "', @fbPage='" + user.fbPage + "', @TwName='" + user.twitterHandle + "', @PinName='" + user.PinterestHandle + "', @TumName='" + user.TumblrHandle + "'"; SqlConnection myConnection = new SqlConnection(db); try { myConnection.Open(); using (SqlDataAdapter adp = new SqlDataAdapter(query, myConnection)) { SqlCommand cmd = adp.SelectCommand; cmd.CommandTimeout = 300000; System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { updatedUser = GetUserFromSqlReader(dr); } } } finally { myConnection.Close(); } return updatedUser; }
public static List<UserProfile> GetTaggedPopularStylists(long tagId, long uId, string db) { List<UserProfile> users = new List<UserProfile>(); string query = "EXEC [stp_SS_GetTaggedPopularStylists] @tagId=" + tagId + ",@userId=" + uId; SqlConnection myConnection = new SqlConnection(db); try { myConnection.Open(); using (SqlDataAdapter adp = new SqlDataAdapter(query, myConnection)) { SqlCommand cmd = adp.SelectCommand; cmd.CommandTimeout = 300000; System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { UserProfile user = new UserProfile(); user.userId = long.Parse(dr["Id"].ToString()); user.pic = dr["Pic"].ToString(); user.name = dr["Name"].ToString(); users.Add(user); } } } finally { myConnection.Close(); } return users; }
public static UserProfile SaveOrUpdateUser(UserProfile user, string db) { UserProfile updatedUser = new UserProfile(); updatedUser = user; int gender = 0; if (user.gender == Sex.Male) gender = 1; string fbFriends = "<Friends>"; foreach (long id in user.facebookFriends) { fbFriends += "<Friend Id=\"" + id + "\" />"; } fbFriends += "</Friends>"; string query = "EXEC [stp_SS_SaveUser] @pic=N'" + user.pic + "', @name=N'" + user.name.Replace("'", "\"") + "', @sex=" + gender + ", @email=N'" + user.emailId + "', @location=N'" + user.location.Replace("'", "\"") + "', @facebookId=" + user.facebookId + ", @locale='" + user.locale + "', @fbFriends='" + fbFriends + "'" + ",@flags=" + (int)user.userFlags + ",@token='" + user.accessToken + "'" + ",@referral=N'" + user.Referral + "'" + ", @password=N'" + user.password + "'"; if (!string.IsNullOrEmpty(user.userName)) { query += ", @userName=N'" + user.userName + "'"; } SqlConnection myConnection = new SqlConnection(db); try { myConnection.Open(); using (SqlDataAdapter adp = new SqlDataAdapter(query, myConnection)) { SqlCommand cmd = adp.SelectCommand; cmd.CommandTimeout = 300000; System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { updatedUser = GetUserFromSqlReader(dr); } } } finally { myConnection.Close(); } return updatedUser; }