示例#1
0
        public static int AddUser(UserProfile elm)
        {
            int id = -1;

            try
            {
                DataAccessLayer DAL = new DataAccessLayer();
                DataTable dt = DAL.select(String.Format("FacebookID = '{0}'", elm.FacebookID), "UserProfile");

                if (dt == null ||dt.Rows.Count == 0)
                {
                    Dictionary<string, string> Profile = new Dictionary<string, string>();
                    Profile.Add("FacebookID", elm.FacebookID);
                    Profile.Add("Name", elm.Name);
                    Profile.Add("Email", elm.Email);
                    Profile.Add("FacebookProfileLink", elm.FacebookProfileLink);
                    Profile.Add("Gender", elm.Gender);
                    Profile.Add("IsActive", "1");
                    Profile.Add("IsDeleted", "0");
                    Profile.Add("CreatedDate", Convert.ToString(DateTime.Now));
                    Profile.Add("ModifiedDate", Convert.ToString(DateTime.Now));
                    id = DAL.insert(Profile, "UserProfile");
                }
            }
            catch (Exception ex)
            {
                Console.Write("ERROR: An error occured in adding a new user --- " + ex.Message);
            }

            return id;
        }
示例#2
0
        public static UserProfile getUserProfile(int profileID)
        {
            UserProfile profile = null;

            try
            {
                DataAccessLayer DAL = new DataAccessLayer();
                DataTable dt = DAL.select(String.Format("ProfileID = '{0}'", profileID), "UserProfile");

                if (dt != null && dt.Rows.Count > 0)
                {
                    DataRow row = dt.Rows[0];

                    string facebookID = Convert.ToString(row["FacebookID"]);
                    string name = Convert.ToString(row["Name"]);
                    string email = Convert.ToString(row["Email"]);
                    string facebookProfileLink = Convert.ToString(row["FacebookProfileLink"]);
                    string gender = Convert.ToString(row["Gender"]);

                    profile = new UserProfile(name, facebookProfileLink, facebookID, gender, email, String.Empty);
                }
            }
            catch (Exception ex)
            {
                Console.Write("ERROR: An error occured in retrieving the user profile --- " + ex.Message);
            }

            return profile;
        }
示例#3
0
        public ActionResult FacebookCallback(string code, string returnUrl)
        {
            var fb = new FacebookClient();
            dynamic result = fb.Post("oauth/access_token", new
            {
                // Production :
                client_id = "410278782401754",
                client_secret = "4d0fd841a025dd908191f50b86ec90f7",
                // Development :
                //client_id = "424967934259582",
                //client_secret = "7d491f9e46f04614240c0043094fd2d5",
                redirect_uri = RedirectUri.AbsoluteUri,
                code = code
            });

            var accessToken = result.access_token;

            // Store the access token in the session
            Session["AccessToken"] = accessToken;

            // update the facebook client with the access token so
            // we can make requests on behalf of the user
            fb.AccessToken = accessToken;

            // Get the user's information
            IDictionary<string, object> user = (IDictionary<string, object>)fb.Get("me"); //get the current user

            UserProfile userProfile = new UserProfile(
                Convert.ToString(user["name"]),
                Convert.ToString(user["link"]),
                Convert.ToString(user["id"]),
                Convert.ToString(user["gender"]),
                Convert.ToString(user["email"]), String.Empty);

            AccountHandler.AddUser(userProfile);

            // Set the auth cookie
            FormsAuthentication.SetAuthCookie(Convert.ToString(user["name"]), false);

            return RedirectToAction("Index", "Home");
        }