public bool AjouterStatistique(Enumeration enume) { int x = 0; Region reg = db.Regions.Where(i => i.Villes.Where(y => y.UID == enume.UID_V).FirstOrDefault().UID == enume.UID_V).FirstOrDefault(); var regStat = StatExists(reg.UID); if (regStat != null) { regStat.Cas_Confirmer += enume.Cas_Confirmer; regStat.Cas_Mort += enume.Cas_Mort; regStat.Cas_Retablis += enume.Cas_Retablis; db.Entry(regStat).State = System.Data.Entity.EntityState.Modified; x = db.SaveChanges(); } else { RegionStatistique regionStatistique = new RegionStatistique() { Cas_Confirmer = enume.Cas_Confirmer, Cas_Mort = enume.Cas_Mort, Cas_Retablis = enume.Cas_Retablis, Date_Ins = enume.Date_Ins, UID = GestionGlobal.GetUID("REGSTAT"), Region = reg }; db.Entry(regionStatistique).State = System.Data.Entity.EntityState.Added; x = db.SaveChanges(); } return(x > 0); }
public APIModel API() { int casC = 0, casM = 0, casR = 0, casT = 0; foreach (var reg in db.Regions.ToList()) { RegionModel Region_ = new RegionModel(); Region_.UID = reg.UID; Region_.Nom = reg.Nom; foreach (var vil in db.Villes.Where(x => x.UID_Region == reg.UID).ToList()) { VilleModel Ville_ = new VilleModel(); Ville_.UID = vil.UID; Ville_.Nom = vil.Nom; foreach (var e in db.Enumerations.Where(e => e.UID_V == vil.UID).ToList()) { StatistiquesModel Statistique_ = new StatistiquesModel() { UID = e.UID, Cas_Confirmer = (int)e.Cas_Confirmer, Cas_Mort = (int)e.Cas_Mort, Cas_Retablis = (int)e.Cas_Retablis, Date_Ins = ConvertDate.ConverDate((DateTime)e.Date_Ins) }; //verify if there is some date to show or show 0 if (e.Cas_Confirmer > 0) casC += (int)e.Cas_Confirmer; if (e.Cas_Retablis > 0) casR += (int)e.Cas_Retablis; if (e.Cas_Mort > 0) casM += (int)e.Cas_Mort; if (Statistique_.UID != null) Ville_.Statistiques.Add(Statistique_); } // add villes with stat in region Region_.Villes.Add(Ville_); } // return Region statis if exists var RegStat = ReturnRegStat(Region_.UID); if (RegStat == null) { RegionStatistique rgS = new RegionStatistique() { UID = GestionGlobal.GetUID("REGSTAT"), Cas_Confirmer = casC, Cas_Mort = casM, Cas_Retablis = casR, Date_Ins = DateTime.Now, UID_R = Region_.UID }; //db.RegionStatistiques.Add(rgS); //db.Entry(rgS).State = System.Data.Entity.EntityState.Added; //db.SaveChanges(); Region_.Statistiques = ReturnRegStat(Region_.UID); } else { RegStat = ReturnRegStat(Region_.UID); Region_.Statistiques = RegStat; } Data.api.Add(Region_); casC = casM = casR = casT = 0; } return Data; }