public List <AreaData> GetDistrictAll(string nameArea) { var getData = AreaCollection.Find(it => it.NameArea == nameArea).ToList(); var listDistrict = getData.Where(it => it.NameParty == "เพื่อไทย").ToList(); return(listDistrict); }
public void MockDataTable2() { var getDataTable3 = AreaCollection.Find(it => true).ToList().OrderBy(it => it.IDProvince).OrderBy(it => it.LocationCode.Substring(0, 2)); var dataGroupByNameArea = getDataTable3.GroupBy(it => it.NameArea).ToList(); var listDataTable2 = new List <DataTable2>(); var rnd = new Random(); foreach (var item in dataGroupByNameArea) { var dataGroupByNameParty = item.GroupBy(it => it.NameParty).ToList(); foreach (var datas in dataGroupByNameParty) { var sumScore = datas.Sum(it => it.ScoreReceive.Last().Score); var data = datas.FirstOrDefault(); listDataTable2.Add(new DataTable2 { Id = Guid.NewGuid().ToString(), NameArea = data.NameArea, IDProvince = data.IDProvince, LocationCode = data.LocationCode, NameParty = data.NameParty, NoRegister = data.NoRegister, NameRegister = data.NameRegister, Status = data.Status, Score = sumScore, TargetScore = sumScore + rnd.Next(-1500, 1500) }); } } DataTable2Collection.InsertMany(listDataTable2); }
public List <string> GetAreaAll() { var getData = AreaCollection.Find(it => true).ToList().OrderBy(it => it.IDProvince).OrderBy(it => it.LocationCode.Substring(0, 2)); var groupByArea = getData.GroupBy(it => it.NameArea).ToList(); var listAreaName = new List <string>(); foreach (var item in groupByArea) { listAreaName.Add(item.Key); } return(listAreaName); }
public void AddScoreElection(string id, [FromBody] DataScore addScore) { var getArea = AreaCollection.Find(it => it.Id == id).FirstOrDefault(); addScore.DateElection = DateTime.Now; getArea.ScoreReceive.Add(new DataScore { DateElection = addScore.DateElection, Score = addScore.Score }); AreaCollection.ReplaceOne(it => it.Id == id, getArea); }
public void AddMockScore() { var getArea = AreaCollection.Find(it => true).ToList(); var rnd = new Random(); foreach (var item in getArea) { item.ScoreReceive.Add(new DataScore { DateElection = new DateTime(2019, 1, 28), Score = rnd.Next(1000, 3000) }); } AreaCollection.DeleteMany(it => true); AreaCollection.InsertMany(getArea); }
public AreaData GetAreaData(string id) { var getArea = AreaCollection.Find(it => it.Id == id).FirstOrDefault(); return(getArea); }
public List <AreaData> GetAllArea() { var getAllArea = AreaCollection.Find(it => true).ToList(); return(getAllArea); }