Example #1
0
        public List <ScorePollV2> GetAreaScorePoll(string idArea)
        {
            var getData      = FinalScorePollCollection.Find(it => it.IdArea == idArea.ToUpper()).ToList();
            var groupByParty = getData.GroupBy(it => it.IdParty);
            var listCurrentScorePollOfArea = new List <ScorePollV2>();

            foreach (var item in groupByParty)
            {
                var getCurrent = item.OrderByDescending(it => it.datePoll).ToList().FirstOrDefault();
                listCurrentScorePollOfArea.Add(getCurrent);
            }
            return(listCurrentScorePollOfArea);
        }
        public async Task UpdateTable4()
        {
            var dataScorePoll            = FinalScorePollCollection.Find(it => true).ToList();
            var dataTable4               = Table4Collection.Find(it => true).ToList();
            var dataScorePollGroupByArea = dataScorePoll.GroupBy(it => it.IdArea).ToList();
            var listT4 = new List <ScoreArea>();

            foreach (var dataPoll in dataScorePollGroupByArea)
            {
                var dataScorePollGroupByParty = dataPoll.GroupBy(it => it.IdParty).ToList();
                foreach (var dataParty in dataScorePollGroupByParty)
                {
                    var getCurentData      = dataParty.OrderByDescending(it => it.datePoll).FirstOrDefault();
                    var getMatchDataTable4 = dataTable4.FirstOrDefault(it => it.IdArea == getCurentData.IdArea &&
                                                                       it.IdParty == getCurentData.IdParty);
                    if (getMatchDataTable4 != null)
                    {
                        getMatchDataTable4.Score          = getCurentData.Score;
                        getMatchDataTable4.Source         = getCurentData.Source;
                        getMatchDataTable4.StatusEdit     = false;
                        getMatchDataTable4.StatusAreaEdit = false;
                        getMatchDataTable4.Region         = getCurentData.Region;
                        getMatchDataTable4.IdRegion       = getCurentData.IdRegion;
                        // create tag
                        if (getMatchDataTable4.Tags == null)
                        {
                            getMatchDataTable4.Tags = new List <string>();
                        }
                        listT4.Add(getMatchDataTable4);
                        // Table4Collection.ReplaceOne(it => it.IdArea == getMatchDataTable4.IdArea
                        // && it.IdParty == getMatchDataTable4.IdParty, getMatchDataTable4);
                    }
                }
            }

            for (int i = 0; i < listT4.Count; i += 550)
            {
                var list = listT4.Skip(i).Take(550);
                ListT4Collection.InsertMany(list);
                await Task.Delay(1000);
            }

            foreach (var data in dataTable4.GroupBy(it => it.IdArea))
            {
                Table4Collection.DeleteMany(it => it.IdArea == data.Key);
            }
        }
Example #3
0
 public List <ScorePollV2> GetAllScorePoll()
 {
     return(FinalScorePollCollection.Find(it => true).ToList());
 }