コード例 #1
0
ファイル: FacebookAPI.cs プロジェクト: msanj1/BOTF
        public string getArtistFacebookID(string ArtistName, Proposal proposal, int Current_User)
        {
            string artistName = "BOTF " + ArtistName;
            string ArtistID = "";
            try
            {
                var output = client.Get("fql", new { q = "SELECT page_id FROM page WHERE contains('" + artistName + "') limit 1" });
                var data = (IDictionary<string, object>)output;
                if (data.ContainsKey("data"))
                {
                    var temp = (List<object>)data["data"];
                    foreach (IDictionary<string, object> item in temp)
                    {
                        ArtistID = item["page_id"].ToString();

                    }
                }
                return ArtistID;
            }
            catch (FacebookApiException ex)
            {
                _db.FacebookPostSchedule.Add(new FacebookPostSchedule { DateCreated = DateTime.Now, ErrorCode = 190, ProposalID = proposal.Id, UserId = Current_User, ArtistPost = true });
                _db.SaveChanges();
                return "";

            }
        }
コード例 #2
0
        /*add a facebook post id to database*/
        public void AddOrUpdateFacebookArtistPost(int ProposalId, int UserId, string PostId)
        {
            Service  service = _db.User.FirstOrDefault(c => c.UserId == UserId).Services.FirstOrDefault(c => c.Provider == "facebook");
            Proposal propsal = _db.Proposal.FirstOrDefault(c => c.Id == ProposalId);


            if (service != null && propsal != null)
            {
                propsal.FacebookPostIdArtist = PostId;
                _db.SaveChanges();
            }
        }
コード例 #3
0
ファイル: FacebookAPI.cs プロジェクト: msanj1/BOTFv2
        public dynamic InsertToArtistFeed(Proposal proposal, int CurrentUser, string URL = "")
        {
            dynamic parameters = new ExpandoObject();

            parameters.message = "just suggested you play an event at " + proposal.Venue + " on Battle of the Fans. It has already received " + proposal.Votes + " votes!. Check it out and let your fans know what you think";

            parameters.name    = "We all love music! Who do you want to see?";
            parameters.link    = URL;
            parameters.privacy = new { value = "EVERYONE", };
            string FacebookID = getArtistFacebookID(proposal.Artist, proposal, CurrentUser);



            try
            {
                if (FacebookID == "")
                {
                    return(4); //could not find the artist page
                }
                else
                {
                    var id = client.Post(FacebookID + "/feed", parameters);
                    return(id);
                }
            }
            catch (FacebookApiException ex)
            {
                if (ex.ErrorCode == 100) //postId does not exist
                {
                    proposal.FacebookPostIdArtist = "";
                    _db.SaveChanges();
                    return(1);
                }
                if (ex.ErrorCode == 190) //Token Expired
                {
                    _db.FacebookPostSchedule.Add(new FacebookPostSchedule {
                        DateCreated = DateTime.Now, ErrorCode = 190, ProposalID = proposal.Id, UserId = CurrentUser, ArtistPost = true
                    });
                    _db.SaveChanges();
                    return(2);
                }

                return(3);//another error has happenned
            }
        }
コード例 #4
0
ファイル: FacebookAPI.cs プロジェクト: msanj1/BOTFv2
        public dynamic InsertToFeed(Proposal proposal, int CurrentUser, string URL)
        {
            dynamic parameters = new ExpandoObject();

            parameters.message = "just suggested the event " + "->"
                                 + proposal.Artist + "<-" + " at " + "->" + proposal.Venue + "<-" + " for Battleof the Fans." + " Like this? Get on board and vote for it! "
                                 + "Awesome prizes to be won!" + " Battle of the Fans would like to thank you for dedication to the cause!";


            parameters.name    = "We all love music! Who do you want to see?";
            parameters.link    = URL;
            parameters.picture = proposal.Image;
            parameters.privacy = new { value = "EVERYONE", };

            try
            {
                return(client.Post("/me/feed", parameters));
            }
            catch (FacebookApiException ex)
            {
                if (ex.ErrorCode == 100) //postId does not exist
                {
                    proposal.FacebookPostId = "";
                    _db.SaveChanges();
                    return(1);
                }
                if (ex.ErrorCode == 190) //Token Expired
                {
                    _db.FacebookPostSchedule.Add(new FacebookPostSchedule {
                        DateCreated = DateTime.Now, ErrorCode = 190, ProposalID = proposal.Id, UserId = CurrentUser, ArtistPost = false
                    });
                    _db.SaveChanges();
                    return(2);
                }

                return(3);//another error has happenned
            }
        }
コード例 #5
0
ファイル: FacebookAPI.cs プロジェクト: msanj1/BOTFv2
        public int deleteComment(string commentID, string postID)
        {
            try
            {
                client.Delete(commentID);
                return(0);
            }
            catch (FacebookApiException ex)
            {
                if (ex.ErrorCode == 100) //postId does not exist
                {
                    Proposal proposal = _db.Proposal.FirstOrDefault(c => c.FacebookPostId == postID);
                    proposal.FacebookPostId = "";
                    _db.SaveChanges();
                    return(1);
                }
                if (ex.ErrorCode == 190) //Token Expired
                {
                    return(2);
                }

                return(3);//another error has happenned
            }
        }
コード例 #6
0
ファイル: FacebookScheduler.cs プロジェクト: msanj1/BOTFv2
        public void RunScheduler(string NewToken, int CurrentLoggedInUser)
        {
            ContextDb        _db      = new ContextDb();
            DatabaseCallsApi _api     = new DatabaseCallsApi();
            FacebookAPI      facebook = new FacebookAPI(NewToken);

            _api.AddOrUpdateService(CurrentLoggedInUser, "facebook", NewToken); //update user's token

            var Proposals_lists = _db.FacebookPostSchedule.Where(c => c.UserId == CurrentLoggedInUser && c.ErrorCode != 900).ToList();


            var Comments_lists = _db.FacebookCommentSchedule.Where(c => c.UserId == CurrentLoggedInUser && c.ErrorCode != 900).ToList();

            if (Proposals_lists.Count > 0)
            {
                //


                foreach (var post in Proposals_lists)
                {
                    Proposal proposal = _db.Proposal.FirstOrDefault(c => c.Id == post.ProposalID);
                    if (proposal != null)
                    {
                        dynamic status;
                        if (post.ArtistPost)
                        {
                            status = facebook.InsertToArtistFeed(proposal, CurrentLoggedInUser, System.Web.HttpContext.Current.Request.UrlReferrer.ToString());
                            if (!(status is int))
                            {
                                proposal.FacebookPostIdArtist = status.id;
                                _db.FacebookPostSchedule.Remove(post);
                                _db.SaveChanges();
                            }
                        }
                        else
                        {
                            status = facebook.InsertToFeed(proposal, CurrentLoggedInUser, System.Web.HttpContext.Current.Request.UrlReferrer.ToString());
                            if (!(status is int))
                            {
                                proposal.FacebookPostId = status.id;
                                _db.FacebookPostSchedule.Remove(post);
                                _db.SaveChanges();
                            }
                        }
                        //do something
                    }
                    else
                    {
                        _db.FacebookPostSchedule.Remove(post);
                        _db.SaveChanges();
                    }
                }
                //
            }
            if (Comments_lists.Count > 0)
            {
                foreach (var comment in Comments_lists)
                {
                    int status = facebook.postCommentToPost(comment.FacebookPostId, comment.Body, comment.UserId);
                    if (status == 0)
                    {
                        _db.FacebookCommentSchedule.Remove(comment);
                        _db.SaveChanges();
                    }
                }
            }
        }
コード例 #7
0
ファイル: ProposalsController.cs プロジェクト: msanj1/BOTF
        public HttpResponseMessage PostProposal(ViewProposal proposal)
        {
            if (ModelState.IsValid)
            {

                 try
                 {

                     dynamic ArtistData = lastfm.GetArtistInfo(proposal.artist); //grab data from LastFM
                     Models.User u = _db.User.FirstOrDefault(c=>c.UserId == WebSecurity.CurrentUserId);
                     if (u.RemainingProposals <= 0)
                     {
                             return  Request.CreateResponse(HttpStatusCode.Forbidden); //check if user can propose a new proposal or not
                     }

                     Proposal temp = new Proposal { Artist = ArtistData.ArtistName, Biography = ArtistData.ArtistBio, Genre = ArtistData.MusicGenre, Image = ArtistData.PictureURL, Venue = proposal.venue, Votes = 0, ProposedBy = WebSecurity.CurrentUserId };
                     var DatabaseIntegrityCHK = _db.Proposal.FirstOrDefault(c => c.Venue == temp.Venue && c.Artist == temp.Artist);
                     if (DatabaseIntegrityCHK != null) //check if a similar proposal exists
                     {
                         return Request.CreateResponse(HttpStatusCode.Conflict);
                     }
                     u.Proposals.Add(temp);

                     //_db.Proposal.Add(temp);

                     _db.SaveChanges();
                      Models.User user =  _db.User.First(c=> c.UserId == WebSecurity.CurrentUserId);
                     user.RemainingProposals--; //reduce remaining proposal

                     //_db.VoteHistory.Add(new Domain.VoteHistory { ProposalId =temp.Id, UserId=WebSecurity.CurrentUserId });
                     _db.SaveChanges();

                     //Proposal list = new Proposal { Id = propId, id = propId.ToString(), UserId = (ObjectId)userId, Artist = artist, Venue = venue, Votes = 0, Image = image, UsersName = userName, Biography = ArtistData.ArtistBio, Genre = ArtistData.MusicGenre};
                     var response = new HttpResponseMessage(HttpStatusCode.Created);
                     response.Headers.Location = new Uri(Request.RequestUri, "/api/FacebookProposal?Id=" + temp.Id + "&ArtistPost=" + false); //header for background post to feed and tweeter page

                     //response.Headers = temp;

                     return response;
                 }
                 catch (Exception)
                 {
                     return Request.CreateResponse(HttpStatusCode.BadRequest);

                 }

            }else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }
コード例 #8
0
ファイル: FacebookAPI.cs プロジェクト: msanj1/BOTF
        public dynamic InsertToFeed(Proposal proposal, int CurrentUser, string URL)
        {
            dynamic parameters = new ExpandoObject();

            parameters.message = "just suggested the event " + "->"
             + proposal.Artist + "<-" + " at " + "->" + proposal.Venue + "<-" + " for Battleof the Fans." + " Like this? Get on board and vote for it! "
             + "Awesome prizes to be won!" + " Battle of the Fans would like to thank you for dedication to the cause!";

            parameters.name = "We all love music! Who do you want to see?";
            parameters.link = URL;
            parameters.picture = proposal.Image;
            parameters.privacy = new { value = "EVERYONE", };

            try
            {
                return client.Post("/me/feed", parameters);

            }
            catch (FacebookApiException ex)
            {
                if (ex.ErrorCode == 100) //postId does not exist
                {

                    proposal.FacebookPostId = "";
                    _db.SaveChanges();
                    return 1;
                }
                if (ex.ErrorCode == 190) //Token Expired
                {
                    _db.FacebookPostSchedule.Add(new FacebookPostSchedule { DateCreated = DateTime.Now, ErrorCode = 190, ProposalID = proposal.Id, UserId = CurrentUser, ArtistPost=false });
                    _db.SaveChanges();
                    return 2;
                }

                return 3;//another error has happenned

            }
        }
コード例 #9
0
ファイル: FacebookAPI.cs プロジェクト: msanj1/BOTF
        public dynamic InsertToArtistFeed(Proposal proposal, int CurrentUser, string URL="")
        {
            dynamic parameters = new ExpandoObject();

            parameters.message = "just suggested you play an event at " + proposal.Venue + " on Battle of the Fans. It has already received " + proposal.Votes + " votes!. Check it out and let your fans know what you think";

            parameters.name = "We all love music! Who do you want to see?";
            parameters.link = URL;
            parameters.privacy = new { value = "EVERYONE", };
            string FacebookID = getArtistFacebookID(proposal.Artist,proposal,CurrentUser);

            try
            {
                if (FacebookID == "")
                {
                    return 4; //could not find the artist page
                }
                else
                {

                    var id = client.Post(FacebookID + "/feed", parameters);
                    return id;
                }

            }
            catch (FacebookApiException ex)
            {
                if (ex.ErrorCode == 100) //postId does not exist
                {

                    proposal.FacebookPostIdArtist = "";
                    _db.SaveChanges();
                    return 1;
                }
                if (ex.ErrorCode == 190) //Token Expired
                {
                    _db.FacebookPostSchedule.Add(new FacebookPostSchedule { DateCreated = DateTime.Now, ErrorCode = 190, ProposalID = proposal.Id, UserId = CurrentUser, ArtistPost=true });
                    _db.SaveChanges();
                    return 2;
                }

                return 3;//another error has happenned

            }
        }