Exemple #1
0
        private async Task <SubmitCaseRsp> CallQueue(ClaimModel claim)
        {
            string json = JsonConvert.SerializeObject(claim);
            HttpResponseMessage response = await HttpUtil.PostJsonAsync(json, Settings.QueueUrl, _authenticationResult.Token);

            if (response.IsSuccessStatusCode)
            {
                string responseStr = await response.Content.ReadAsStringAsync();

                char[] charsToTrim = { '\"' };
                responseStr = responseStr.Trim(charsToTrim).Replace("\\\"", "\"");
                SubmitCaseRsp value = JsonConvert.DeserializeObject <SubmitCaseRsp>(responseStr);
                return(value);
            }
            return(null);
        }
Exemple #2
0
        private async void OnSubmitClaimButtonClicked(object sender, EventArgs e)
        {
            try
            {
                if (_mediaFile != null)
                {
                    using (var scope = new ActivityIndicatorScope(activityIndicator, activityIndicatorPanel, true))
                    {
                        HttpResponseMessage response = await HttpUtil.PostImageAsync(_mediaFile, Settings.UploadImageUrl, _authenticationResult.Token);

                        if (response.IsSuccessStatusCode)
                        {
                            string responseURL = await response.Content.ReadAsStringAsync();

                            char[] charsToTrim = { '\"' };
                            responseURL = responseURL.Trim(charsToTrim);

                            Random     rnd       = new Random();
                            string     claimName = rnd.Next(15000, 16000).ToString();
                            ClaimModel claim     = new ClaimModel
                            {
                                Id               = Guid.NewGuid().ToString(),
                                Name             = claimName,
                                Status           = "Submitted",
                                ClaimDateTime    = this.datePicker.Date,
                                ClaimDescription = this.claimDescriptionEditor.Text,
                                ImageUrl         = responseURL,
                                Tag              = ""
                            };

                            SubmitCaseRsp ret = await CallQueue(claim);

                            if (ret != null && ret.result)
                            {
                                _parentPage.AddNewClaim(claim);
                                await DisplayAlert("Thank you", "Your claim is being processed.", "Ok");

                                await Navigation.PopAsync();
                            }
                            else
                            {
                                await DisplayAlert("Please resubmit", "Photo doesn't appear to match the claim.", "Ok");
                            }
                        }
                        else
                        {
                            // If the call failed with access denied, show the user an error indicating they might need to sign-in again.
                            if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
                            {
                                await DisplayAlert("Unauthorized", "Please login again, then new claim works well again", "Ok");

                                await Navigation.PopToRootAsync();
                            }
                            else
                            {
                                await DisplayAlert("Error", response.StatusCode.ToString(), "Ok");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Utils.TraceException("Image upload failed", ex);
                await DisplayAlert("Image upload failed", "Image upload failed. Please try again later", "Ok");
            }
        }