public IActionResult UpdateFoodEntry(Guid id, [FromBody] FoodEntryUpdateModel updateModel)
        {
            UpdateFoodEntryResponse response = _foodEntryService.UpdateFoodEntry(id, updateModel);

            if (!response.ResponseStatus.HasError())
            {
                return(Ok());
            }

            return(StatusCode(response.ResponseStatus.Status, response.ResponseStatus.Message));
        }
Ejemplo n.º 2
0
        public UpdateFoodEntryResponse UpdateFoodEntry(Guid foodEntryId, FoodEntryUpdateModel updateModel)
        {
            //TODO: Handle food entry with non existent id
            UpdateFoodEntryResponse response = new UpdateFoodEntryResponse();

            try
            {
                _foodEntryRepository.UpdateFoodEntry(foodEntryId, updateModel);

                response.ResponseStatus.SetOk();
            }
            catch (Exception e)
            {
                _logger.LogError(e.ToString());

                response.ResponseStatus.SetError(ResponseStatusCode.INTERNAL_SERVER_ERROR,
                                                 e.ToString());
            }

            return(response);
        }
Ejemplo n.º 3
0
        public void UpdateFoodEntry(Guid foodEntryId, FoodEntryUpdateModel updateModel)
        {
            try
            {
                double servingAmount = updateModel.ServingAmount;

                int selectedServingId = updateModel.SelectedServingId;

                string sql = $"call update_food_entry_serving_size('{foodEntryId}',{servingAmount},{selectedServingId})";

                using (var connection = _dbConnectionFactory.CreateConnection(ConfigurationsHelper.ConnectionString))
                {
                    connection.Open();

                    connection.Execute(sql);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }