256 lines
13 KiB
C#
256 lines
13 KiB
C#
using Manager.DTOs;
|
|
using ManagerService.Data;
|
|
using ManagerService.Data.SubSection;
|
|
using ManagerService.DTOs;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace ManagerService.Services
|
|
{
|
|
public static class SectionFactory
|
|
{
|
|
public static Section Create(SectionDTO dto)
|
|
{
|
|
return dto.type switch
|
|
{
|
|
SectionType.Agenda => new SectionAgenda
|
|
{
|
|
Id = dto.id,
|
|
Label = dto.label,
|
|
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
|
|
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
|
|
Order = dto.order.Value,
|
|
ImageId = dto.imageId,
|
|
ImageSource = dto.imageSource,
|
|
IsSubSection = dto.isSubSection,
|
|
ParentId = dto.parentId,
|
|
IsBeacon = dto.isBeacon,
|
|
BeaconId = dto.beaconId,
|
|
Latitude = dto.latitude,
|
|
Longitude = dto.longitude,
|
|
MeterZoneGPS = dto.meterZoneGPS,
|
|
Type = dto.type,
|
|
AgendaResourceIds = ((AgendaDTO)dto).resourceIds.Select(r => new Translation().FromDTO(r)).ToList(),
|
|
AgendaMapProvider = ((AgendaDTO)dto).agendaMapProvider
|
|
},
|
|
SectionType.Article => new SectionArticle
|
|
{
|
|
Id = dto.id,
|
|
Label = dto.label,
|
|
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
|
|
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
|
|
Order = dto.order.Value,
|
|
ImageId = dto.imageId,
|
|
ImageSource = dto.imageSource,
|
|
IsSubSection = dto.isSubSection,
|
|
ParentId = dto.parentId,
|
|
IsBeacon = dto.isBeacon,
|
|
BeaconId = dto.beaconId,
|
|
Latitude = dto.latitude,
|
|
Longitude = dto.longitude,
|
|
MeterZoneGPS = dto.meterZoneGPS,
|
|
Type = dto.type,
|
|
ArticleContent = ((ArticleDTO)dto).content.Select(r => new Translation().FromDTO(r)).ToList(),
|
|
ArticleIsContentTop = ((ArticleDTO)dto).isContentTop,
|
|
ArticleAudioIds = ((ArticleDTO)dto).audioIds.Select(a => new Translation().FromDTO(a)).ToList(),
|
|
ArticleIsReadAudioAuto = ((ArticleDTO)dto).isReadAudioAuto,
|
|
ArticleContents = ((ArticleDTO)dto).contents.Select(c => new Content().FromDTO(c)).ToList()
|
|
},
|
|
SectionType.Map => new SectionMap
|
|
{
|
|
Id = dto.id,
|
|
Label = dto.label,
|
|
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
|
|
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
|
|
Order = dto.order.Value,
|
|
ImageId = dto.imageId,
|
|
ImageSource = dto.imageSource,
|
|
IsSubSection = dto.isSubSection,
|
|
ParentId = dto.parentId,
|
|
IsBeacon = dto.isBeacon,
|
|
BeaconId = dto.beaconId,
|
|
Latitude = dto.latitude,
|
|
Longitude = dto.longitude,
|
|
MeterZoneGPS = dto.meterZoneGPS,
|
|
Type = dto.type,
|
|
MapZoom = ((MapDTO)dto).zoom,
|
|
MapMapType = ((MapDTO)dto).mapType,
|
|
MapTypeMapbox = ((MapDTO)dto).mapTypeMapbox,
|
|
MapMapProvider = ((MapDTO)dto).mapProvider,
|
|
MapResourceId = ((MapDTO)dto).iconResourceId,
|
|
MapCenterLatitude = ((MapDTO)dto).centerLatitude,
|
|
MapCenterLongitude = ((MapDTO)dto).centerLongitude,
|
|
MapCategories = null, //((MapDTO)dto).categories, // TODO specific
|
|
MapPoints = null // ((MapDTO)dto).points, // TODO specific
|
|
},
|
|
SectionType.Menu => new SectionMenu
|
|
{
|
|
Id = dto.id,
|
|
Label = dto.label,
|
|
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
|
|
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
|
|
Order = dto.order.Value,
|
|
ImageId = dto.imageId,
|
|
ImageSource = dto.imageSource,
|
|
IsSubSection = dto.isSubSection,
|
|
ParentId = dto.parentId,
|
|
IsBeacon = dto.isBeacon,
|
|
BeaconId = dto.beaconId,
|
|
Latitude = dto.latitude,
|
|
Longitude = dto.longitude,
|
|
MeterZoneGPS = dto.meterZoneGPS,
|
|
Type = dto.type,
|
|
//Sections = ((MenuDTO)dto).sections, // TODO specific
|
|
},
|
|
SectionType.PDF => new SectionPdf
|
|
{
|
|
Id = dto.id,
|
|
Label = dto.label,
|
|
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
|
|
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
|
|
Order = dto.order.Value,
|
|
ImageId = dto.imageId,
|
|
ImageSource = dto.imageSource,
|
|
IsSubSection = dto.isSubSection,
|
|
ParentId = dto.parentId,
|
|
IsBeacon = dto.isBeacon,
|
|
BeaconId = dto.beaconId,
|
|
Latitude = dto.latitude,
|
|
Longitude = dto.longitude,
|
|
MeterZoneGPS = dto.meterZoneGPS,
|
|
Type = dto.type,
|
|
PDFOrderedTranslationAndResources = ((PdfDTO)dto).pdfs.Select(p => new OrderedTranslationAndResource().FromDTO(p)).ToList()
|
|
},
|
|
SectionType.Puzzle => new SectionPuzzle
|
|
{
|
|
Id = dto.id,
|
|
Label = dto.label,
|
|
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
|
|
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
|
|
Order = dto.order.Value,
|
|
ImageId = dto.imageId,
|
|
ImageSource = dto.imageSource,
|
|
IsSubSection = dto.isSubSection,
|
|
ParentId = dto.parentId,
|
|
IsBeacon = dto.isBeacon,
|
|
BeaconId = dto.beaconId,
|
|
Latitude = dto.latitude,
|
|
Longitude = dto.longitude,
|
|
MeterZoneGPS = dto.meterZoneGPS,
|
|
Type = dto.type,
|
|
PuzzleMessageDebut = ((PuzzleDTO)dto).messageDebut.Select(md => new TranslationAndResource().FromDTO(md)).ToList(),
|
|
PuzzleMessageFin = ((PuzzleDTO)dto).messageFin.Select(mf => new TranslationAndResource().FromDTO(mf)).ToList(),
|
|
PuzzleImageId = ((PuzzleDTO)dto).puzzleImageId,
|
|
PuzzleRows = ((PuzzleDTO)dto).rows,
|
|
PuzzleCols = ((PuzzleDTO)dto).cols
|
|
},
|
|
SectionType.Quiz => new SectionQuiz
|
|
{
|
|
Id = dto.id,
|
|
Label = dto.label,
|
|
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
|
|
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
|
|
Order = dto.order.Value,
|
|
ImageId = dto.imageId,
|
|
ImageSource = dto.imageSource,
|
|
IsSubSection = dto.isSubSection,
|
|
ParentId = dto.parentId,
|
|
IsBeacon = dto.isBeacon,
|
|
BeaconId = dto.beaconId,
|
|
Latitude = dto.latitude,
|
|
Longitude = dto.longitude,
|
|
MeterZoneGPS = dto.meterZoneGPS,
|
|
Type = dto.type,
|
|
QuizBadLevel = ((QuizDTO)dto).bad_level.Select(bl => new TranslationAndResource().FromDTO(bl)).ToList(),
|
|
QuizMediumLevel = ((QuizDTO)dto).medium_level.Select(ml => new TranslationAndResource().FromDTO(ml)).ToList(),
|
|
QuizGoodLevel = ((QuizDTO)dto).good_level.Select(gol => new TranslationAndResource().FromDTO(gol)).ToList(),
|
|
QuizGreatLevel = ((QuizDTO)dto).great_level.Select(gl => new TranslationAndResource().FromDTO(gl)).ToList(),
|
|
//Questions = ((QuizDTO)dto).questions, // TODO specific
|
|
},
|
|
SectionType.Slider => new SectionSlider
|
|
{
|
|
Id = dto.id,
|
|
Label = dto.label,
|
|
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
|
|
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
|
|
Order = dto.order.Value,
|
|
ImageId = dto.imageId,
|
|
ImageSource = dto.imageSource,
|
|
IsSubSection = dto.isSubSection,
|
|
ParentId = dto.parentId,
|
|
IsBeacon = dto.isBeacon,
|
|
BeaconId = dto.beaconId,
|
|
Latitude = dto.latitude,
|
|
Longitude = dto.longitude,
|
|
MeterZoneGPS = dto.meterZoneGPS,
|
|
Type = dto.type,
|
|
SliderContents = ((SliderDTO)dto).contents.Select(c => new Content().FromDTO(c)).ToList(), // TODO TEST
|
|
},
|
|
SectionType.Video => new SectionVideo
|
|
{
|
|
Id = dto.id,
|
|
Label = dto.label,
|
|
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
|
|
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
|
|
Order = dto.order.Value,
|
|
ImageId = dto.imageId,
|
|
ImageSource = dto.imageSource,
|
|
IsSubSection = dto.isSubSection,
|
|
ParentId = dto.parentId,
|
|
IsBeacon = dto.isBeacon,
|
|
BeaconId = dto.beaconId,
|
|
Latitude = dto.latitude,
|
|
Longitude = dto.longitude,
|
|
MeterZoneGPS = dto.meterZoneGPS,
|
|
Type = dto.type,
|
|
VideoSource = ((VideoDTO)dto).source,
|
|
},
|
|
|
|
SectionType.Weather => new SectionWeather
|
|
{
|
|
Id = dto.id,
|
|
Label = dto.label,
|
|
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
|
|
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
|
|
Order = dto.order.Value,
|
|
ImageId = dto.imageId,
|
|
ImageSource = dto.imageSource,
|
|
IsSubSection = dto.isSubSection,
|
|
ParentId = dto.parentId,
|
|
IsBeacon = dto.isBeacon,
|
|
BeaconId = dto.beaconId,
|
|
Latitude = dto.latitude,
|
|
Longitude = dto.longitude,
|
|
MeterZoneGPS = dto.meterZoneGPS,
|
|
Type = dto.type,
|
|
WeatherCity = ((WeatherDTO)dto).city,
|
|
WeatherUpdatedDate = ((WeatherDTO)dto).updatedDate,
|
|
WeatherResult = ((WeatherDTO)dto).result
|
|
},
|
|
SectionType.Web => new SectionWeb
|
|
{
|
|
Id = dto.id,
|
|
Label = dto.label,
|
|
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
|
|
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
|
|
Order = dto.order.Value,
|
|
ImageId = dto.imageId,
|
|
ImageSource = dto.imageSource,
|
|
IsSubSection = dto.isSubSection,
|
|
ParentId = dto.parentId,
|
|
IsBeacon = dto.isBeacon,
|
|
BeaconId = dto.beaconId,
|
|
Latitude = dto.latitude,
|
|
Longitude = dto.longitude,
|
|
MeterZoneGPS = dto.meterZoneGPS,
|
|
Type = dto.type,
|
|
WebSource = ((WebDTO)dto).source,
|
|
},
|
|
|
|
_ => throw new NotImplementedException("Section type not handled")
|
|
};
|
|
}
|
|
}
|
|
|
|
}
|