Exemplo n.º 1
0
        public static string GetStationNameById(int id)
        {
            TrainCommanderEntities db = new TrainCommanderEntities();

            return((from o in db.Station
                    where o.Id == id
                    select o.name).First());
        }
Exemplo n.º 2
0
        public static Train AddTrain()
        {
            TrainCommanderEntities db = new TrainCommanderEntities();
            Train train = new Train {
                is_double = false, seat_number = 350, remaining_seat = 350
            };

            db.Train.Add(train);
            return(train);
        }
Exemplo n.º 3
0
        private static void AddSuperTrip(SuperTrip superTrip)
        {
            TrainCommanderEntities db = new TrainCommanderEntities();

            if (!db.SuperTrip.Any(o =>
                                  o.id_departure_station == superTrip.id_departure_station &&
                                  o.id_arrival_station == superTrip.id_arrival_station &&
                                  o.departure_date == superTrip.departure_date))
            {
                db.SuperTrip.Add(superTrip);
            }
            db.SaveChanges();
        }
Exemplo n.º 4
0
        public static string GetStationSNCFId(string name)
        {
            TrainCommanderEntities db = new TrainCommanderEntities();
            string idSncf;
            var    search = (from o in db.Station
                             where o.name.ToLower() == name.ToLower()
                             select o).FirstOrDefault();

            if (search.id_sncf == null)
            {
                idSncf         = GetIDFromPlace(name);
                search.id_sncf = idSncf;
                db.SaveChanges();
            }
            return(search.id_sncf);
        }
Exemplo n.º 5
0
        public static int GetStationIdByName(string name)
        {
            TrainCommanderEntities db = new TrainCommanderEntities();
            int returnVar             = 0;

            try
            {
                returnVar = (from o in db.Station
                             where o.name == name
                             select o.Id).First();
            }
            catch (EntityCommandCompilationException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(returnVar);
            }
            return(returnVar);
        }
Exemplo n.º 6
0
        public static Station GetStationBySNCFName(string name)
        {
            TrainCommanderEntities db = new TrainCommanderEntities();
            Station station           = new Station();
            var     query             = (from o in db.Station
                                         where o.name == name
                                         select o).FirstOrDefault();

            if (query == null)
            {
                station.name = name;
                db.Station.Add(station);
                db.SaveChanges();
            }
            else
            {
                station = query;
            }
            return(station);
        }
Exemplo n.º 7
0
        public static List <Trip> ConvertToListTrip(List <SNCFTrip> sncfTrips)
        {
            TrainCommanderEntities db    = new TrainCommanderEntities();
            List <Trip>            trips = new List <Trip>();

            foreach (SNCFTrip sncfTrip in sncfTrips)
            {
                Station departure = GetStationBySNCFName(sncfTrip.departure);
                Station arrival   = GetStationBySNCFName(sncfTrip.arrival);
                Trip    trip      = new Trip
                {
                    id_departure_station = departure.Id,
                    id_arrival_station   = arrival.Id,
                    departure_date       = DateTime.ParseExact(sncfTrip.departure_date_time, "yyyyMMddTHHmmss", CultureInfo.InvariantCulture),
                    arrival_date         = DateTime.ParseExact(sncfTrip.arrival_date_time, "yyyyMMddTHHmmss", CultureInfo.InvariantCulture),
                    price = sncfTrip.price
                };
                trips.Add(trip);
            }
            return(trips);
        }
Exemplo n.º 8
0
        private static void AddTrips(List <Trip> trips)
        {
            TrainCommanderEntities db = new TrainCommanderEntities();
            DateTime departure_date   = trips.First().departure_date;
            DateTime arrival_date     = trips.Last().arrival_date;

            foreach (Trip trip in trips)
            {
                if (!db.Trip.Any(o =>
                                 o.id_departure_station == trip.id_departure_station &&
                                 o.id_arrival_station == trip.id_arrival_station &&
                                 o.departure_date == trip.departure_date))
                {
                    SuperTrip supertrip = (from o in db.SuperTrip
                                           where o.departure_date == departure_date && o.arrival_date == arrival_date
                                           select o).FirstOrDefault();
                    trip.SuperTrip.Add(supertrip);
                    trip.Train = AddTrain();
                    db.Trip.Add(trip);
                    db.SaveChanges();
                }
            }
        }