Esempio n. 1
0
        public async Task <ActionResult> Put(int id, [FromBody] Dish dish)
        {
            // If id in body does not match the id in the URL
            if (id != dish.Dish_ID)
            {
                return(BadRequest("id in URL has to match the id of the record to be updated\n"));
            }

            try
            {
                // Searching for record in the Dish table
                var response = await _repository.GetById(id);

                // If record does not exists
                if (response == null)
                {
                    return(NotFound("Dish record was not found\n"));
                }
                else
                {
                    // Record exists then modify its
                    await _repository.ModifyById(dish);

                    string format = "Dish record with key={0} was updated succesfully\n";
                    return(Ok(String.Format(format, id)));
                }
            }
            catch (Npgsql.PostgresException ex)
            {
                // Postgres threw and exception
                return(BadRequest(ex.Message.ToString()));
            }
            catch
            {
                // Unknown error
                return(BadRequest("Error: Dish Record could not be updated\n"));
            }
        }