public async Task AddAsync(IngredientCreateDto ingredientCreateDto) { var payload = JsonConvert.SerializeObject(ingredientCreateDto); var content = new StringContent( payload, Encoding.UTF8, "application/json" ); var relativeUri = new Uri(IngredientListsDynamicRoutes.INGREDIENT_LIST_ROUTE(_ingredientListId), UriKind.Relative); var httpResponseMessage = await _httpClient.PutAsync( relativeUri, content ); if (httpResponseMessage.StatusCode != HttpStatusCode.OK) { var responseContent = await httpResponseMessage.Content.ReadAsStringAsync(); var exception = HttpResponseContentToException.Convert(responseContent); throw exception; } }
public async Task RemoveAsync(Guid ingredientId) { var relativeUri = new Uri(IngredientListsDynamicRoutes.INGREDIENT_ROUTE(_ingredientListId, ingredientId), UriKind.Relative); var httpResponseMessage = await _httpClient.DeleteAsync( relativeUri ); httpResponseMessage.EnsureSuccessStatusCode(); }
public async Task <IEnumerable <IngredientResultDto> > GetAllAsync(Guid ingredientListId) { var relativeUri = new Uri(IngredientListsDynamicRoutes.INGREDIENT_LIST_ROUTE(_ingredientListId), UriKind.Relative); var httpResponseMessage = await _httpClient.GetAsync( relativeUri ); httpResponseMessage.EnsureSuccessStatusCode(); var content = await httpResponseMessage.Content.ReadAsStringAsync(); var topics = JsonConvert.DeserializeObject <IEnumerable <IngredientResultDto> >(content); return(topics); }