From 26feaeca304f1ece2d3f66885cf80d49d4e4d628 Mon Sep 17 00:00:00 2001 From: Markus Meyer Date: Tue, 3 Mar 2020 05:55:39 +0100 Subject: [PATCH] #66 Change Restaurant Id --- .../Models/RestaurantModel.cs | 8 ++----- .../RestaurantService.cs | 24 +++++++++++++++---- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/PlanB.Butler.Services/PlanB.Butler.Services/Models/RestaurantModel.cs b/PlanB.Butler.Services/PlanB.Butler.Services/Models/RestaurantModel.cs index eacc708..39acb14 100644 --- a/PlanB.Butler.Services/PlanB.Butler.Services/Models/RestaurantModel.cs +++ b/PlanB.Butler.Services/PlanB.Butler.Services/Models/RestaurantModel.cs @@ -16,7 +16,7 @@ namespace PlanB.Butler.Services.Models public class RestaurantModel { /// - /// Gets the identifier. + /// Gets or sets the identifier. /// /// /// The identifier. @@ -24,11 +24,7 @@ public class RestaurantModel [JsonProperty("id")] public string Id { - get - { - var id = $"{this.Name}-{this.City}"; - return id; - } + get; set; } /// diff --git a/PlanB.Butler.Services/PlanB.Butler.Services/RestaurantService.cs b/PlanB.Butler.Services/PlanB.Butler.Services/RestaurantService.cs index ee9e892..3e4078f 100644 --- a/PlanB.Butler.Services/PlanB.Butler.Services/RestaurantService.cs +++ b/PlanB.Butler.Services/PlanB.Butler.Services/RestaurantService.cs @@ -8,7 +8,7 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; - +using System.Web; using AzureFunctions.Extensions.Swashbuckle.Attribute; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -271,12 +271,16 @@ public static async Task CreateRestaurant( if (isValid) { - var filename = $"{restaurantModel.Id}.json"; - trace.Add($"filename", filename); + var fileName = CreateFileName(restaurantModel); + trace.Add($"fileName", fileName); + restaurantModel.Id = fileName; + + var fullFileName = $"{fileName}.json"; + trace.Add($"fullFileName", fullFileName); req.HttpContext.Response.Headers.Add(Constants.ButlerCorrelationTraceHeader, correlationId.ToString()); - CloudBlockBlob blob = cloudBlobContainer.GetBlockBlobReference($"{filename}"); + CloudBlockBlob blob = cloudBlobContainer.GetBlockBlobReference($"{fullFileName}"); if (blob != null) { blob.Properties.ContentType = "application/json"; @@ -377,5 +381,17 @@ internal static bool Validate(RestaurantModel model, Guid correlationId, ILogger return isValid; } + + /// + /// Creates the name of the file. + /// + /// The model. + /// + internal static string CreateFileName(RestaurantModel model) + { + string fileName = $"{model.Name}-{model.City}"; + fileName = HttpUtility.UrlEncode(fileName); + return fileName; + } } }