public async void ButtonClick(object sender, EventArgs e) { if (postList.Children.IndexOf((Button)sender) != votedOption) { var k = await App.Current.MainPage.DisplayAlert("Alert", "Are you sure?", "Yes", "No"); if (k) { await((HomeLayout)App.Current.MainPage).SetLoading(true, "Updating vote.."); await((HomeLayout)App.Current.MainPage).SetProgressBar(0.2); currentPost = await BaseFunctions.GetPost(currentPost.postID); await((HomeLayout)App.Current.MainPage).SetProgressBar(0.4); if (votedOption != -1) { ServerVoteOption vOption = currentPost.voteOptions[votedOption]; vOption.votedUsers.Remove(App.userID); currentPost.voteOptions[votedOption] = vOption; } for (int i = 0; i < postList.Children.Count; i++) { if (sender == postList.Children[i] && i != votedOption) { ServerVoteOption voteOption = currentPost.voteOptions[i]; ((Button)postList.Children[i]).BackgroundColor = b_BackgroundColor(true); ((Button)postList.Children[i]).TextColor = b_TextColor(true); votedOption = i; voteOption.votedUsers.Add(App.userID); currentPost.voteOptions[i] = voteOption; if (await BaseFunctions.EditPost(currentPost)) { await((HomeLayout)App.Current.MainPage).SetProgressBar(0.6); await((HomeLayout)App.Current.MainPage).DisplayAlert("Vote Updated", "Thank you for Voting...", "Close"); } } else { ((Button)postList.Children[i]).BackgroundColor = b_BackgroundColor(false); ((Button)postList.Children[i]).TextColor = b_TextColor(false); } } await((HomeLayout)App.Current.MainPage).SetProgressBar(0.8); await((HomeLayout)App.Current.MainPage).SetLoading(false, "Updating vote.."); } } }