From f9b3344a77affab36681d3af2bda1acdf3a18acf Mon Sep 17 00:00:00 2001 From: Thomas Fransolet Date: Thu, 6 May 2021 17:40:03 +0200 Subject: [PATCH] Add TranslationDTO for titles and descriptions --- Manager.Interfaces/DTO/SectionDTO.cs | 4 +- Manager.Interfaces/DTO/SubSection/MapDTO.cs | 6 +-- .../DTO/SubSection/SliderDTO.cs | 4 +- Manager.Interfaces/DTO/TranslationDTO.cs | 12 ++++++ Manager.Interfaces/Models/Section.cs | 9 ++-- Manager.Interfaces/Models/SubSection/Map.cs | 6 +-- .../Models/SubSection/Slider.cs | 4 +- .../Controllers/SectionController.cs | 41 +++++++++++-------- 8 files changed, 52 insertions(+), 34 deletions(-) create mode 100644 Manager.Interfaces/DTO/TranslationDTO.cs diff --git a/Manager.Interfaces/DTO/SectionDTO.cs b/Manager.Interfaces/DTO/SectionDTO.cs index d64fd52..4f8e6a1 100644 --- a/Manager.Interfaces/DTO/SectionDTO.cs +++ b/Manager.Interfaces/DTO/SectionDTO.cs @@ -9,8 +9,8 @@ namespace Manager.Interfaces.DTO { public string Id { get; set; } public string Label { get; set; } // use in manager - public string Title { get; set; } // Dictionary with all languages - public string Description { get; set; } // Dictionary with all languages + public List Title { get; set; } + public List Description { get; set; } public string ImageId { get; set; } // == RessourceId public string ConfigurationId { get; set; } public bool IsSubSection { get; set; } // true if part of menu type diff --git a/Manager.Interfaces/DTO/SubSection/MapDTO.cs b/Manager.Interfaces/DTO/SubSection/MapDTO.cs index a0ae931..db80b61 100644 --- a/Manager.Interfaces/DTO/SubSection/MapDTO.cs +++ b/Manager.Interfaces/DTO/SubSection/MapDTO.cs @@ -16,11 +16,11 @@ namespace Manager.Interfaces.DTO public class GeoPointDTO { public int Id { get; set; } - public string Title { get; set; } // Dictionary with all languages - public string Description { get; set; } // Dictionary with all languages + public List Title { get; set; } + public List Description { get; set; } public string Image { get; set; } // url to ressource id (local) or on internet public string ImageType { get; set; } // url or ressource - public string Text { get; set; } // Dictionary with all languages + public List Text { get; set; } public string Latitude { get; set; } public string Longitude { get; set; } } diff --git a/Manager.Interfaces/DTO/SubSection/SliderDTO.cs b/Manager.Interfaces/DTO/SubSection/SliderDTO.cs index a05a597..47a01e5 100644 --- a/Manager.Interfaces/DTO/SubSection/SliderDTO.cs +++ b/Manager.Interfaces/DTO/SubSection/SliderDTO.cs @@ -10,8 +10,8 @@ namespace Manager.Interfaces.DTO } public class ImageDTO { - public string Title { get; set; } // Dictionary with all languages - public string Description { get; set; } // Dictionary with all languages + public List Title { get; set; } + public List Description { get; set; } public string Source { get; set; } // url to ressource id (local) or on internet } } diff --git a/Manager.Interfaces/DTO/TranslationDTO.cs b/Manager.Interfaces/DTO/TranslationDTO.cs new file mode 100644 index 0000000..6ca5ef1 --- /dev/null +++ b/Manager.Interfaces/DTO/TranslationDTO.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Manager.Interfaces.DTO +{ + public class TranslationDTO + { + public string Language { get; set; } + public string Value { get; set; } + } +} diff --git a/Manager.Interfaces/Models/Section.cs b/Manager.Interfaces/Models/Section.cs index 2b86bcd..2c91e8a 100644 --- a/Manager.Interfaces/Models/Section.cs +++ b/Manager.Interfaces/Models/Section.cs @@ -2,6 +2,7 @@ using MongoDB.Bson.Serialization.Attributes; using System; using System.Collections.Generic; +using System.Linq; using System.Text; @@ -22,10 +23,10 @@ namespace Manager.Interfaces.Models [BsonElement("Title")] [BsonRequired] - public string Title { get; set; } // Dictionary with all languages + public List Title { get; set; } [BsonElement("Description")] - public string Description { get; set; } // Dictionary with all languages + public List Description { get; set; } [BsonElement("ConfigurationId")] [BsonRequired] @@ -59,8 +60,8 @@ namespace Manager.Interfaces.Models { Id = Id, Label = Label, - Title = Title, - Description = Description, + Title = Title.OrderBy(t => t.Language).ToList(), + Description = Description.OrderBy(d => d.Language).ToList(), Type = Type, ImageId = ImageId, ConfigurationId = ConfigurationId, diff --git a/Manager.Interfaces/Models/SubSection/Map.cs b/Manager.Interfaces/Models/SubSection/Map.cs index 39f5a3c..3f30136 100644 --- a/Manager.Interfaces/Models/SubSection/Map.cs +++ b/Manager.Interfaces/Models/SubSection/Map.cs @@ -45,10 +45,10 @@ namespace Manager.Interfaces.Models public class GeoPoint { public int Id { get; set; } - public string Title { get; set; } // Dictionary with all languages - public string Description { get; set; } // Dictionary with all languages + public List Title { get; set; } + public List Description { get; set; } public string Image { get; set; } // url to ressource id (local) or on internet - public string Text { get; set; } // Dictionary with all languages + public List Text { get; set; } public string Latitude { get; set; } public string Longitude { get; set; } diff --git a/Manager.Interfaces/Models/SubSection/Slider.cs b/Manager.Interfaces/Models/SubSection/Slider.cs index d757862..d1d36b7 100644 --- a/Manager.Interfaces/Models/SubSection/Slider.cs +++ b/Manager.Interfaces/Models/SubSection/Slider.cs @@ -31,8 +31,8 @@ namespace Manager.Interfaces.Models public class Image { - public string Title { get; set; } // Dictionary with all languages - public string Description { get; set; } // Dictionary with all languages + public List Title { get; set; } + public List Description { get; set; } public string Source { get; set; } // url to ressource id (local) or on internet public ImageDTO ToDTO() diff --git a/ManagerService/Controllers/SectionController.cs b/ManagerService/Controllers/SectionController.cs index d19b03a..e47f759 100644 --- a/ManagerService/Controllers/SectionController.cs +++ b/ManagerService/Controllers/SectionController.cs @@ -229,10 +229,9 @@ namespace ManagerService.Controllers section.IsSubSection = false; section.ParentId = null; section.Type = newSection.Type; - + section.Title = new List(); + section.Description = new List(); // Preparation - Dictionary titles = new Dictionary(); - Dictionary descriptions = new Dictionary(); List languages = _configurationService.GetById(newSection.ConfigurationId).Languages; var mapDTO = new MapDTO(); // For menu dto @@ -240,29 +239,35 @@ namespace ManagerService.Controllers foreach (var language in languages) { + TranslationDTO title = new TranslationDTO(); + TranslationDTO description = new TranslationDTO(); + title.Language = language.ToUpper(); + description.Language = language.ToUpper(); switch (language.ToUpper()) { case "FR": - titles.Add(language, "Titre en français"); - descriptions.Add(language, "Description en français"); + title.Value = "Titre en français"; + description.Value = "Description en français"; break; case "EN": - titles.Add(language, "Title in english"); - descriptions.Add(language, "Description en anglais"); + title.Value = "Title in english"; + description.Value = "Description en anglais"; break; case "NL": - titles.Add(language, "Titre in dutch"); - descriptions.Add(language, "Description en néerlandais"); + title.Value = "Titre in dutch"; + description.Value = "Description en néerlandais"; break; case "DE": - titles.Add(language, "Titre en allemand"); - descriptions.Add(language, "Description en allemand"); + title.Value = "Titre en allemand"; + description.Value = "Description en allemand"; break; } + section.Title.Add(title); + section.Description.Add(description); } - section.Title = JsonConvert.SerializeObject(titles); - section.Description = JsonConvert.SerializeObject(descriptions); + section.Title = section.Title.OrderBy(t => t.Language).ToList(); + section.Description = section.Description.OrderBy(d => d.Language).ToList(); switch (newSection.Type) { case SectionType.Map: @@ -274,13 +279,13 @@ namespace ManagerService.Controllers mapDTO.Points = new List() { new GeoPointDTO() { Id = 0, - Title = JsonConvert.SerializeObject(titles), - Description = JsonConvert.SerializeObject(descriptions), + Title = section.Title, + Description = section.Description, Image = "", // TODO sample ImageType = "url", // TODO Latitude = "50.416639", Longitude= "4.879169", - Text= "Musée de la fraise texte" + Text= section.Description } }; @@ -289,8 +294,8 @@ namespace ManagerService.Controllers case SectionType.Slider: sliderDTO = new SliderDTO(); ImageDTO imageDTO = new ImageDTO(); - imageDTO.Title = JsonConvert.SerializeObject(titles); - imageDTO.Description = JsonConvert.SerializeObject(descriptions); + imageDTO.Title = section.Title; + imageDTO.Description = section.Description; imageDTO.Source = ""; sliderDTO.Images = new List(); sliderDTO.Images.Add(imageDTO);