public async Task <FoodGetDto> AddFood(Catering.Data.Food food) { EnsureClient(); FoodGetDto foodGetDto = null; try { var response = await _client.PostAsJsonAsync("api/food", food); response.EnsureSuccessStatusCode(); foodGetDto = await response.Content.ReadAsAsync <FoodGetDto>(); } catch (HttpRequestException ex) { _logger.LogError("Caught exception whilst adding food: " + food + ". Exception: " + ex.Message); } return(foodGetDto); }
public async Task <FoodGetDto> GetFood(int id) { EnsureClient(); FoodGetDto foodGetDto = null; try { var response = await _client.GetAsync("api/food/" + id); response.EnsureSuccessStatusCode(); foodGetDto = await response.Content.ReadAsAsync <FoodGetDto>(); } catch (HttpRequestException ex) { _logger.LogError("Caught exception whilst getting food id: " + id + ". Exception: " + ex.Message); } return(foodGetDto); }