Ejemplo n.º 1
0
        public void Jwriter(string fullName, string travelDate, string seatNumber, string destination, string origin)
        {
            List<Passenger> psngrData = new List<Passenger>();
            Passenger passenger = new Passenger(fullName, travelDate, seatNumber, destination, origin);
            psngrData.Add(passenger);

            string readFile = File.ReadAllText("Passengers.json");
            List<Passenger> fileReadList = JsonConvert.DeserializeObject<List<Passenger>>(readFile);
            psngrData.AddRange(fileReadList);

            string json = JsonConvert.SerializeObject(psngrData, Formatting.Indented);
            File.WriteAllText("Passengers.json", json);

        }
Ejemplo n.º 2
0
        public void Jwriter(string fullName, string travelDate, string seatNumber, string destination )
        {
            List<Passenger> psngrData = new List<Passenger>();
            Passenger passenger = new Passenger(fullName, travelDate, seatNumber, destination);
            psngrData.Add(passenger);
            //FileReader FR = new FileReader();
            //Passenger.Add(fullName);
            //Passenger.Add(travelDate);
            //Passenger.Add(seatNumber);
            //Passenger.Add(destination);
            //string json = JsonConvert.SerializeObject(Passenger.ToArray(), Formatting.Indented);
            //File.AppendAllText("Passengers.json", json);
            //passengerData.Add(pss);

            string name = File.ReadAllText("Passengers.json");
            List<Passenger> fileReadList = JsonConvert.DeserializeObject<List<Passenger>>(name);
            psngrData.AddRange(fileReadList);

            string json = JsonConvert.SerializeObject(psngrData, Formatting.Indented);
            File.WriteAllText("Passengers.json", json);

        }