示例#1
0
文件: City.cs 项目: thedoomx/CSharp
 public static List<City> GetAllCities()
 {
     using(var context = new TicketsDB())
     {
         return context.City.ToList();
     }
 }
示例#2
0
        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.");
                }
            }
        }
示例#3
0
        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.");
                }
            }
        }
示例#4
0
文件: City.cs 项目: thedoomx/CSharp
 public static List <City> GetAllCities()
 {
     using (var context = new TicketsDB())
     {
         return(context.City.ToList());
     }
 }
示例#5
0
文件: Train.cs 项目: thedoomx/CSharp
 public static void AddTrain(int seats, string trainDescription)
 {
     using (var context = new TicketsDB())
     {
         context.Train.Add(new Train() { Seats = seats, TrainDescription = trainDescription });
         context.SaveChanges();
     }
 }
示例#6
0
 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());
     }
 }
示例#7
0
 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");
     }
 }
示例#8
0
        public static List <Train> GetAllTrains()
        {
            using (var context = new TicketsDB())
            {
                List <Train> result = new List <Train>();

                result = context.Train.ToList();

                return(result);
            }
        }
示例#9
0
 public static void AddTrain(int seats, string trainDescription)
 {
     using (var context = new TicketsDB())
     {
         context.Train.Add(new Train()
         {
             Seats = seats, TrainDescription = trainDescription
         });
         context.SaveChanges();
     }
 }
示例#10
0
文件: Train.cs 项目: thedoomx/CSharp
        public static List<Train> GetAllTrains()
        {
            using (var context = new TicketsDB())
            {
                List<Train> result = new List<Train>();

                result = context.Train.ToList();

                return result;
            }
        }
示例#11
0
        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");

            }
        }
示例#12
0
        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();
                }
            }
        }
示例#13
0
文件: Train.cs 项目: thedoomx/CSharp
        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();
                }
            }
        }
示例#14
0
 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");
         }
     }
 }
示例#15
0
        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();
            }
        }
示例#16
0
文件: City.cs 项目: thedoomx/CSharp
        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));
                }
            }
        }
示例#17
0
文件: City.cs 项目: thedoomx/CSharp
        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));
                }
            }
        }
示例#18
0
文件: Train.cs 项目: thedoomx/CSharp
        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();
            }
        }
示例#19
0
文件: City.cs 项目: thedoomx/CSharp
        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));
                }
            }
        }
示例#20
0
文件: City.cs 项目: thedoomx/CSharp
        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));
                }
            }
        }
示例#21
0
        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.");
                }
            }
        }
示例#22
0
 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");
         }
     }
 }
示例#23
0
 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();
     }
 }
示例#24
0
        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.");
                }
            }
        }