示例#1
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.");
                }
            }
        }
示例#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
文件: 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();
     }
 }
示例#4
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();
     }
 }
示例#5
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();
                }
            }
        }
示例#6
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();
                }
            }
        }
示例#7
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));
                }
            }
        }
示例#8
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));
                }
            }
        }
示例#9
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));
                }
            }
        }
示例#10
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();
            }
        }
示例#11
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));
                }
            }
        }
示例#12
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.");
                }
            }
        }
示例#13
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.");
                }
            }
        }
示例#14
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();
            }
        }