Esempio n. 1
0
        public void SaveAll(TrainEntity[] entities)
        {
            if (entities == null)
            {
                return;
            }

            using (var db = new TrainTrainContext())
            {
                db.Trains.AddOrUpdate(entities);
                db.SaveChanges();
            }
        }
Esempio n. 2
0
 public void Remove(string trainId)
 {
     using (var db = new TrainTrainContext())
     {
         var train = db.Trains.Include(t => t.Seats).SingleOrDefault(t => t.TrainId == trainId);
         if (train != null)
         {
             train.Seats.RemoveAll(t => true);
             RemoveSeats(db);
             db.Trains.Remove(train);
         }
         db.SaveChanges();
     }
 }
Esempio n. 3
0
 public void RemoveAll()
 {
     using (var db = new TrainTrainContext())
     {
         var trains = db.Trains.Include(t => t.Seats).ToList();
         if (trains.Any())
         {
             foreach (var trainEntity in trains)
             {
                 trainEntity.Seats.RemoveAll(t => true);
                 RemoveSeats(db);
                 db.Trains.Remove(trainEntity);
             }
         }
         db.SaveChanges();
     }
 }