Exemple #1
0
 public static void AddCity(City city)
 {
     using (var context = new TrainContext())
     {
         var citi = context.Set<City>();
         citi.Add(city);
         context.SaveChanges();
     }
 }
Exemple #2
0
 public static void AddTrain(Train train)
 {
     using (var db = new TrainContext())
     {
         var tr = db.Set<Train>();
         tr.Add(train);
         db.SaveChanges();
     }
 }
Exemple #3
0
 public static void AddUser(User user)
 {
     using (var db = new TrainContext())
     {
         var us = db.Set<User>();
         us.Add(user);
         db.SaveChanges();
     }
 }
 public static void AddSchedule(Schedule sch)
 {
     List<Schedule> otherSchedules = ListSchedule();
     using (var db = new TrainContext())
     {
         foreach (var item in otherSchedules.Where(s => s.Train == sch.Train))
         {
             if (item.Train == sch.Train)
             {
                 if (!IntersectDates(sch.DateAndTime, item.DateAndTime, sch.TripDuration, item.TripDuration))
                 {
                     throw new Exception("Train is unvailable for this trip");
                 }
             }
         }
         var addshedule = db.Set<Schedule>();
         addshedule.Add(sch);
         db.SaveChanges();
     }
 }