Exemple #1
0
        public void MAJVolsCedules()
        {
            List <VolsCedule> vols = new List <VolsCedule>(LoadJson());

            using (db = DB2.Aeroport())
            {
                try
                {
                    for (int i = 0; i < vols.Count; i++)
                    {
                        string     num = vols[i].Numero_Vol;
                        VolsCedule vol = db.VolsCedules.SingleOrDefault(m => m.Numero_Vol == num);

                        if (vol != null)
                        {
                            vols[i].Id_Date_Depart = vol.Id_Date_Depart;
                            bool IsEqual = vol.IsEqual(vols[i]);
                            if (!IsEqual)
                            {
                                vol.Date_Depart_Revisee  = vols[i].Date_Depart_Revisee;
                                vol.Date_Arrivee_Revisee = vols[i].Date_Arrivee_Revisee;
                                vol.Etat   = vols[i].Etat;
                                vol.Statut = vols[i].Statut;
                            }
                            else
                            {
                                vols.Remove(vols[i]);
                            }
                        }
                    }

                    db.SaveChanges();
                    UpdateNotification(vols);
                }
                catch (Exception e) {
                    return;
                }
            }
        }
Exemple #2
0
        private VolsCedule[] LoadJson()
        {
            List <VolsCedule> items;

            using (StreamReader r = new StreamReader(_FILELOCATION))
            {
                string json = r.ReadToEnd();
                items = new List <VolsCedule>(JsonConvert.DeserializeObject <VolsCedule[]>(json));
            }

            using (db = DB2.Aeroport())
            {
                try
                {
                    items.ForEach((item) =>
                    {
                        VolsCedule vol = db.VolsCedules.FirstOrDefault(m => m.Numero_Vol == item.Numero_Vol);
                        if (vol != null)
                        {
                            db.Entry(vol).Property(u => u.Date_Arrivee_Revisee).CurrentValue = item.Date_Arrivee_Revisee;
                            db.Entry(vol).Property(u => u.Date_Depart_Revisee).CurrentValue  = item.Date_Depart_Revisee;
                            db.Entry(vol).Property(u => u.Etat).CurrentValue           = item.Etat;
                            db.Entry(vol).Property(u => u.Statut).CurrentValue         = item.Statut;
                            db.Entry(vol).Property(u => u.Id_Date_Depart).CurrentValue = item.Id_Date_Depart;
                        }
                    });
                    if (items.Count > 0)
                    {
                        db.SaveChanges();
                    }
                }
                catch (Exception e)
                {
                }
            }

            return(items.ToArray());
        }