/// <summary> /// Toggles the like of the current post on the api. /// </summary> public async Task LikePostAsync(Post post) { var like = new Like { PostId = post.Id, UserIdentifier = DeviceUtils.DeviceId }; using (var client = new RestClient("http://localhost:55298/api/")) { var request = new RestRequest("likes", Method.POST); request.AddBody(like); var result = await client.Execute(request); if (result.StatusCode == System.Net.HttpStatusCode.Created) { post.Likes++; } else { post.Likes--; } } }
/// <summary> /// Adds a post to the api. /// </summary> /// <param name="imageId"></param> /// <returns></returns> private async Task<bool> AddPostAsync(int imageId) { using (var client = new RestClient("http://localhost:55298/api/")) { var request = new RestRequest("posts", Method.POST); var addPost = new Post { ImageId = imageId, Title = this.title, UserIdentifier = DeviceUtils.DeviceId }; request.AddJsonBody(addPost); try { await client.Execute(request); return true; } catch { return false; } } }