public static List<City> GetAllCities() { using(var context = new TicketsDB()) { return context.City.ToList(); } }
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 List <City> GetAllCities() { using (var context = new TicketsDB()) { return(context.City.ToList()); } }
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 List <Schedule> GetAllSchedulesBetweenCities(string startingCity, string endCity) { using (var context = new TicketsDB()) { return((from s in context.Schedule where s.StartingCity.Equals(startingCity) && s.EndCity.Equals(endCity) select s).ToList()); } }
static void Main(string[] args) { using (var context = new TicketsDB()) { City.AddCity("Plovidv"); City.AddCity("Haskovo"); City.DeleteCity("Gosho"); City.AddCity("Varna"); City.DeleteCity("Haskovo"); } }
public static List <Train> GetAllTrains() { using (var context = new TicketsDB()) { List <Train> result = new List <Train>(); result = context.Train.ToList(); return(result); } }
public static List<Train> GetAllTrains() { using (var context = new TicketsDB()) { List<Train> result = new List<Train>(); result = context.Train.ToList(); return result; } }
static void Main(string[] args) { using(var context = new TicketsDB()) { City.AddCity("Plovidv"); City.AddCity("Haskovo"); City.DeleteCity("Gosho"); City.AddCity("Varna"); City.DeleteCity("Haskovo"); } }
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 DisplaySchedule(int id) { using (var context = new TicketsDB()) { var schedule = (from s in context.Schedule where s.ID == id select s).FirstOrDefault(); if (schedule != null) { Console.WriteLine(string.Format("From: {0} to {1}, for {2}. Ticket price: {3}.", schedule.StartingCity, schedule.EndCity, schedule.TravelTime, schedule.TicketPrice)); } else { Console.WriteLine("There isn't any schedule with that id"); } } }
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 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 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."); } } }
public static List<Schedule> GetAllSchedulesBetweenCities(string startingCity, string endCity) { using (var context = new TicketsDB()) { return (from s in context.Schedule where s.StartingCity.Equals(startingCity) && s.EndCity.Equals(endCity) select s).ToList(); } }