Esempio n. 1
0
        public void GetTotalScoreOfPartry()
        {
            PartyScoreColloection.DeleteMany(it => true);
            var  getDataFromTable2 = DataTable2Collection.Find(it => true).ToList();
            long total             = getDataFromTable2.Sum(it => it.Score);

            var groupByParty   = getDataFromTable2.GroupBy(it => it.NameParty).ToList();
            var listPartyScore = new List <PartyScore>();

            foreach (var item in groupByParty)
            {
                var percentScore = item.Sum(it => it.Score) * 100.0 / total;
                var totalScore   = Convert.ToInt32(Math.Round(percentScore / 100 * 500));
                var areaScore    = item.Count(it => it.Tag == "ชนะ");

                listPartyScore.Add(new PartyScore
                {
                    Id            = Guid.NewGuid().ToString(),
                    PartyName     = item.Key,
                    TotalScore    = totalScore,
                    AreaScore     = areaScore,
                    NameListScore = totalScore - areaScore,
                    PercentScore  = percentScore
                });
            }
            PartyScoreColloection.InsertMany(listPartyScore);
        }
Esempio n. 2
0
        public void fillDataPartyScore()
        {
            PartyScoreColloection.DeleteMany(it => true);
            var csvReader     = new ReadCsv();
            var dataPartScore = csvReader.GetDataPartyScore();
            var listParty     = new List <PartyScore>();

            foreach (var data in dataPartScore)
            {
                data.Id = Guid.NewGuid().ToString();
                listParty.Add(data);
            }
            PartyScoreColloection.InsertMany(listParty);
        }