Beispiel #1
0
        public static Profile GetProfile(int userId)
        {
            Profile profile = null;

            try
            {
                DataAccess DAL = new DataAccess();
                DataTable dt = DAL.select(String.Format("UserId = '{0}'", userId), "UserProfile", NumRows : 1);

                if (dt != null && dt.Rows.Count > 0)
                {
                    DataRow row = dt.Rows[0];
                    string name = Convert.ToString(row["DisplayName"]);
                    string email = Convert.ToString(row["UserName"]);
                    string facebookId = row["FacebookId"] is DBNull ? null : Convert.ToString(row["FacebookId"]);
                    string facebookLink = row["FacebookLink"] is DBNull ? null : Convert.ToString(row["FacebookLink"]);

                    profile = new Profile(userId, name, email, facebookId, facebookLink);
                }
            }
            catch (Exception ex)
            {
                Console.Write("ERROR: An error occured in retrieving the user profile --- " + ex.Message);
            }

            return profile;
        }
Beispiel #2
0
        //User clicked on link
        //We shall update the database to validate his/her account using the provided token
        public static Profile ValidateProfile(Guid Token)
        {
            Profile profile = null;

            try
            {
                var DAL = new DataAccess();
                var dt = DAL.select(String.Format("ValidationToken = '{0}'", Token), "UserProfile", NumRows: 1);

                if (dt != null && dt.Rows.Count > 0)
                {
                    var updateDictionary = new Dictionary<string, object>();

                    updateDictionary.Add("IsValid", true);

                    DAL.update("UserProfile", "ValidationToken = '{0}'", updateDictionary);

                    var row = dt.Rows[0];
                    var UserName = Convert.ToString(row["UserName"]);
                    var profileId = Convert.ToInt32(row["UserId"]);
                    var displayName = Convert.ToString(row["DisplayName"]);
                    var facebookId = row["FacebookId"] is DBNull ? null : Convert.ToString(row["FacebookId"]);
                    var facebookLink = row["FacebookLink"] is DBNull ? null : Convert.ToString(row["FacebookLink"]);

                    profile = new Profile(profileId, displayName, UserName, facebookId, facebookLink);
                }
            }
            catch (Exception ex)
            {
                Console.Write("ERROR: An error occured in retrieving the user profile --- " + ex.Message);
            }

            return profile;
        }