public async Task <OrderRatingResponse> RateOrder(OrderRatingRequest rating) { string url = $"/rate/create"; var requestBody = await Task.Run(() => JsonConvert.SerializeObject(rating)); using (HttpClient httpClient = new HttpClient()) { OrderRatingResponse data = new OrderRatingResponse(); try { var authHeader = new AuthenticationHeaderValue("Bearer", await SecureStorage.GetAsync("auth_token")); httpClient.DefaultRequestHeaders.Authorization = authHeader; httpClient.BaseAddress = new Uri(Constants.BaseUrl); StringContent content = new StringContent(requestBody, Encoding.UTF8, "application/json"); HttpResponseMessage result = await httpClient.PostAsync(url, content); string response = await result.Content.ReadAsStringAsync(); data = JsonConvert.DeserializeObject <OrderRatingResponse>(response); if (result.IsSuccessStatusCode && result.StatusCode == HttpStatusCode.OK) { return(data); } return(null); } catch (Exception exp) { return(null); } } }
public async Task <OrderRatingResponse> RateOrder(OrderRatingRequest rating) { IsBusy = true; var res = await orderRatingAPI.RateOrder(rating); IsBusy = false; return(res); }
private async void Submit_Clicked(object sender, EventArgs e) { Button button = (Button)sender; button.IsEnabled = false; try { OrderRatingRequest rating = new OrderRatingRequest() { userId = OperationData.userId, itemId = order.itemId, sellerId = order.SellerId, orderId = order.id, comment = !string.IsNullOrEmpty(OrderCommentEditor.Text) == true ? OrderCommentEditor.Text : "", starRating = RatingView.Value != null?Convert.ToInt32(RatingView.Value) : 0 }; var res = await orderRatingViewModel.RateOrder(rating); if (res != null) { if (res.Code == 0) { await PopupNavigation.PopAsync(); //pastOrdersViewModel.LoadOrdersCommand.Execute(null); MessagingCenter.Send(res.Data, "ORDER_RATED"); } else { await DisplayAlert("Something went wrong", "Please try again.", null, "OK"); } } else { await DisplayAlert("Something went wrong", "Please try again.", null, "OK"); } } catch (Exception ex) { } finally { button.IsEnabled = true; } }