Esempio n. 1
0
        public static Car ReadCarById(int id)
        {
            RequestProvider requestProvider = new RequestProvider(readUri);

            requestProvider.Id = id;
            byte[] response        = requestProvider.performGet();
            string encodedResponse = Encoding.UTF8.GetString(response, 0, response.Length);

            if (errorsRead.Contains(encodedResponse))
            {
                MainWindow.ShowErrorInfo(encodedResponse);
                return(new Car());
            }
            else
            {
                CarWrapper carWrapper             = JsonConvert.DeserializeObject <CarWrapper>(encodedResponse);
                Singleton.GetInstance().ActualCar = carWrapper;
                return(new Car()
                {
                    CarId = carWrapper.Id,
                    CarManufacturer = carWrapper.Manufacturer,
                    CarModel = carWrapper.Model,
                    CarFirstRegistrationDate = carWrapper.FirstRegistrationDate,
                    CarActualMileage = carWrapper.ActualMileage,
                    CarLicencePlate = carWrapper.LicencePlate,
                    CarPurchaseDate = carWrapper.PurchaseDate,
                    CarPurchaseMileage = carWrapper.PurchaseMileage,
                    CarVin = carWrapper.Vin
                });
            }
        }
Esempio n. 2
0
        public static string CreateCar(ComboBox comboBoxCars, Dictionary <string, string> paramDictionary, ref int counter)
        {
            RequestProvider requestProvider = new RequestProvider(createUri);

            requestProvider.Parameters = paramDictionary;
            byte[] response        = requestProvider.performPost();
            string encodedResponse = Encoding.UTF8.GetString(response, 0, response.Length);

            if (errorsCreate.Contains(encodedResponse))
            {
                return(encodedResponse);
            }
            CarWrapper carWrapper = JsonConvert.DeserializeObject <CarWrapper>(encodedResponse);

            Singleton.GetInstance().ActualUser.CarList.Add(carWrapper.Id);
            ObservableCollection <CmbElement> cmbList = (ObservableCollection <CmbElement>)comboBoxCars.ItemsSource;
            CmbElement cmbElementActual = new CmbElement {
                Id = counter++, Value = carWrapper.Id.ToString()
            };

            cmbList.Add(cmbElementActual);
            comboBoxCars.ItemsSource  = cmbList;
            comboBoxCars.SelectedItem = cmbElementActual;
            return("Correct");
        }