Esempio n. 1
0
        //public ItemsResponse<Incident> GetComplaint(IncidentAddRequest model)
        //{
        //    ItemsResponse<Incident> resp = new ItemsResponse<Incident>();

        //    List<SqlParameter> collection = new List<SqlParameter>();
        //    collection.Add(CreateParameter("@categoryId", model.CategoryId, SqlDbType.Int, ParameterDirection.Input));
        //    collection.Add(CreateParameter("@lat", model.Lat, SqlDbType.BigInt, ParameterDirection.Input));
        //    collection.Add(CreateParameter("@lng", model.Lng, SqlDbType.BigInt, ParameterDirection.Input));

        //    Func<IDataRecord, Incident> complaintReader = delegate (IDataRecord record)
        //    {
        //        Incident req = new Incident();
        //        req.Id = record.GetInt32(0);
        //        req.Lat = record.GetDouble(1);
        //        req.Lng = record.GetDouble(2);
        //        req.Status = (ComplaintStatusType)record.GetInt32(3);
        //        req.CategoryId = record.GetInt32(4);
        //        req.TweetId = record.GetInt32(5);

        //        return req;
        //    };

        //    try
        //    {
        //        resp.Items = ExecuteReader<Incident>("DBNAME", "SP_NAME", complaintReader, collection);
        //        resp.IsSuccessFull = true;
        //    }
        //    catch (Exception ex)
        //    {
        //        throw new Exception(ex.Message);
        //    }

        //    return resp;
        //}

        public IncidentResponse CreateComplaint(IncidentAddRequest model)
        {
            //var id = 0;

            List<SqlParameter> collection = new List<SqlParameter>();
            collection.Add(CreateParameter("@categoryId", model.categoryId, SqlDbType.Int, ParameterDirection.Input));
            collection.Add(CreateParameter("@lat", model.Lat, SqlDbType.Float, ParameterDirection.Input));
            collection.Add(CreateParameter("@lng", model.Lng, SqlDbType.Float, ParameterDirection.Input));
            collection.Add(CreateParameter("@userId", model.UserId, SqlDbType.Int, ParameterDirection.Input));
            collection.Add(CreateParameter("@TweetId", null, SqlDbType.BigInt, ParameterDirection.Output));
            collection.Add(CreateParameter("@IncidentId", null, SqlDbType.Int, ParameterDirection.Output));


            ExecuteNonQuery("wehackdb", "dbo.Incident_Insert", collection);

            //id = (int)collection.FirstOrDefault(x => x.ParameterName == "@userId").SqlValue;

            IncidentResponse resp = new IncidentResponse();
            if (collection.FirstOrDefault(x => x.ParameterName == "@TweetId").Value == DBNull.Value)
            {
                resp.TweetId = null;
            }
            else
            {
                resp.TweetId = (long?)collection.FirstOrDefault(x => x.ParameterName == "@TweetId").SqlValue;
            }
            resp.IncidentId = (int)collection.FirstOrDefault(x => x.ParameterName == "@IncidentId").Value;

            return resp;
        }
        public HttpResponseMessage SendComplaint(IncidentAddRequest model)
        {
            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*/_wehackDataService.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";

                    TwitterActionController contrlr = new TwitterActionController();

                    contrlr.Send(tweet);

                    incident.TweetId = 688120489823186944;  //<--- this is for testing!!

                    //assign tweetId back to database; update tweet; use UPDATE stored proc
                    IncidentUpdateRequest iur = new IncidentUpdateRequest();
                    iur.TweetId = (long)incident.TweetId; //3333333333;
                    iur.IncidentId = incident.IncidentId;
                    _wehackDataService.UpdateComplaint(iur);
                }
                else 
                {
                    //retweet existing tweet
                }
                //ComplaintModel existingComplaint = WehackDataService.GetComplaint(model);

                //if(existingComplaint == null) { WehackDataService.CreateComplaint(model); }
                //  else { 
                        //bool userIsAdmin = WehackDataService.CheckIfUserAdmin(model.userId);
                        //if(userisAdmin) 
                        //{
                        //      status = model.Message.ParseStatus();
                        //      if(status == ComplaintStatusType.Resolved) { WehackDataService.SendResolve(existingComplaint); }
                        //}
                        //else
                            //TwitterService.Retweet(existingComplaint); 
                //}

                resp = Request.CreateResponse(HttpStatusCode.OK);
            }
            catch (Exception ex)
            {
                resp = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex);
            }

            return resp;
        }
Esempio n. 3
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");
        }