通过Facebook和Instagram循环

时间:2018-04-04 13:13:25

标签: c# asp.net asp.net-mvc

我遇到了一个小问题,我正在我的网站上显示社交网络Feed,比如facebook和Instagram,这就是问题,当我发布一些东西时,我是通过手机进行的,所以我在Facebook上分享它Instagram同时,这意味着我在网站上有一些重复,来自facebook的文本与Instagram标题文本相同。现在我想要做的是,当facebook文本与instagram标题文本相同时。我不想显示facebook帖子,有人可以帮我这个吗?这是代码

控制器:

        //Instagram
        posts.AddRange((from InstagramMedia media in response.Body.Data
                        select new NewsViewModel
                        {
                            InstagramLink = media.Link,
                            Images = media.Standard,
                            Caption = media.CaptionText,
                            DateAdded = media.Created,
                            InstagramDateTimeAdded = media.Created,
                            LikesCount = media.LikeCount,
                            ProfilePicture = media.User.ProfilePicture


                        })
                                    .ToList());
        //Facebook
        posts.AddRange((from FacebookPost media in responseFB.Body.Data
                        select new NewsViewModel
                        {
                           FaceBookText = media.Message,
                           DateAdded = media.CreatedTime,
                           FacebookDateTimeAdded = media.CreatedTime,
                           FacebookStory = media.Story,
                           FacebookId = media.Id
                       }).ToList());


        return View(posts);`

这是视图

            @if(tweet.FacebookStory != null)
            {
                <div class="facebookFeed-container mb-3 mt-3">
                    <a href="https://facebook.com/iosoftab" target="_blank">
                        <img src="~/Content/img/logos/IosoftFbLogo.png" class="mt-2 ml-2" style="width:40px;" />
                        <span style="color:#5572A9;font-weight:600;position:relative;top:5px; left:10px;">IOSoft AB</span>
                    </a>
                    <hr style="margin-top:5px;" />
                    <p style="padding:10px;
                        overflow-wrap: break-word;
                        word-wrap: break-word;">
                        @tweet.FacebookStory
                    </p>
                    <hr />
                    <div class="bottom-news-facebook">
                        <a href="https://facebook.com/@tweet.FacebookId" target="_blank"><i class="far fa-thumbs-up fa-2x ml-3"></i></a>
                        <span style="float:right;color:#5572A9" class="mr-3">@tweet.DateAdded.ToLongDateString() @tweet.DateAdded.ToShortTimeString()</span>
                    </div>
                </div>
            }
            @if(tweet.Caption != null)
            {
                <div class="instagramFeed-container mb-3 mt-3">
                    <a href="https://www.instagram.com/iosoft/" target="_blank">
                        <img src="@tweet.ProfilePicture" class="mt-2 ml-2" style="width:40px;" />
                        <span style="color:#545454;font-weight:600;position:relative;top:7px; left:10px;">iosoft</span>
                    </a>
                    <img src="@tweet.Images" style="width:100%; margin-top:15px;margin-bottom:10px;" />
                    <div class="bottom-news-instagram">
                        <a href="@tweet.InstagramLink" target="_blank"><i class="far fa-heart fa-2x"></i></a>
                    </div>
                    <p style="padding:10px;
                        overflow-wrap: break-word;
                        word-wrap: break-word;">
                        <span style="font-weight:600">iosoft</span> @tweet.Caption
                    </p>
                    <hr />
                    <div class="instagram-bottom-timeLikes">
                        <span style="font-weight:600;margin-left:10px;">@tweet.LikesCount gilla-markeringar</span>
                        <span style="float:right;color:#5572A9" class="mr-3">@tweet.InstagramDateTimeAdded.AddHours(1)</span>
                    </div>
                </div>
            }
            @if (tweet.FaceBookText != null && tweet.FaceBookText != tweet.Caption)
            {
                <div class="facebookFeed-container mb-3 mt-3">
                    <a href="https://facebook.com/iosoftab" target="_blank">
                        <img src="~/Content/img/logos/IosoftFbLogo.png" class="mt-2 ml-2" style="width:40px;" />
                        <span style="color:#5572A9;font-weight:600;position:relative;top:5px; left:10px;">IOSoft AB</span>
                    </a>
                    <hr style="margin-top:5px;" />
                    <p style="padding:10px;
                        overflow-wrap: break-word;
                        word-wrap: break-word;">
                        @tweet.FaceBookText
                    </p>
                    <hr />
                    <div class="bottom-news-facebook">
                        <a href="https://facebook.com/@tweet.FacebookId" target="_blank"><i class="far fa-thumbs-up fa-2x ml-3"></i></a>
                        <span style="float:right;color:#5572A9" class="mr-3">@tweet.FacebookDateTimeAdded</span>
                    </div>
                </div> 
            }
        </div>`

但我仍然看到facebook帖子,有人知道为什么吗? / Patryk

1 个答案:

答案 0 :(得分:0)

试试tweet.FaceBookText!= null&amp;&amp; tweet.FaceBookText.ToLower()!= tweet.Caption.ToLower()