public async Task jsAddLike(string id) { var currPost = await GetPostByIdAsync(id); var ImgCreatorId = currPost.ProfileId; var currUserId = User.Identity.Name; var obj = new ReqStr { Id = currPost.Id, ArrayName = "Likes", //Method = "Add", UserId = User.Identity.Name }; if (currPost.LikesProfileId.Where(x => x == User.Identity.Name).Count() == 0) // You cant add like if you already like { obj.Method = "Add"; } else { obj.Method = "Del"; //currPost.LikesProfileId.Add(currUserId); } await ChangePostAsync(obj); // } //} }
public async Task ChangePostAsync(ReqStr obj) { var js = JsonConvert.SerializeObject(obj); HttpContent cont = new StringContent(js, Encoding.UTF8, "application/json"); var response = await _apiService.callPutAPI("http://localhost:5012/posts", cont); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); } }