private async void LikeCommentClick(UIFeedButton button) { button.LoadingIndicatorButton(true); if ("Like".Equals(button.CurrentTitle)) { button.SetTitle("Unlike", UIControlState.Normal); updateLikeCount(++surveyCommentModel.totalLikes); SurveyCommentLikeModel surveyCommentLikeModel = new SurveyCommentLikeModel(); surveyCommentLikeModel.commentId = surveyCommentModel.surveyId + surveyCommentModel.commentDate; surveyCommentLikeModel.user = new User(); surveyCommentLikeModel.user.id = LoginController.userModel.id; surveyCommentModel.userLiked = true; await commentLikeManager.LikeComment(surveyCommentLikeModel, LoginController.tokenModel.access_token); } else { button.SetTitle("Like", UIControlState.Normal); updateLikeCount(--surveyCommentModel.totalLikes); surveyCommentModel.userLiked = null; await commentLikeManager.UnlikeComment(surveyCommentModel.surveyId + surveyCommentModel.commentDate, LoginController.userModel.id, LoginController.tokenModel.access_token); } LayoutSubviews(); button.LoadingIndicatorButton(false); }
public async Task LikeComment(SurveyCommentLikeModel surveyCommentLikeModel, string authenticationToken) { try { CommentLikeService commentLikeService = new CommentLikeService(); var response = await commentLikeService.LikeComment(surveyCommentLikeModel, authenticationToken).ConfigureAwait(false); if (!response.IsSuccessStatusCode) { throw new Exception(response.StatusCode.ToString() + " - " + response.ReasonPhrase); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task <HttpResponseMessage> LikeComment(SurveyCommentLikeModel surveyCommentLikeModel, string authenticationToken) { try { using (var client = new HttpClient()) { var formContent = new StringContent(JsonConvert.SerializeObject(surveyCommentLikeModel, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }), Encoding.UTF8, "application/json"); client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "Bearer " + authenticationToken); return(await client.PostAsync(EnvironmentConstants.getServerUrl() + "api/survey/likecomment", formContent)); } } catch (Exception ex) { throw new Exception(ex.Message); } }