Beispiel #1
0
        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);
        }
Beispiel #2
0
        public async Task <bool> UpdateFood(int foodId, Catering.Data.Food food)
        {
            EnsureClient();

            bool success = false;

            try
            {
                var response = await _client.PutAsJsonAsync("api/food/" + foodId, food);

                response.EnsureSuccessStatusCode();
                success = true;
            }
            catch (HttpRequestException ex)
            {
                _logger.LogError("Caught exception whilst updating food: " + food + ". Exception: " + ex.Message);
            }

            return(success);
        }