Beispiel #1
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);
            }
        }
Beispiel #2
0
        internal async Task <int> QueryShift(ShiftTable shift, bool shiftStarted, int userId = 0, int companyId = 0, int dayShift = 0)
        {
            string contentType = Constants.CONTENT_TYPE;
            string url;

            string json;

            if (shiftStarted)
            {
                url = GetBaseUrl() + Constants.REST_URL_ADDSHIFTEND;
                EndShiftModel shiftModel = new EndShiftModel()
                {
                    id              = shift.ServerKey,
                    endDate         = shift.EndDate,
                    endLocationLat  = shift.EndLat,
                    endLocationLong = shift.EndLong,
                    endLocation     = shift.EndLocation,
                    endNote         = shift.EndNote
                };
                json = JsonConvert.SerializeObject(shiftModel);
            }
            else
            {
                url = GetBaseUrl() + Constants.REST_URL_ADDSHIFTSTART;

                StartShiftModel shiftModel = new StartShiftModel()
                {
                    driverId          = userId,
                    companyId         = companyId,
                    startDate         = shift.StartDate,
                    startLocationLat  = shift.StartLat,
                    startLocationLong = shift.StartLong,
                    startLocation     = shift.StartLocation,
                    startNote         = shift.StartNote,
                    dayShiftId        = dayShift
                };
                json = JsonConvert.SerializeObject(shiftModel);
            }

            HttpContent content = new StringContent(json, Encoding.UTF8, contentType);

            HttpResponseMessage response;

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

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

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

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

                return(-2);
            }
        }