Exemplo n.º 1
0
        private void EditCar(string payload, StreamWriter clientWriter)
        {
            EditWorkerRequest request = JsonSerializer.Deserialize <EditWorkerRequest>(payload);
            Car newCar = request.NewCar;

            List <Car> cars = ReadCarsFromFile();

            for (int i = 0; i < cars.Count; i++)
            {
                if (cars[i].Name.Equals(request.OldName))
                {
                    cars[i] = newCar;
                }
            }

            CarsArray arr = new CarsArray()
            {
                Cars = cars
            };

            clientWriter.WriteLine(JsonSerializer.Serialize(arr));
            clientWriter.Flush();

            string carsStr = JsonSerializer.Serialize(cars);

            carsStr = "";

            cars.ForEach(car =>
            {
                carsStr += JsonSerializer.Serialize(car) + "\n";
            });

            File.WriteAllText(@"C:\Users\Max\Downloads\Lab3_ris-master (1)\Lab3_ris-master\Lab3Server\text.txt", carsStr);
        }
Exemplo n.º 2
0
        private void DeleteCar(string name, StreamWriter clientWriter)
        {
            List <Car> cars = ReadCarsFromFile();

            cars = cars.FindAll(car => !car.Name.Equals(name));

            CarsArray arr = new CarsArray()
            {
                Cars = cars
            };

            string carsStr = JsonSerializer.Serialize(arr);

            clientWriter.WriteLine(carsStr);
            clientWriter.Flush();

            carsStr = "";

            cars.ForEach(car =>
            {
                carsStr += JsonSerializer.Serialize(car) + "\n";
            });

            File.WriteAllText(@"C:\Users\Max\Downloads\Lab3_ris-master (1)\Lab3_ris-master\Lab3Server\text.txt", carsStr);
        }
Exemplo n.º 3
0
        private void GetCars(StreamWriter clientWriter)
        {
            List <Car> cars = ReadCarsFromFile();

            CarsArray arr = new CarsArray()
            {
                Cars = cars
            };

            clientWriter.WriteLine(JsonSerializer.Serialize(arr));
            clientWriter.Flush();
        }
Exemplo n.º 4
0
        private void SearchCar(string payload, StreamWriter clientWriter)
        {
            List <Car> cars = ReadCarsFromFile();

            cars = cars.FindAll(car => car.Name.Contains(payload));

            CarsArray arr = new CarsArray()
            {
                Cars = cars
            };

            clientWriter.WriteLine(JsonSerializer.Serialize(arr));
            clientWriter.Flush();
        }
Exemplo n.º 5
0
        private void SortByPrice(StreamWriter clientWriter)
        {
            List <Car> cars = ReadCarsFromFile();

            IEnumerable <Car> query = cars.OrderBy(car => car.Price);

            cars = query.ToList();

            CarsArray arr = new CarsArray()
            {
                Cars = cars
            };

            clientWriter.WriteLine(JsonSerializer.Serialize(arr));
            clientWriter.Flush();
        }