Пример #1
0
        internal async Task <int> GetVehicleHubo(VehicleTable vehicle)
        {
            string url         = GetBaseUrl() + Constants.REST_URL_GETVEHICLEHUBO;
            string contentType = Constants.CONTENT_TYPE;
            HttpResponseMessage response;

            var huboGet = new HttpRequestMessage(HttpMethod.Get, url);

            huboGet.Headers.Add("VehicleId", vehicle.ServerKey.ToString());

            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.Add("Authorization", accessToken);

                try
                {
                    response = await client.SendAsync(huboGet);
                }
                catch
                {
                    return(0);
                }
            }

            if (response.IsSuccessStatusCode)
            {
                VehicleHuboResponse huboResponse = JsonConvert.DeserializeObject <VehicleHuboResponse>(response.Content.ReadAsStringAsync().Result);
                return(huboResponse.Hubo);
            }
            else
            {
                return(0);
            }
        }
Пример #2
0
        internal async Task <bool> QueryAddVehicle(VehicleTable vehicle)
        {
            string url         = GetBaseUrl() + Constants.REST_URL_ADDVEHICLE;
            string contentType = Constants.CONTENT_TYPE;

            VehicleRequestModel vehicleModel = new VehicleRequestModel()
            {
                registrationNo = vehicle.Registration,
                makeModel      = vehicle.MakeModel,
                fleetNumber    = vehicle.FleetNumber,
                companyId      = vehicle.CompanyId
            };
            string      json    = JsonConvert.SerializeObject(vehicleModel);
            HttpContent content = new StringContent(json, Encoding.UTF8, contentType);

            HttpResponseMessage response;

            using (HttpClient client = new HttpClient())
            {
                try
                {
                    response = await client.PostAsync(url, content);
                }
                catch
                {
                    return(false);
                }
            }

            if (response.IsSuccessStatusCode)
            {
                QueryShiftResponse result = JsonConvert.DeserializeObject <QueryShiftResponse>(response.Content.ReadAsStringAsync().Result);

                if (result.Success)
                {
                    return(true);
                }
                else
                {
                    await UserDialogs.Instance.AlertAsync(Resource.RegisterVehicleError, Resource.Alert, Resource.Okay);

                    return(false);
                }
            }
            else
            {
                await UserDialogs.Instance.AlertAsync(Resource.ConnectionError, Resource.Alert, Resource.Okay);

                return(false);
            }
        }
Пример #3
0
        internal async Task <int> InsertVehicle(VehicleTable vehicleToInsert)
        {
            string url         = GetBaseUrl() + Constants.REST_URL_ADDVEHICLE;
            string contentType = Constants.CONTENT_TYPE;
            HttpResponseMessage response;

            VehicleInsertModel vehicleInsertModel = new VehicleInsertModel()
            {
                RegistrationNo    = vehicleToInsert.Registration,
                IsManuallyEntered = true
            };

            string      json    = JsonConvert.SerializeObject(vehicleInsertModel);
            HttpContent content = new StringContent(json, Encoding.UTF8, contentType);

            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.Add("Authorization", accessToken);
                try
                {
                    response = await client.PostAsync(url, content);
                }
                catch
                {
                    return(-1);
                }
            }

            if (response.IsSuccessStatusCode)
            {
                InsertVehicleResponse result = JsonConvert.DeserializeObject <InsertVehicleResponse>(response.Content.ReadAsStringAsync().Result);
                if (result.Success)
                {
                    return(result.Result);
                }

                return(-1);
            }

            return(-1);
        }
Пример #4
0
        internal void UpdatePage(int selectedVehicle)
        {
            VehicleTable vehicle = new VehicleTable();

            vehicle = listOfVehicles[selectedVehicle];

            CompanyTable companyDetails = new CompanyTable();

            companyDetails = GetCompany(vehicle.CompanyId);

            RegistrationEntry = vehicle.Registration;
            MakeModelEntry    = vehicle.MakeModel;
            FleetEntry        = vehicle.FleetNumber;
            Company           = companyDetails.Name;

            VehicleSelected = true;

            OnPropertyChanged("RegistrationEntry");
            OnPropertyChanged("MakeModelEntry");
            OnPropertyChanged("FleetEntry");
            OnPropertyChanged("VehicleActive");
            OnPropertyChanged("VehicleSelected");
            OnPropertyChanged("SwitchText");
        }