Inheritance: BaseService, IWehackDataService
Beispiel #1
0
        public ActionResult Form()
        {
            WehackDataService service = new WehackDataService();
            IncidentAddRequest model = new IncidentAddRequest();
            model.categoryId = 2;
            model.Lat = -118.229819;
            model.Lng = 33.957508;
            model.UserId = 1;

            return View();
        }
        public ActionResult TweetRetweet()
        {
            IncidentAddRequest model = new IncidentAddRequest();
            model.categoryId = Convert.ToInt16(Request.QueryString["CategoryId"]);
            model.UserId = Convert.ToInt16(Request.QueryString["UserId"]);
            model.Lat = Convert.ToDouble(Request.QueryString["Lat"]);
            model.Lng = Convert.ToDouble(Request.QueryString["Lng"]);


            //HttpResponseMessage resp = null;
            try
            {
                //ComplaintStatusType status = ComplaintStatusType.NotSet;

                //Check location and category of tweet to see if complaint already exists
                WehackDataService service = new WehackDataService();
                IncidentResponse incident = service.CreateComplaint(model);

                if (incident == null || incident.TweetId == null)
                {
                    //get auth context
                    //create tweet
                    //assign tweetId back to database
                    //template: @riadosaband Issue #93 Pothole! 33.940109, -118.133159 #lahasissues
                    var categoryString = model.categoryId == 1 ? "Pothole" : "Streetlight";
                    var tweet = "@riadosaband " + "#" + categoryString + incident.IncidentId.ToString() + " " + model.Lat + ", " + model.Lng + " #lahasissues";

                    var auth = new MvcAuthorizer
                    {
                        CredentialStore = new SessionStateCredentialStore(System.Web.HttpContext.Current.Session)
                    };
                    try
                    {
                        Task.Run(() => wehack.Services.TwitterService.SendTweet(auth, tweet));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }

                    
                }
                else
                {

                    var auth = new MvcAuthorizer
                    {
                        CredentialStore = new SessionStateCredentialStore(System.Web.HttpContext.Current.Session)
                    };
                    try
                    {
                        Task.Run(() => wehack.Services.TwitterService.ReTweet(auth, Convert.ToInt16(incident.TweetId)));

                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }

                }
                
            }
            catch (Exception ex)
            {
                throw ex;//resp = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex);
            }
            return RedirectToAction("IssueFeed", "Home");  //RedirectToRoute("IssueFeed", "Home");
        }