Exemplo n.º 1
0
        public static async Task UpdateAccidentDeviceAndAPI()
        {
            parentViewModel.Accident = Context.AccidentRepository.AddOrUpdate(parentViewModel.Accident);

            if (await App.CheckForValidAccountAndTokenAndRefreshIfExpired())
            {
                if (parentViewModel.Accident.Id != 0)
                {
                    using (var accidentClient = new AutoResolveWebserviceClient<AccidentViewModel>("api/accidents/" + parentViewModel.Accident.Id))
                    {
                        accidentClient.AddBearerTokenHeader(parentViewModel.CurrentAccount.LatestBearerToken);
                        var response = await accidentClient.PutAsync(parentViewModel.Accident);


                        if (response.IsSuccessStatusCode)
                        {
                            //nothing
                        }
                        else
                        {
                            var error = await response.Content.ReadAsStringAsync();
                            SetLatestAPIErrorMessage(error);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static async Task<HttpResponseMessage> UpdateWitnessDeviceAndAPIIfNoKey(WitnessViewModel vm)
        {
            Context.WitnessRepository.AddOrUpdate(vm);

            if (await App.CheckForValidAccountAndTokenAndRefreshIfExpired())
            {
                if (parentViewModel.Customer.Id != 0)
                {
                    //create in API
                    using (var otherDriverClient = new AutoResolveWebserviceClient<WitnessViewModel>("api/otherdrivers/" + vm.Id))
                    {
                        otherDriverClient.AddBearerTokenHeader(parentViewModel.CurrentAccount.LatestBearerToken);
                        var response = await otherDriverClient.PutAsync(vm);

                        if (response.IsSuccessStatusCode)
                        {
                            //nothing
                        }
                        else
                        {
                            var error = await response.Content.ReadAsStringAsync();
                            SetLatestAPIErrorMessage(error);
                        }

                        return response;
                    }
                }
            }
            return null;
        }
Exemplo n.º 3
0
        public static async Task UpdateCustomerSettingsDeviceAndAPI()
        {
            UserSettings = Context.CustomerSettingsRepository.AddOrUpdate(UserSettings);
            if (await App.CheckForValidAccountAndTokenAndRefreshIfExpired())
            {
                if (UserSettings.Id != 0)
                {
                    //create in API
                    using (var customerSettingsClient = new AutoResolveWebserviceClient<CustomerSettingsViewModel>("api/customersettings/" + UserSettings.Id))
                    {
                        customerSettingsClient.AddBearerTokenHeader(parentViewModel.CurrentAccount.LatestBearerToken);
                        var response = await customerSettingsClient.PutAsync(UserSettings);

                        if (response.IsSuccessStatusCode)
                        {
                            //nothing
                        }
                        else
                        {
                            var error = await response.Content.ReadAsStringAsync();
                            SetLatestAPIErrorMessage(error);
                        }
                    }
                }
            }
        }