/// <summary> /// Удалить суслика из избранное. /// </summary> /// <param name="addedGopher">Удаляемый пользователь.</param> /// <param name="addingGopher">Удаляющий пользователь.</param> /// <returns>Был ли удален пользователь в избранное.</returns> public async Task <bool> RemoveFromFavorites(IGopher addedGopher, IGopher addingGopher) { using (var client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = AuthenticationHeaderValue.Parse($"{_token.TokenType} {_token.Token}"); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var response = await client.PostAsync(RemoveFromFavoritesUri, new FormUrlEncodedContent(new Dictionary <string, string> { { "suslik_uuid", addedGopher.Guid.ToString() }, { "user_uuid", addingGopher.Guid.ToString() } })); var jsonString = await response.Content.ReadAsStringAsync(); Debug.WriteLine(jsonString); return(await Task.FromResult(response.IsSuccessStatusCode)); } }
/// <summary> /// Возвращает сусликов добавленных в избранное. /// </summary> /// <param name="gopher">Пользователь добавивший сусликов в избранное.</param> /// <returns>Список сусликов.</returns> public async Task <IEnumerable <IGopher> > GetFavorites(IGopher gopher) { using (var client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = AuthenticationHeaderValue.Parse($"{_token.TokenType} {_token.Token}"); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var response = await client.PostAsync(FavoritesGophersUri, new FormUrlEncodedContent(new Dictionary <string, string> { { "user_uuid", gopher.Guid.ToString() } })); var jsonString = await response.Content.ReadAsStringAsync(); Debug.WriteLine(jsonString); var jsonData = JsonConvert.DeserializeObject <JsonDataResponse <List <Gopher> > >(jsonString); SetPictures(jsonData.Data); return(await Task.FromResult(jsonData.Data)); } }