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); }
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(); } } }
static public List <Train> ViewTrains() { TrainReservationSystemEntities1 db = new TrainReservationSystemEntities1(); var list = db.Trains.Where(pt => pt.AvailableSeats != 0).ToList(); return(list); }
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(); } } }
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; }
static public List <Train> ViewAllTrains() { TrainReservationSystemEntities1 db = new TrainReservationSystemEntities1(); var list = db.Trains.ToList(); return(list); }
public static bool Loging(string name, string password, bool type) { TrainReservationSystemEntities1 db = new TrainReservationSystemEntities1(); var user = db.LogIns.Where(p => p.Password == password && p.Username == name && p.Type == type).FirstOrDefault(); if (user == null) return false; else 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; } }
static public bool Loging(string name, string password, bool type) { TrainReservationSystemEntities1 db = new TrainReservationSystemEntities1(); var user = db.LogIns.Where(p => p.Password == password && p.Username == name && p.Type == type).FirstOrDefault(); if (user == null) { return(false); } else { 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; } }
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; } }
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); } }
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); } }
static public Train GetTrainById(int id) { TrainReservationSystemEntities1 db = new TrainReservationSystemEntities1(); return(db.Trains.Where(p => p.ID == id).FirstOrDefault()); }
public static Train GetTrainById(int id) { TrainReservationSystemEntities1 db = new TrainReservationSystemEntities1(); return db.Trains.Where(p => p.ID == id).FirstOrDefault(); }
public static List <History> GetHistory() { var db = new TrainReservationSystemEntities1(); return(db.Histories.ToList()); }
public static List<Train> ViewAllTrains() { TrainReservationSystemEntities1 db = new TrainReservationSystemEntities1(); var list = db.Trains.ToList(); return list; }
public static List<History> GetHistory() { var db = new TrainReservationSystemEntities1(); return db.Histories.ToList(); }
public static List<Train> ViewTrains() { TrainReservationSystemEntities1 db = new TrainReservationSystemEntities1(); var list = db.Trains.Where(pt => pt.AvailableSeats != 0).ToList(); return list; }