Пример #1
0
        public async Task <Following> Create(Following following)
        {
            // TODO: Handle Exception for multiple entries
            AppUser follower = await _dbContext.Users.FirstOrDefaultAsync(u => u.Id == following.FollowerId);

            if (follower == null)
            {
                throw new ArgumentNullException("Follower not found");
            }

            AppUser followee = await _dbContext.Users.FirstOrDefaultAsync(u => u.Id == following.FolloweeId);

            if (followee == null)
            {
                throw new ArgumentNullException("Followee not found");
            }

            FollowingModel model = new FollowingModel {
                FollowerId = following.FollowerId,
                FolloweeId = following.FolloweeId
            };

            _dbContext.Following.Add(model);
            await _dbContext.SaveChangesAsync();

            return(new Following {
                Id = model.Id,
                Follower = follower,
                FollowerId = model.FollowerId,
                Followee = followee,
                FolloweeId = model.FolloweeId
            });
        }
Пример #2
0
        public List <FollowingModel> GetFollowing(int personId)
        {
            List <FollowingModel> list = new List <FollowingModel>();

            sqlCommand = new SqlCommand()
            {
                Connection  = connectionHelper.connection,
                CommandType = CommandType.StoredProcedure,
                CommandText = "FollowingSP",
            };

            sqlCommand.Parameters.Add("@PersonId", SqlDbType.Int).Value = personId;

            connectionHelper.connection.Open();
            SqlDataReader sqlReader = sqlCommand.ExecuteReader();

            if (sqlReader.HasRows)
            {
                while (sqlReader.Read())
                {
                    var model = new FollowingModel()
                    {
                        Id   = Convert.ToInt32(sqlReader["Id"]),
                        Name = sqlReader["Name"] as string
                    };

                    list.Add(model);
                }
            }

            connectionHelper.connection.Close();

            return(list);
        }
        public JsonResult UnfollowJSON(string Id)
        {
            var currentUser = idb.Users.Find(User.Identity.GetUserId());

            repository.DeleteFollowingUser(currentUser.Id, Id);
            List <FollowingModel>  _FollowingList = new List <FollowingModel>();
            List <ApplicationUser> _Users         = idb.Users.Where(l => l.LocationID == currentUser.LocationID && l.Id != currentUser.Id).ToList();

            foreach (ApplicationUser item in _Users)
            {
                FollowingModel _Fmodel = new FollowingModel
                {
                    FirstName = item.FirstName,
                    LastName  = item.LastName,
                    UserID    = item.Id,
                    UserName  = item.UserName,
                    following = repository.IsFollowing(currentUser.Id, item.Id)
                };
                _FollowingList.Add(_Fmodel);
            }

            return(Json(new
            {
                success = true
            }, JsonRequestBehavior.AllowGet));
        }
Пример #4
0
        public async Task <ActionResult> Following()
        {
            ViewBag.Message = TempData["result"] as string;

            using (var context = new EntityFramework())
            {
                var authenticateResult = await HttpContext.GetOwinContext().Authentication.AuthenticateAsync("ExternalCookie");

                long user = Convert.ToInt64(authenticateResult.Identity.Claims.FirstOrDefault(x => x.Type == "urn:twitter:userid").Value);

                FollowingModel following = new FollowingModel
                {
                    //get list of all possible news sources and topics to follow
                    AllSources = ((from pub in context.Set <Publisher>()
                                   select new
                    {
                        pub.PID,
                        pub.Name,
                        pub.Description,
                        pub.URL
                    }).ToList()
                                  .Select(x => new Publisher {
                        PID = x.PID, Name = x.Name, Description = x.Description, URL = x.URL
                    })).ToList(),
                    AllTopics = ((from top in context.Set <Category>()
                                  select new
                    {
                        top.CID,
                        top.Country
                    }).ToList()
                                 .Select(x => new Category {
                        CID = x.CID, Country = x.Country
                    })).ToList(),
                    FollowedTopics = ((from category in context.Set <Category>()
                                       where (
                                           (from subcat in context.User_Category
                                            where subcat.UserID.Equals(user)
                                            select subcat.CategoryID)
                                           .ToList())
                                       .Contains(category.ID)
                                       select category.CID)
                                      .ToList().Select(x => new Category {
                        CID = x
                    })).ToList(),
                    FollowedSources = ((from source in context.Set <Publisher>()
                                        where (
                                            (from subcat in context.User_Publisher
                                             where subcat.UserID.Equals(user)
                                             select subcat.PublisherID)
                                            .ToList())
                                        .Contains(source.PID)
                                        select new { source.PID, source.Name })
                                       .ToList().Select(x => new Publisher {
                        PID = x.PID, Name = x.Name
                    })).ToList()
                };

                return(View(following));
            }
        }
Пример #5
0
        public ActionResult Index()
        {
            FollowingModel        model       = new FollowingModel();
            EFILE_CHIASE_SEARCHBO searchModel = new EFILE_CHIASE_SEARCHBO();

            searchModel.USER_ID  = GetUserInfo().ID;
            EFILE_CHIASEBusiness = Get <EFILE_CHIASEBusiness>();
            model.ListChiaSe     = EFILE_CHIASEBusiness.GetDaTaByPage(searchModel);
            SessionManager.SetValue("FollowingSearch", searchModel);
            return(View(model));
        }
Пример #6
0
        public async Task <bool> ExistFollowing(Following following)
        {
            FollowingModel model = await _dbContext.Following
                                   .FirstOrDefaultAsync(f => f.FollowerId == following.FollowerId && f.FolloweeId == following.FolloweeId);

            if (model == null)
            {
                return(false);
            }

            return(true);
        }
Пример #7
0
        public async Task Remove(Following following)
        {
            FollowingModel model = await _dbContext.Following
                                   .FirstOrDefaultAsync(f => f.FollowerId == following.FollowerId && f.FolloweeId == following.FolloweeId);

            if (model == null)
            {
                throw new ArgumentException("Following not exist");
            }

            _dbContext.Following.Remove(model);
            await _dbContext.SaveChangesAsync();
        }
        public FollowingModel GetFollowing(string id, string maxResults, string paginationToken)
        {
            UsersClient client = new UsersClient(_oAuthInfo);

            // these override the base behaviour for the user service when fetching followers
            string tweetFields = "attachments,author_id,context_annotations,conversation_id,created_at,entities,geo,id,in_reply_to_user_id,lang,non_public_metrics,public_metrics,organic_metrics,promoted_metrics,possibly_sensitive,referenced_tweets,reply_settings,source,text,withheld";
            string userFields  = "created_at,description,entities,id,location,name,pinned_tweet_id,profile_image_url,protected,public_metrics,url,username,verified,withheld";

            string followersJson = client.GetFollowing(id, _expansionsFields, maxResults, paginationToken, tweetFields, userFields);

            FollowingDTO resultsDTO = JsonConvert.DeserializeObject <FollowingDTO>(followersJson);

            FollowingModel models = _iMapper.Map <FollowingDTO, FollowingModel>(resultsDTO);

            return(models);
        }
        public ActionResult Follow()
        {
            var currentUser = idb.Users.Find(User.Identity.GetUserId());
            List <FollowingModel>  _FollowingList = new List <FollowingModel>();
            List <ApplicationUser> _Users         = idb.Users.Where(l => l.LocationID == currentUser.LocationID && l.Id != currentUser.Id).ToList();

            foreach (ApplicationUser item in _Users)
            {
                FollowingModel _Fmodel = new FollowingModel {
                    FirstName = item.FirstName,
                    LastName  = item.LastName,
                    UserID    = item.Id,
                    UserName  = item.UserName,
                    following = repository.IsFollowing(currentUser.Id, item.Id)
                };
                _FollowingList.Add(_Fmodel);
            }

            return(View(_FollowingList));
        }
        public async Task IsCheckingExistFollowingInRepo()
        {
            FollowingModel model = new FollowingModel {
                FollowerId = "11", FolloweeId = "1"
            };

            _dbContext.Add <FollowingModel>(model);
            _dbContext.SaveChanges();

            Following f = new Following {
                FollowerId = "11", FolloweeId = "1"
            };
            bool exist = await _repository.ExistFollowing(f);

            Assert.IsTrue(exist);

            f.FolloweeId = "199";
            exist        = await _repository.ExistFollowing(f);

            Assert.IsFalse(exist);
        }
        public JsonResult FollowAddJSON(string Id)
        {
            var currentUser = idb.Users.Find(User.Identity.GetUserId());

            repository.AddFollowingUser(currentUser.Id, Id);
            List <FollowingModel>  _FollowingList = new List <FollowingModel>();
            List <ApplicationUser> _Users         = idb.Users.Where(l => l.LocationID == currentUser.LocationID && l.Id != currentUser.Id).ToList();

            foreach (ApplicationUser item in _Users)
            {
                FollowingModel _Fmodel = new FollowingModel
                {
                    FirstName = item.FirstName,
                    LastName  = item.LastName,
                    UserID    = item.Id,
                    UserName  = item.UserName,
                    following = repository.IsFollowing(currentUser.Id, item.Id)
                };
                _FollowingList.Add(_Fmodel);
            }

            Task E = new Task(() =>
            {
                UserHelper _UserHelp = new UserHelper();
                string email         = _UserHelp.GetUserEmailViaUserId(Id);
                ApplicationUser _u   = idb.Users.Find(currentUser.Id);
                string Username      = _u.UserName + " (" + _u.FirstName + " " + _u.LastName + ")";
                _UserHelp.SendFollowing(Username, email);
            });

            E.Start();

            return(Json(new
            {
                success = true
            }, JsonRequestBehavior.AllowGet));
        }
Пример #12
0
        static void Main(string[] args)
        {
            string _ConsumerKey       = ConfigurationManager.AppSettings.Get("ConsumerKey");
            string _ConsumerSecret    = ConfigurationManager.AppSettings.Get("ConsumerSecret");
            string _AccessToken       = ConfigurationManager.AppSettings.Get("AccessToken");
            string _AccessTokenSecret = ConfigurationManager.AppSettings.Get("AccessTokenSecret");

            OAuthInfo oAuthInfo = new OAuthInfo
            {
                AccessSecret   = _AccessTokenSecret,
                AccessToken    = _AccessToken,
                ConsumerSecret = _ConsumerSecret,
                ConsumerKey    = _ConsumerKey
            };

            HideReplyService hideRepliesService = new HideReplyService(oAuthInfo);
            HideReplyModel   model = hideRepliesService.HideReply("1296341968176451585");

            // Sampled Stream Service Test
            SampledStreamService streamService = new SampledStreamService(oAuthInfo);

            streamService.DataReceivedEvent += StreamService_DataReceivedEvent;
            streamService.StartStream("https://api.twitter.com/2/tweets/sample/stream?expansions=attachments.poll_ids,attachments.media_keys,author_id,entities.mentions.username,geo.place_id,in_reply_to_user_id,referenced_tweets.id,referenced_tweets.id.author_id", 100, 5);

            // Recent Search
            RecentSearchService searchService = new RecentSearchService(oAuthInfo);

            List <RecentSearchResultsModel> resultsModels = searchService.SearchTweets("iphone", 100, 3);

            // Tweet(s)
            TweetService tweetsService = new TweetService(oAuthInfo);
            TweetModel   tweetModel    = tweetsService.GetTweet("1293779846691270658");

            List <string> tids = new List <string>();

            tids.Add("1293779846691270658"); // social opinion tweet
            tids.Add("1293779846691270658"); // social opinion tweet
            TweetsModel tweetModels = tweetsService.GetTweets(tids);

            //// User(s)
            UserService userService = new UserService(oAuthInfo);
            UserModel   userModel   = userService.GetUser("socialopinions");

            UserService userService2 = new UserService(oAuthInfo);
            UserModel   userModel2   = userService2.GetUser("jamie_maguire1");

            List <string> users = new List <string>();

            users.Add("jamie_maguire1");
            users.Add("socialopinions");
            UsersModel usersResults = userService.GetUsers(users);

            UserService myUserService = new UserService(oAuthInfo);

            FollowersModel followers = myUserService.GetFollowers("958676983", "100", null);

            FollowingModel following = myUserService.GetFollowing("38906681", "100", null);

            // Metrics
            List <string> ids = new List <string>();

            ids.Add("1258736674844094465"); // social opinion tweet
            TweetMetricsService     service      = new TweetMetricsService(oAuthInfo);
            List <TweetMetricModel> metricModels = service.GetTweetMetrics(ids);

            // testing Filtered Stream
            FilteredStreamService filteredStreamService = new FilteredStreamService(oAuthInfo);

            List <FilteredStreamRule> rules = filteredStreamService.CreateRule(
                new MatchingRule {
                tag = "testing #iPhone", Value = "#iphone"
            });

            filteredStreamService.DataReceivedEvent += FilteredStreamService_DataReceivedEvent;
            filteredStreamService.StartStream("https://api.twitter.com/2/tweets/search/stream?tweet.fields=attachments,author_id,context_annotations,conversation_id,created_at,entities,geo,id,in_reply_to_user_id,lang,public_metrics,possibly_sensitive,referenced_tweets,source,text,withheld&expansions=author_id&user.fields=created_at,description,entities,id,location,name,pinned_tweet_id,profile_image_url,protected,public_metrics,url,username,verified,withheld", 10, 5);
        }