public static List<Timetable> LoadAllTimetables() { var timetableFiles = new List<Timetable>(); var fileList = Directory.GetFiles(Options.workingDirectory + "\\Timetables"); foreach (string filename in fileList) { // Reasds the CSV using the method in this class. // The 'false' argument prevents readCSV from adding the directory path, // as it is already in the filename string. var splitCsv = readCSV(filename, true); // Split the timetable name into parts to be processed var timetableNameParts = Path.GetFileName(filename).Split('.'); // Initialise a new timetable Timetable thisTimetable = new Timetable(); // Set the route name and the specific sub-route to the values in the filename thisTimetable.routeName = timetableNameParts[0]; thisTimetable.subRoute = timetableNameParts[1]; // Look at the filename for which days it runs and use the sub to input these ProcessDaysRun(thisTimetable, timetableNameParts[2]); // For each line of the CSV except for the first line containing stop IDs for (int i = 1; i < splitCsv.Count; i++) { // Initialise a journey Journey journey = new Journey(); var row = splitCsv[i]; for (int j = 0; j < row.Length; j++) { if (Validation.ValidTime(row[j])) { JourneyStop stop = new JourneyStop(); stop.stopID = splitCsv[0][j]; int thisTime = int.Parse(splitCsv[i][j]); stop.stopMinuteTime = Time.ConvertToMinTime(thisTime); journey.stops.Add(stop); } } thisTimetable.journeys.Add(journey); } timetableFiles.Add(thisTimetable); } return timetableFiles; }
public ActionResult PurchaseComplete() { var form = Request.Form; string json = form["ModelJson"]; var model = JsonConvert.DeserializeObject <TransporterReservationViewModel>(json); var depPlace = new Place() { GoogleId = model.From.Id, Name = model.From.Name, City = model.From.Name, Country = model.From.Name, Latitude = 35, Longitude = 35 }; var arrPlace = new Place() { GoogleId = model.To.Id, Name = model.To.Name, City = model.To.Name, Country = model.To.Name, Latitude = 35, Longitude = 35 }; db.Places.Add(depPlace); db.Places.Add(arrPlace); db.SaveChanges(); var journey = new Journey(); journey.DeparturePlaceId = depPlace.Id; journey.ArrivalPlaceId = arrPlace.Id; journey.DepartureDate = DateTime.Now; journey.ArrivalDate = DateTime.Now; journey.Title = model.From.Name + " mekanından " + model.To.Name + " mekanına yolculuk"; journey.Transporter = db.Transporters.Find(model.Id); db.Journeys.Add(journey); db.SaveChanges(); journey.JourneyStops = new List <JourneyStop>(); foreach (var item in model.Stops) { var stop = new JourneyStop(); stop.EstimatedDate = DateTime.Now; stop.PassengerCountGetOn = item.PassengerCountGetOn; stop.PassengerCountGetOff = item.PassengerCountGetOff; stop.Place = new Place() { GoogleId = item.Place.Id, Name = item.Place.Name, City = item.Place.Name, Country = item.Place.Name, Latitude = 35, Longitude = 35 }; stop.Sort = item.Sort; stop.JourneyId = journey.Id; db.JourneyStops.Add(stop); } db.SaveChanges(); var payment = new Payment(); payment.Provision = "provision 1"; payment.Type = 1; db.Payments.Add(payment); db.SaveChanges(); var reservation = new Reservation(); reservation.Code = CreateCode(); reservation.Payment = payment; reservation.JourneyId = journey.Id; db.Reservations.Add(reservation); db.SaveChanges(); return(RedirectToAction("ReservationDetails", new { code = reservation.Code })); }