コード例 #1
0
        public ResSummary PatchRestaurant(int id, ResPatch resPatch)
        {
            ResSummary resSummary = null;

            using (var con = new NpgsqlConnection(connectionString))
            {
                con.Open();

                using (var cmd = new NpgsqlCommand($"UPDATE restaurants SET rating = {resPatch.rating} WHERE restaurant_id = {id} RETURNING restaurant_id", con))
                    id = int.Parse(cmd.ExecuteScalar().ToString());
                using (var newcmd = new NpgsqlCommand($"SELECT * FROM restaurants WHERE restaurant_id = {id} ", con))
                    using (var reader = newcmd.ExecuteReader())
                        while (reader.Read())
                        {
                            resSummary = new ResSummary
                            {
                                restaurant_id = reader.GetInt32(0),
                                name          = reader.GetString(1),
                                description   = reader.GetString(2),
                                rating        = reader.GetIntOrDefault(3),
                                photo_url     = reader.GetStringOrDefault(4),
                                address       = reader.GetStringOrDefault(5),
                                link_to_360   = reader.GetStringOrDefault(6),
                                latitude      = reader.GetFloatOrDefault(7),
                                longitude     = reader.GetFloatOrDefault(8),
                                created_at    = reader.GetDateTimeOrDefault(9)
                            }
                        }
                ;
            }

            return(resSummary);
        }
    }
コード例 #2
0
 public ActionResult <ResSummary> Patch([FromRoute] int id, [FromBody] ResPatch resPatch)
 {
     return(restaurantsRepo.PatchRestaurant(id, resPatch));
 }