private async void SubmitButton_Clicked(object sender, EventArgs e)
        {
            try
            {
                VoteInputView inputVote = new VoteInputView
                {
                    comments   = entryComment.Text,
                    supercarId = Convert.ToInt32(entrySuperCarId.Text),
                    userId     = _myProfile.UserId
                };
                await _myServices.PostVote(inputVote);

                //var dataBaru = await _myServices.GetLeaderboardById(Convert.ToInt32(entrySuperCarId));
                //this.BindingContext = dataBaru;
                await DisplayAlert("Keterangan", "Vote Berhasil Ditambah", "OK");

                var data = await _myServices.GetLeaderboardById(Convert.ToInt32(entrySuperCarId.Text));

                data.Votes.RemoveAll(item => item == null);
                this.BindingContext = data;
                BeginInit();
            }
            catch (Exception ex)
            {
                await DisplayAlert("Kesalahan", $"{ex.Message}", "OK");
            }
        }
예제 #2
0
        public async Task PostVote(VoteInputView inputVote)
        {
            var uriPost = new Uri(hostUrl + "api/Vote");

            try
            {
                var jsonData = JsonConvert.SerializeObject(inputVote);
                var content  = new StringContent(jsonData, Encoding.UTF8, "application/json");
                _client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "PhoneApp");
                HttpResponseMessage response = await _client.PostAsync(uriPost, content);

                if (!response.IsSuccessStatusCode)
                {
                    throw new Exception($"Gagal menambah data: {response.StatusCode}");
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }