public HttpResponseMessage PublishPostToSocial(string r) { try { var dateAfter = DateTime.UtcNow.AddDays(-90); PostRepository repo = new PostRepository(); var posts = repo.FindPublic(1000).Select(x => x.Id).ToList(); var postId = FacebookData.GetRandomPostToSocialize(posts, dateAfter); var token = FacebookData.GetLatestAccessToken(); if (String.IsNullOrEmpty(token)) FacebookData.ResetFacebookConnection(); else { var post = repo.FindById(postId); string baseUrl = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath.TrimEnd('/'); FacebookFactory.Initialize(token) .GetPageAuthorization(ConfigurationManager.AppSettings["FacebookPageName"].ToString(), ConfigurationManager.AppSettings["FacebookPageId"].ToString()) .PostToFanPage(post.Title, baseUrl + post.RelativeLink, baseUrl + post.MainImageUrl, post.Title, post.Title, string.Empty); FacebookFactory.Initialize(token).GetPageAuthorization(ConfigurationManager.AppSettings["FacebookPageName2"].ToString(), ConfigurationManager.AppSettings["FacebookPageId2"].ToString()) .PostToFanPage(post.Title, baseUrl + post.RelativeLink, baseUrl + post.MainImageUrl, post.Title, post.Title, string.Empty); TwitterFactory.Initialize(ConfigurationManager.AppSettings["TwitterConsumerKey"].ToString(), ConfigurationManager.AppSettings["TwitterConsumerSecret"].ToString(), ConfigurationManager.AppSettings["TwitterToken"].ToString(), ConfigurationManager.AppSettings["TwitterTokenSecret"].ToString()) .SendMessage(post.Title + " #rollerderby " + baseUrl + post.RelativeLink); } return Request.CreateResponse(HttpStatusCode.OK); } catch (UnauthorizedAccessException) { return Request.CreateResponse(HttpStatusCode.Unauthorized); } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, GetType()); return Request.CreateResponse(HttpStatusCode.InternalServerError); } }
protected void Page_Load(object sender, EventArgs e) { try { if (Page.IsCallback) return; if (Request.RawUrl.ToLowerInvariant().Contains("/news/")) { DisplayCategories(); } else if (Request.RawUrl.ToLowerInvariant().Contains("/author/")) { DisplayAuthors(); } else if (Request.RawUrl.ToLowerInvariant().Contains("?tag=")) { DisplayTag(); } else { PostRepository repository = new PostRepository(); Posts = repository.FindPublic(take: 60); } StoreItem = SiteCache.GetRandomPublishedStoreItems(3); PostsColumn1 = new List<PostItem>(); PostsColumn2 = new List<PostItem>(); PostsColumn3 = new List<PostItem>(); // var resul = SiteSingleton.Instance.GetLastTweets("#derbyscores");// Search by HashTag var resul = SiteSingleton.Instance.GetTweetsStatus("@rollinnews"); //Get 150 tweets from Home Timeline. Tweets = resul; if (Tweets == null) Tweets = new List<TweetSharp.TwitterStatus>(); int i = 0; foreach (var post in Posts) { if (i % 3 == 0) PostsColumn1.Add(post); else if (i % 3 == 1) PostsColumn2.Add(post); else if (i % 3 == 2) PostsColumn3.Add(post); i += 1; } //Disabled as #derbyscores no longer needed. //Games = RDN.Library.Cache.SiteCache.GetPastGames(0, 15); LeagueOfWeek = SiteCache.GetLeagueOfWeek(); if (LeagueOfWeek != null) { if (!String.IsNullOrEmpty(LeagueOfWeek.Logo.ImageThumbUrl)) LeagueOfWeek.Logo.ImageThumbUrl = LeagueOfWeek.Logo.ImageUrl; } SkaterOfWeek = SiteCache.GetSkaterOfWeek(); if (SkaterOfWeek != null) { if (SkaterOfWeek.Bio.Length > 230) SkaterOfWeek.Bio = SkaterOfWeek.Bio.Remove(230) + "..."; } } catch (Exception exception) { ErrorDatabaseManager.AddException(exception, exception.GetType()); } }