public void MockScoreParty() { var getData = ScoreAreaCollection.Find(it => true).ToList(); var groupByParty = getData.GroupBy(it => it.IdParty).ToList(); var totalScore = getData.Sum(it => it.Score); var listScoreParty = new List <PartyList>(); foreach (var item in groupByParty) { var totalScoreParty = item.Sum(it => it.Score); var percentScore = totalScoreParty * 100.0 / totalScore; // var totalScoreHave = Math.Round(percentScore / 100 * 500); var totalScoreHave = Convert.ToInt32(Math.Round(percentScore / 100 * 500)); var nameP = item.FirstOrDefault(it => it.IdParty == item.Key).NameParty; // Any var totalScoreArea = item.Count(it => it.Tags.Any(i => i == "ชนะ")); var scorePartyList = (totalScoreHave - totalScoreArea >= 0) ? totalScoreHave - totalScoreArea : 0; listScoreParty.Add(new PartyList { Id = Guid.NewGuid().ToString(), IdParty = item.Key, PartyName = nameP, TotalScore = totalScoreHave, AreaScore = totalScoreArea, NameListScore = scorePartyList, PercentScore = percentScore }); } PartyScoreCollection.DeleteMany(it => true); var sortData = listScoreParty.OrderByDescending(it => it.PercentScore); PartyScoreCollection.InsertMany(sortData); }
public List <PartyList> GetAllPartyScore() { var getData = PartyScoreCollection.Find(it => true).ToList(); var sortData = getData.OrderByDescending(it => it.PercentScore).ToList(); return(sortData); }
public PartyList GetSum() { var getData = PartyScoreCollection.Find(it => true).ToList(); var gt = new PartyList(); gt.TotalScore = getData.Sum(it => it.TotalScore); gt.AreaScore = getData.Sum(it => it.AreaScore); gt.PercentScore = getData.Sum(it => it.PercentScore); return(gt); }
public PartyList CheckSumPartyScore() { var getData = PartyScoreCollection.Find(it => true).ToList(); var sumHaveScore = getData.Sum(it => it.TotalScore); var sumAreaScore = getData.Sum(it => it.AreaScore); var sumPartyListScore = getData.Sum(it => it.NameListScore); var sumPercentScore = getData.Sum(it => it.PercentScore); var partyScore = new PartyList { TotalScore = sumHaveScore, AreaScore = sumAreaScore, NameListScore = sumPartyListScore, PercentScore = sumPercentScore }; return(partyScore); }
public PartyList GetPartyScore(string IdParty) { var getData = PartyScoreCollection.Find(it => it.IdParty == IdParty).FirstOrDefault(); return(getData); }