예제 #1
0
        static public void AddNewTrain(string from, string to, string startDate, string endDate, int numberofCars)
        {
            TrainReservationSystemEntities1 db = new TrainReservationSystemEntities1();
            Train train = new Train()
            {
                NumberOfCars    = numberofCars,
                ArrivalDate     = endDate,
                DepartureDate   = startDate,
                StartingStation = from,
                EndingStation   = to,
                AvailableSeats  = numberofCars * 24
            };

            db.Trains.Add(train);
            db.SaveChanges();
            for (int i = 0; i < numberofCars; i++)
            {
                var car = new Car()
                {
                    Number = i + 1, TrainID = train.ID
                };
                db.Cars.Add(car);
                db.SaveChanges();
                for (int j = 0; j < 24; j++)
                {
                    var seat = new Seat()
                    {
                        Available = true, CarID = car.ID, Coordinates = j.ToString()
                    };
                    db.Seats.Add(seat);
                    db.SaveChanges();
                }
            }
        }
 public static void AddNewTrain(string from, string to, string startDate, string endDate, int numberofCars)
 {
     TrainReservationSystemEntities1 db = new TrainReservationSystemEntities1();
     Train train = new Train()
     {
         NumberOfCars = numberofCars,
         ArrivalDate = endDate,
         DepartureDate = startDate,
         StartingStation = from,
         EndingStation = to,
         AvailableSeats = numberofCars * 24
     };
     db.Trains.Add(train);
     db.SaveChanges();
     for (int i = 0; i < numberofCars; i++)
     {
         var car = new Car() { Number = i + 1, TrainID = train.ID };
         db.Cars.Add(car);
         db.SaveChanges();
         for (int j = 0; j < 24; j++)
         {
             var seat = new Seat() { Available = true, CarID = car.ID, Coordinates = j.ToString() };
             db.Seats.Add(seat);
             db.SaveChanges();
         }
     }
 }
예제 #3
0
        static public bool ReserveChair(int ID, int passportID, string name)
        {
            TrainReservationSystemEntities1 db = new TrainReservationSystemEntities1();
            var seat = db.Seats.Where(p => p.ID == ID).FirstOrDefault();

            if (seat != null)
            {
                if (seat.Available == true)
                {
                    seat.Available = false;
                    seat.Car.Train.AvailableSeats--;
                    Passenger PP = new Passenger();
                    var       p  = db.Passengers.Where(t => t.PassportNumber == passportID).FirstOrDefault();
                    if (p == null)
                    {
                        PP.PassportNumber = passportID;
                        PP.Name           = name;
                        db.Passengers.Add(PP);
                        db.SaveChanges();
                    }
                    seat.PassengerPassport = passportID;
                    db.Histories.Add(new History {
                        PassportNumber = passportID, TrainID = seat.Car.TrainID
                    });

                    // db.SaveChanges();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }
        public static bool ReserveChair(int ID, int passportID, string name)
        {
            TrainReservationSystemEntities1 db = new TrainReservationSystemEntities1();
               var seat =  db.Seats.Where(p => p.ID == ID).FirstOrDefault();
               if (seat != null)
               {
               if (seat.Available == true)
               {
                   seat.Available = false;
                   seat.Car.Train.AvailableSeats --;
                   Passenger PP = new Passenger();
                   var p = db.Passengers.Where(t => t.PassportNumber == passportID).FirstOrDefault();
                   if (p == null)
                   {
                       PP.PassportNumber = passportID;
                       PP.Name = name;
                       db.Passengers.Add(PP);
                       db.SaveChanges();
                   }
                   seat.PassengerPassport = passportID;
                   db.Histories.Add(new History{PassportNumber=passportID,TrainID=seat.Car.TrainID});

                  // db.SaveChanges();
                   return true;
               }
               else
                   return false;
               }
            return true;
        }
        public static bool RemoveTrain(int id)
        {
            TrainReservationSystemEntities1 db = new TrainReservationSystemEntities1();
            var temp = db.Trains.Where(p => p.ID == id).FirstOrDefault();
            if (temp == null)
                return false;
            else
            {
                db.Trains.Remove(temp);
                db.SaveChanges();
                return true;

            }
        }
 public static bool CancelChairReservation(int ID, int passportID)
 {
     TrainReservationSystemEntities1 db = new TrainReservationSystemEntities1();
     var seat = db.Seats.Where(p => p.ID == ID).FirstOrDefault();
     if (seat == null)
         return false;
     else {
            seat.Available = false;
            seat.Car.Train.AvailableSeats ++;
            seat.PassengerPassport =0;
            db.Histories.Remove(new History{PassportNumber=passportID,TrainID=seat.Car.TrainID});
            db.SaveChanges();
         return true;
     }
 }
예제 #7
0
        static public bool RemoveTrain(int id)
        {
            TrainReservationSystemEntities1 db = new TrainReservationSystemEntities1();
            var temp = db.Trains.Where(p => p.ID == id).FirstOrDefault();

            if (temp == null)
            {
                return(false);
            }
            else
            {
                db.Trains.Remove(temp);
                db.SaveChanges();
                return(true);
            }
        }
        public static bool EditTrain(int id, string from, string to, string startDate, string endDate, int numberofCars)
        {
            TrainReservationSystemEntities1 db = new TrainReservationSystemEntities1();

            var temp = db.Trains.Where(p => p.ID == id).FirstOrDefault();
            if (temp == null)
                return false;
            else
            {
                temp.ID = id;
                temp.NumberOfCars = numberofCars;
                temp.StartingStation = from;
                temp.EndingStation = to;
                temp.DepartureDate = startDate;
                temp.ArrivalDate = endDate;
                db.SaveChanges();
                return true;
            }
        }
예제 #9
0
        static public bool CancelChairReservation(int ID, int passportID)
        {
            TrainReservationSystemEntities1 db = new TrainReservationSystemEntities1();
            var seat = db.Seats.Where(p => p.ID == ID).FirstOrDefault();

            if (seat == null)
            {
                return(false);
            }
            else
            {
                seat.Available = false;
                seat.Car.Train.AvailableSeats++;
                seat.PassengerPassport = 0;
                db.Histories.Remove(new History {
                    PassportNumber = passportID, TrainID = seat.Car.TrainID
                });
                db.SaveChanges();
                return(true);
            }
        }
예제 #10
0
        static public bool EditTrain(int id, string from, string to, string startDate, string endDate, int numberofCars)
        {
            TrainReservationSystemEntities1 db = new TrainReservationSystemEntities1();

            var temp = db.Trains.Where(p => p.ID == id).FirstOrDefault();

            if (temp == null)
            {
                return(false);
            }
            else
            {
                temp.ID              = id;
                temp.NumberOfCars    = numberofCars;
                temp.StartingStation = from;
                temp.EndingStation   = to;
                temp.DepartureDate   = startDate;
                temp.ArrivalDate     = endDate;
                db.SaveChanges();
                return(true);
            }
        }