public static void AddTrip(int trainID, string startingCity, string endCity, TimeSpan travelTime, decimal ticketPrice) { using (var context = new TicketsDB()) { var availableTrain = (from s in context.Schedule where s.TrainID == trainID select s).FirstOrDefault(); if(availableTrain == null) { context.Schedule.Add(new Schedule { TrainID = trainID, StartingCity = startingCity, EndCity = endCity, TravelTime = travelTime, TicketPrice = ticketPrice }); context.SaveChanges(); } else { Console.WriteLine("The specified train is in use."); } } }
public static void AddTrip(int trainID, string startingCity, string endCity, TimeSpan travelTime, decimal ticketPrice) { using (var context = new TicketsDB()) { var availableTrain = (from s in context.Schedule where s.TrainID == trainID select s).FirstOrDefault(); if (availableTrain == null) { context.Schedule.Add(new Schedule { TrainID = trainID, StartingCity = startingCity, EndCity = endCity, TravelTime = travelTime, TicketPrice = ticketPrice }); context.SaveChanges(); } else { Console.WriteLine("The specified train is in use."); } } }
public static void AddTrain(int seats, string trainDescription) { using (var context = new TicketsDB()) { context.Train.Add(new Train() { Seats = seats, TrainDescription = trainDescription }); context.SaveChanges(); } }
public static void EditTrain(int id, int seats, string trainDescription) { using (var context = new TicketsDB()) { var train = (from t in context.Train where t.ID == id select t).FirstOrDefault(); if(train != null) { train.Seats = seats; train.TrainDescription = trainDescription; context.SaveChanges(); } } }
public static void EditTrain(int id, int seats, string trainDescription) { using (var context = new TicketsDB()) { var train = (from t in context.Train where t.ID == id select t).FirstOrDefault(); if (train != null) { train.Seats = seats; train.TrainDescription = trainDescription; context.SaveChanges(); } } }
public static void DeleteCity(string name) { using (var context = new TicketsDB()) { var city = (from c in context.City where c.Name.Equals(name) select c).FirstOrDefault(); if(city != null) { context.City.Remove(city); context.SaveChanges(); } else { Console.WriteLine(string.Format("There is no {0} city in database", name)); } } }
public static void AddCity(string name) { using (var context = new TicketsDB()) { var existing = (from c in context.City where c.Name.Equals(name) select c).FirstOrDefault(); if (existing == null) { context.City.Add(new City() { Name = name }); context.SaveChanges(); } else { Console.WriteLine(string.Format("{0} is already in database.", name)); } } }
public static void DeleteCity(string name) { using (var context = new TicketsDB()) { var city = (from c in context.City where c.Name.Equals(name) select c).FirstOrDefault(); if (city != null) { context.City.Remove(city); context.SaveChanges(); } else { Console.WriteLine(string.Format("There is no {0} city in database", name)); } } }
public static void RemoveTrain(int id) { using (var context = new TicketsDB()) { var train = (from t in context.Train where t.ID == id select t).FirstOrDefault(); if (train != null) { context.Train.Remove(train); } else { Console.WriteLine("There is no such train id"); } context.SaveChanges(); } }
public static void EditTrip(int trainID, string startingCity, string endCity, TimeSpan travelTime, decimal ticketPrice) { using (var context = new TicketsDB()) { var existing = (from s in context.Schedule where s.TrainID == trainID select s).FirstOrDefault(); if (existing != null) { existing.StartingCity = startingCity; existing.EndCity = endCity; existing.TravelTime = travelTime; existing.TicketPrice = ticketPrice; context.SaveChanges(); } else { Console.WriteLine("There is no train with that id."); } } }