public ActionResult SendToFacebook(int id)
        {
            var model = repository.Especiales.First(e => e.EspecialId == id);

            try
            {
                var     facebookId = User.Identity.Name;
                var     user       = InMemoryUserStore.Get(facebookId);
                var     client     = new FacebookClient(user.AccessToken);
                dynamic parameters = new ExpandoObject();
                parameters.message = string.Format("{0} esta oferta es valida desde {1} hasta {2}", model.Nombre, model.FechaInicio.ToShortDateString(), model.FechaTermino.ToShortDateString());
                //parameters.link = "http://www.youtube.com/watch?v=tko0vvD0N-E";
                //parameters.picture = "http://i3.ytimg.com/vi/2Me7BRES0wQ/default.jpg";
                parameters.name        = model.Nombre;
                parameters.caption     = model.Precio;
                parameters.description = model.Descripcion;

                dynamic result = client.Post(user.FacebookId + "/feed", parameters);
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Detalles", new { id = id }));
            }

            return(RedirectToAction("Detalles", new { id = id }));
        }
Ejemplo n.º 2
0
 protected override void OnAuthorization(AuthorizationContext filterContext)
 {
     base.OnAuthorization(filterContext);
     if (InMemoryUserStore.Get(User.Identity.Name) == null)
     {
         filterContext.Result = new HttpUnauthorizedResult();
     }
 }
Ejemplo n.º 3
0
        public ActionResult Friends()
        {
            var        user        = InMemoryUserStore.Get(User.Identity.Name);
            var        fb          = new FacebookClient(user.AccessToken);
            JsonObject friendsData = fb.Get("/me/friends") as JsonObject;
            var        data        = friendsData["data"] as JsonArray;

            ViewBag.Friends = data;
            return(View());
        }
Ejemplo n.º 4
0
        public ActionResult ProfileInfo()
        {
            var facebookId = long.Parse(User.Identity.Name);
            var user       = InMemoryUserStore.Get(facebookId);
            var client     = new FacebookClient(user.AccessToken);

            dynamic me = client.Get("me?fields=id,name,username,email,birthday");

            ViewBag.Name     = me.name;
            ViewBag.Id       = me.id;
            ViewBag.Email    = me.email;
            ViewBag.Birthday = me.birthday;
            ViewBag.UserId   = Membership.GetUser().ProviderUserKey;
            return(View());
        }
Ejemplo n.º 5
0
        public ActionResult PostToWall(FormCollection formCollection)
        {
            List <ExpandoObject> results = new List <ExpandoObject>();
            var user = InMemoryUserStore.Get(User.Identity.Name);
            var fb   = new FacebookClient(user.AccessToken);

            var friends = formCollection["chkFriends"];

            if (!string.IsNullOrEmpty(friends))
            {
                string[] users = friends.Split(',');
                foreach (var friend in users)
                {
                    if (!string.IsNullOrEmpty(friend))
                    {
                        dynamic fbFriendValue = fb.Get(string.Format("{0}?fields=id,name", friend));
                        dynamic data          = new ExpandoObject();
                        string  path          = string.Format(@"/{0}/feed", friend);
                        Dictionary <string, object> parameters = new Dictionary <string, object>();
                        parameters.Add("name", formCollection["Name"]);
                        parameters.Add("link", formCollection["Link"]);
                        parameters.Add("picture", formCollection["Picture"]);
                        parameters.Add("message", formCollection["Message"]);
                        parameters.Add("caption", formCollection["Caption"]);
                        if (ConfigurationManager.AppSettings["AllowFeedPosting"] == "True")
                        {
                            dynamic fbFeedValue = fb.Post(path, parameters);
                            data.FeedId = fbFeedValue.id;
                        }
                        else
                        {
                            data.FeedId = -1;
                        }

                        data.FriendName = fbFriendValue.name;
                        results.Add(data);
                    }
                }
            }

            ViewBag.Results = results;
            return(View());
        }
Ejemplo n.º 6
0
        public ActionResult Index()
        {
            try
            {
                var user = InMemoryUserStore.Get(User.Identity.Name);

                var     fb = new FacebookClient(user.AccessToken);
                dynamic me = fb.Get("me");

                ViewBag.name = me.name;
            }
            catch (FacebookApiException)
            {
                FormsAuthentication.SignOut();
                return(new HttpUnauthorizedResult());
            }

            return(View());
        }
Ejemplo n.º 7
0
        //
        // GET: /Account/LogOff/

        public ActionResult LogOff()
        {
            var facebookId = long.Parse(User.Identity.Name);
            var user       = InMemoryUserStore.Get(facebookId);

            FormsAuthentication.SignOut();
            if (user != null)
            {
                var logoutUrl = String.Format("https://www.facebook.com/logout.php?next={0}&access_token={1}", logoffUrl, user.AccessToken);
                return(Redirect(logoutUrl));
            }
            else
            {
                return(Redirect(logoffUrl));
            }


            //var oAuthClient = new FacebookOAuthClient(FacebookApplication.Current);
            //oAuthClient.RedirectUri = new Uri(logoffUrl);
            //var logoutUrl = oAuthClient.GetLogoutUrl();
            //return Redirect(logoutUrl);//.AbsoluteUri);
        }