コード例 #1
0
        public IActionResult OnGet(string sortOrder)
        {
            PoliticalParty = new List <SelectListItem> {
                new SelectListItem {
                    Value = "1", Text = "AFD"
                },
                new SelectListItem {
                    Value = "2", Text = "BÜNDNIS 90/DIE GRÜNEN"
                },
                new SelectListItem {
                    Value = "3", Text = "CDU/CSU"
                },
                new SelectListItem {
                    Value = "4", Text = "Die Linke"
                },
                new SelectListItem {
                    Value = "5", Text = "FDP"
                },
                new SelectListItem {
                    Value = "6", Text = "SPD"
                },
                new SelectListItem {
                    Value = "7", Text = "Fraktionslos"
                },
                new SelectListItem {
                    Value = "8", Text = null
                },
            };

            using (var db = new LiteDatabase("TwitterData.db"))
            {
                _logger.LogInformation("===========> Getting Collection...");

                var mapper = BsonMapper.Global;

                mapper.Entity <TwitterUserModel>()
                .Id(y => y.Id);

                var col = db.GetCollection <TwitterUserModel>("TwitterUser");

                var completeCollection = col.FindAll();

                CompleteDB = completeCollection;

                FavCountSort = sortOrder == "FavCount_Desc" ? "FavCount" : "FavCount_Desc";

                switch (sortOrder)
                {
                default:
                    CompleteDB = CompleteDB.OrderBy(s => s.PoliticalParty);
                    break;
                }

                if (sortOrder != null)
                {
                    _logger.LogInformation("Sort order is... " + sortOrder);
                }
            }
            return(Page());
        }
コード例 #2
0
        public async Task OnGet(string searchString, int?pageIndex, string currentFilter, string sortOrder)
        {
            try
            {
                WarningMessage = Config.Parameter.WarningMessage;

                using (var db = new LiteDatabase("TwitterData.db"))
                {
                    CurrentSort = sortOrder;

                    var col = db.GetCollection <TwitterStreamModel>("TwitterStream");

                    //var completeDB = col.FindAll().Where(s => s.TweetCreatedAt > DateTime.Now.AddDays(TimeRange));

                    var completeDB = col.Find(Query.All(Query.Descending), limit: TweetLimit);

                    CompleteDB = completeDB;

                    if (searchString != null)
                    {
                        pageIndex = 1;
                    }
                    else
                    {
                        searchString = currentFilter;
                    }

                    CurrentFilter = searchString;


                    //Search Filtering
                    if (!String.IsNullOrEmpty(searchString))
                    {
                        CompleteDB = CompleteDB.Where(
                            s => s.TweetText != null).Where(s => s.TweetText.ToLower().Contains(searchString.ToLower())
                                                            );
                    }

                    //TimeRange
                    //TimeRange = timeRange;

                    //Sorting
                    FavCountSort     = sortOrder == "FavCount_Desc" ? "FavCount" : "FavCount_Desc";
                    RetweetCountSort = sortOrder == "RetweetCount_Desc" ? "RetweetCount" : "RetweetCount_Desc";
                    CreatedAtSort    = sortOrder == "CreatedAtDate_desc" ? "CreatedAtDate" : "CreatedAtDate_desc";

                    switch (sortOrder)
                    {
                    case "FavCount":
                        CompleteDB = CompleteDB.OrderBy(s => s.TweetFavoriteCount);
                        break;

                    case "FavCount_Desc":
                        CompleteDB = CompleteDB.OrderByDescending(s => s.TweetFavoriteCount);
                        break;

                    case "RetweetCount":
                        CompleteDB = CompleteDB.OrderBy(s => s.TweetReTweetCount);
                        break;

                    case "RetweetCount_Desc":
                        CompleteDB = CompleteDB.OrderByDescending(s => s.TweetReTweetCount);
                        break;

                    case "CreatedAtDate":
                        CompleteDB = CompleteDB.OrderBy(s => s.TweetCreatedAt);
                        break;

                    case "CreatedAtDate_Desc":
                        CompleteDB = CompleteDB.OrderByDescending(s => s.TweetCreatedAt);
                        break;

                    default:
                        CompleteDB = CompleteDB.OrderByDescending(s => s.TweetCreatedAt);
                        break;
                    }

                    if (sortOrder != null)
                    {
                        _logger.LogInformation("Sort order is... " + sortOrder);
                    }
                }
                int pageSize = Config.Parameter.ShowEntries;
                TwitterStreamModel = await PaginatedList <TwitterStreamModel> .CreateAsync(
                    CompleteDB, pageIndex ?? 1, pageSize);
            }
            catch (ArgumentException ex)
            {
                _logger.LogInformation("Argument Exception... " + ex);
            }
            catch (LiteException ex)
            {
                _logger.LogInformation("Error with LiteDB... " + ex);
            }
            catch (Exception ex)
            {
                _logger.LogInformation("Error with tweetinvi... " + ex);
            }
        }
コード例 #3
0
        public async Task OnGet(string searchString, int?pageIndex, string currentFilter, string sortOrder, string politicalParty)
        {
            using (var db = new LiteDatabase("TwitterData.db"))
            {
                CurrentSort           = sortOrder;
                CurrentPoliticalParty = politicalParty;

                var col = db.GetCollection <TwitterUserModel>("TwitterUser");
                if (politicalParty == "SPD")
                {
                    var completeDB = col.FindAll().Where(s => s.PoliticalParty == "SPD");
                    CompleteDB = completeDB;
                }
                else if (politicalParty == "LINKE")
                {
                    var completeDB = col.FindAll().Where(s => s.PoliticalParty == "Die Linke");
                    CompleteDB = completeDB;
                }
                else if (politicalParty == "CDUCSU")
                {
                    var completeDB = col.FindAll().Where(s => s.PoliticalParty == "CDU/CSU");
                    CompleteDB = completeDB;
                }
                else if (politicalParty == "GRUENE")
                {
                    var completeDB = col.FindAll().Where(s => s.PoliticalParty == "BÜNDNIS 90/DIE GRÜNEN");
                    CompleteDB = completeDB;
                }
                else if (politicalParty == "FDP")
                {
                    var completeDB = col.FindAll().Where(s => s.PoliticalParty == "FDP");
                    CompleteDB = completeDB;
                }
                else if (politicalParty == "Fraktionslos")
                {
                    var completeDB = col.FindAll().Where(s => s.PoliticalParty == "Fraktionslos");
                    CompleteDB = completeDB;
                }
                else if (politicalParty == "AFD")
                {
                    var completeDB = col.FindAll().Where(s => s.PoliticalParty == "AFD");
                    CompleteDB = completeDB;
                }
                else
                {
                    var completeDB = col.FindAll();
                    CompleteDB = completeDB;
                }


                //

                TwitterUserCol = col;

                MemberCount = Convert.ToString(TwitterUserCol.Count());

                _logger.LogInformation(Convert.ToString(TwitterUserCol.Count()) + " MdB in der Datenbank");

                if (searchString != null)
                {
                    pageIndex = 1;
                }
                else
                {
                    searchString = currentFilter;
                }

                CurrentFilter = searchString;

                //Search Filtering
                if (!String.IsNullOrEmpty(searchString))
                {
                    CompleteDB = CompleteDB.Where(
                        s => s.Name.ToLower().Contains(searchString.ToLower())
                        );
                }

                //Sorting
                NameSort           = sortOrder == "TwitterName" ? "TwitterName_Desc" : "TwitterName";
                StatusCountSort    = sortOrder == "StatusesCount_Desc" ? "StatusesCount" : "StatusesCount_Desc";
                FollowersCountSort = sortOrder == "FollowersCount_Desc" ? "FollowersCount" : "FollowersCount_Desc";
                FriendsCountSort   = sortOrder == "FriendsCount_Desc" ? "FriendsCount" : "FriendsCount_Desc";
                FavCountSort       = sortOrder == "FavCount_Desc" ? "FavCount" : "FavCount_Desc";
                DateSort           = sortOrder == "LastCreatedDate" ? "LastCreatedDate_Desc" : "LastCreatedDate";
                CreatedAtSort      = sortOrder == "CreatedAtDate" ? "CreatedAtDate_Desc" : "CreatedAtDate";

                switch (sortOrder)
                {
                case "TwitterName":
                    CompleteDB = CompleteDB.OrderBy(s => s.Name);
                    break;

                case "TwitterName_Desc":
                    CompleteDB = CompleteDB.OrderByDescending(s => s.Name);
                    break;

                case "StatusesCount":
                    CompleteDB = CompleteDB.OrderBy(s => s.Statuses_count);
                    break;

                case "StatusesCount_Desc":
                    CompleteDB = CompleteDB.OrderByDescending(s => s.Statuses_count);
                    break;

                case "FollowersCount":
                    CompleteDB = CompleteDB.OrderBy(s => s.Followers_count);
                    break;

                case "FollowersCount_Desc":
                    CompleteDB = CompleteDB.OrderByDescending(s => s.Followers_count);
                    break;

                case "FriendsCount":
                    CompleteDB = CompleteDB.OrderBy(s => s.Friends_count);
                    break;

                case "FriendsCount_Desc":
                    CompleteDB = CompleteDB.OrderByDescending(s => s.Friends_count);
                    break;

                case "FavCount":
                    CompleteDB = CompleteDB.OrderBy(s => s.Favourites_count);
                    break;

                case "FavCount_Desc":
                    CompleteDB = CompleteDB.OrderByDescending(s => s.Favourites_count);
                    break;

                case "CreatedAtDate":
                    CompleteDB = CompleteDB.OrderBy(s => s.Created_at);
                    break;

                case "CreatedAtDate_Desc":
                    CompleteDB = CompleteDB.OrderByDescending(s => s.Created_at);
                    break;

                default:
                    CompleteDB = CompleteDB.OrderByDescending(s => s.Followers_count);
                    break;
                }

                int pageSize = 100;
                TwitterUserModel = await PaginatedList <TwitterUserModel> .CreateAsync(
                    CompleteDB, pageIndex ?? 1, pageSize);

                //StartTasksAsync();
            }
        }