Exemplo n.º 1
0
        public ActionResult MensagemPost(string message)
        {
            var fb = new FacebookWebClient();

            dynamic parameters = new ExpandoObject();
            parameters.message = message;

            dynamic result = fb.Post("me/feed", parameters);

            return RedirectToAction("Index", new { success = true });
        }
Exemplo n.º 2
0
        public ActionResult Publish()
        {
            var app = new FacebookWebClient();

            dynamic parameters = new ExpandoObject();
            parameters.message = "First wall post!";

            dynamic result = app.Post("/me/feed", parameters);

            return RedirectToAction("About");
        }
Exemplo n.º 3
0
        private static bool SendMessage(IEnumerable<long> pushIds, string subject, string templatePath, Dictionary<string, string> tokens)
        {
            FacebookOAuthClient oAuth = new FacebookOAuthClient(FacebookApplication.Current);
            dynamic tokenResponse = oAuth.GetApplicationAccessToken();
            string accessToken = tokenResponse.access_token;

            FacebookWebClient postApp = new FacebookWebClient(accessToken);

            string body = System.IO.File.ReadAllText(templatePath);

            tokens.Add("CanvasUrl", FacebookApplication.Current.ReturnUrlPath);

            foreach (string key in tokens.Keys)
            {
                body = body.Replace("{" + key + "}", tokens[key]);
            }

            Dictionary<string, object> parameters = new Dictionary<string, object>();
            parameters.Add("method", "notifications.sendEmail");
            parameters.Add("recipients", string.Join(",", pushIds));
            parameters.Add("subject", subject);
            parameters.Add("fbml", body);
            dynamic messageResult = postApp.Post(parameters);

            return true;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Publish a message on a wall
        /// </summary>
        public static void Publish(long wallId, string message, string picture = null, string link = null,
            string name = null, string caption = null, string description = null,
            string source = null)
        {
            try
            {
                var fb = new FacebookWebClient();
                var dic = new Dictionary<string, string> {{"message", message}};
                if (picture != null)
                    dic.Add("picture", picture);
                if (link != null)
                    dic.Add("link", link);
                if (name != null)
                    dic.Add("name", name);
                if (caption != null)
                    dic.Add("caption", caption);
                if (description != null)
                    dic.Add("description", description);
                if (source != null)
                    dic.Add("source", source);

                fb.Post("/" + wallId + "/feed", dic);
            }
            catch (Exception ex)
            {
                _logger.Error("Cannot publish", ex);
                Debug.WriteLine(ex);
            }
        }
Exemplo n.º 5
0
        public void PublishToFacebookWall(int tubeId)
        {
            var user = Membership.GetUser(Membership.GetUserNameByEmail(User.Identity.Name));

            if (personRepository.FirstOrDefault(p => p.UserId == (Guid)user.ProviderUserKey).IsPublish == true && Roles.GetRolesForUser(user.UserName)[0] != "Investor")
            {
                var client = new FacebookWebClient(FacebookWebContext.Current.AccessToken);

                var nominations =
                    participantRepository.GetResult(tubeId).FirstOrDefault(p => p.UserId == (Guid) user.ProviderUserKey)
                        .Nomination;

                var parameters = new Dictionary<string, object>
                                     {
                                         {
                                             "message",
                                             String.Format(
                                                 "Pitch was awarded by investors for {0} points at pitchingtube.com", nominations)
                                         },
                                         {"name", "Pitching Tube"},
                                         {"link", "http://www.pitchingtube.com"},
                                         {"description", "description"}
                                        // {"picture","../../Content/img/Logo.png"}
                                     };

                client.Post("me/feed", parameters);
            }
        }
Exemplo n.º 6
0
        public ActionResult PaymentResult()
        {
            PaymentResultViewModel view = new PaymentResultViewModel();
            Settings cfg = ViewBag.SiteSettings;
            string txToken, query;
            string strResponse;
            txToken = Request.QueryString.Get("tx");
            query = string.Format("cmd=_notify-synch&tx={0}&at={1}", txToken, cfg.PaypalPdtToken);

            // Create the request back
            var req = (HttpWebRequest)WebRequest.Create(cfg.PaypalUrl);

            // Set values for the request back
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            req.ContentLength = query.Length;

            // Write the request back IPN strings
            var stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
            stOut.Write(query);
            stOut.Close();

            // Do the request to PayPal and get the response
            StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream());
            strResponse = stIn.ReadToEnd();
            stIn.Close();

            // sanity check
            //mergeDictionary.Add("reponse", strResponse);

            // If response was SUCCESS, parse response string and output details
            if (strResponse.StartsWith("SUCCESS"))
            {

                var parser = PayPalPDTParser.Parse(strResponse);
                int paymentID = parser.Custom.Decrypt().Replace("tarts_", "").ConvertToInt32(0);
                var payment = Repo.GetById<Payment>(paymentID);
                view.Details = strResponse;
                if(payment == null)
                {
                    view.Success = false;
                    view.Message = "Sorry we could not match the payment to the payment reference, we will investigate this manually";
                    return View(view);
                }

                string debugInfo = strResponse;
                debugInfo += "<br/>" + cfg.PaypalUsername + ":" + parser.BusinessEmail;
                debugInfo += "<br/>" + payment.Amount.ToString() + ":" + parser.GrossTotal.ToString();
                //view.Details += "<br/>" + cfg.PaypalUsername + ":" +  parser.BusinessEmail;
                //view.Details += "<br/>" + payment.Amount.ToString() + ":" +  parser.GrossTotal.ToString();

                if (cfg.PaypalUsername != parser.BusinessEmail)
                {
                    payment.Booking.FailPayment(payment, "Receiver email looked to be invalid. " + debugInfo, PayPalPDTParser.ToString(parser));
                    Repo.Save(payment.Booking);

                    view.Success = false;
                    view.Message = "Payment looks to be invalid, we will investigate manually";
                    return View(view);
                }

                //if (Decimal.Round(payment.Amount,0).ToString() != Decimal.Round(parser.GrossTotal.ConvertToDecimal(0m),0).ToString())
                //{
                //    payment.Booking.FailPayment(payment, "Payment amount looked to be invalid. " + debugInfo, PayPalPDTParser.ToString(parser));
                //    Repo.Save(payment.Booking);

                //    view.Success = false;
                //    view.Message = "Payment looks to be invalid, we will investigate manually";
                //    return View(view);
                //}

                try
                {
                    if (FacebookWebContext.Current.IsAuthenticated())
                    {
                        var client = new FacebookWebClient();
                        dynamic me = client.Get("me");
                        var args = new Dictionary<string, object>();
                        args["message"] = string.Format("Has just bought their ticket for {0} at {1}!", payment.Booking.Event.Name, "http://www.appletartsfestival.co.uk");
                        client.Post("/me/feed", args);
                    }
                }
                catch
                {

                }

                if (parser.PaymentStatus.ToLower() == "completed")
                {
                    payment.Booking.MarkPaymentAsComplete(payment, PayPalPDTParser.ToString(parser));
                    Repo.Save(payment.Booking);
                    var settings = Repo.GetById<Settings>(1);
                    var emailer = new Emailer(settings);
                    var sent = emailer.SendEmail(payment.Booking.Customer.Email, payment.Booking.Customer.FirstName + " " + payment.Booking.Customer.Surname,
                                        "Apple Tarts Booking Confirmation", payment.Booking.Event.BookingConfirmation.ProcessVelocityTemplate(payment.Booking));
                    return RedirectToAction("BookingComplete", "Booking", new {id = payment.Booking.ID});
                }
                else
                {
                    payment.Booking.MarkPaymentAsVerfied(payment, parser.PaymentStatus, PayPalPDTParser.ToString(parser));
                    Repo.Save(payment.Booking);

                    view.Success = true;
                    view.Message = "Thank you your payment has been verfied. We will email you as soon as it is processed and your booking is confirmed. ";
                    return View(view);
                }

            }

            view.Success = false;
            view.Message = "Payment has been sent but not yet verified";
            return View(view);
        }