Add sectionIds to ConfigurationDTO
This commit is contained in:
parent
a0b2d5ba9c
commit
74101d9939
@ -21,5 +21,6 @@ namespace Manager.Interfaces.DTO
|
||||
/*public string latitude { get; set; } // MyVisit - latitude of visit ? (MyVisit)
|
||||
public string longitude { get; set; } // MyVisit - True if for mobile (MyVisit)*/
|
||||
public string instanceId { get; set; }
|
||||
public List<string> sectionIds { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Manager.Interfaces.Models
|
||||
@ -54,7 +55,7 @@ namespace Manager.Interfaces.Models
|
||||
[BsonRequired]
|
||||
public string InstanceId { get; set; }
|
||||
|
||||
public ConfigurationDTO ToDTO()
|
||||
public ConfigurationDTO ToDTO(List<string> sectionIds)
|
||||
{
|
||||
return new ConfigurationDTO()
|
||||
{
|
||||
@ -71,6 +72,7 @@ namespace Manager.Interfaces.Models
|
||||
isTablet = IsTablet,
|
||||
isOffline = IsOffline,
|
||||
instanceId = InstanceId,
|
||||
sectionIds = sectionIds
|
||||
};
|
||||
}
|
||||
|
||||
@ -92,6 +94,7 @@ namespace Manager.Interfaces.Models
|
||||
sections = sections,
|
||||
resources = resources,
|
||||
instanceId = InstanceId,
|
||||
sectionIds = sections.Select(s => s.id).ToList()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,7 +56,16 @@ namespace ManagerService.Controllers
|
||||
{
|
||||
List<Configuration> configurations = _configurationService.GetAll(instanceId);
|
||||
|
||||
return new OkObjectResult(configurations.Select(r => r.ToDTO()));
|
||||
List<ConfigurationDTO> configurationDTOs = new List<ConfigurationDTO>();
|
||||
|
||||
foreach(var configuration in configurations)
|
||||
{
|
||||
List<string> sectionIds = _sectionService.GetAllIdsFromConfiguration(configuration.Id);
|
||||
ConfigurationDTO configurationDTO = configuration.ToDTO(sectionIds);
|
||||
configurationDTOs.Add(configurationDTO);
|
||||
}
|
||||
|
||||
return new OkObjectResult(configurationDTOs);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -83,7 +92,9 @@ namespace ManagerService.Controllers
|
||||
if (configuration == null)
|
||||
throw new KeyNotFoundException("This configuration was not found");
|
||||
|
||||
return new OkObjectResult(configuration.ToDTO());
|
||||
List<string> sectionIds = _sectionService.GetAllIdsFromConfiguration(id);
|
||||
|
||||
return new OkObjectResult(configuration.ToDTO(sectionIds));
|
||||
}
|
||||
catch (KeyNotFoundException ex)
|
||||
{
|
||||
@ -133,7 +144,7 @@ namespace ManagerService.Controllers
|
||||
|
||||
Configuration configurationCreated = _configurationService.Create(configuration);
|
||||
|
||||
return new OkObjectResult(configurationCreated.ToDTO());
|
||||
return new OkObjectResult(configurationCreated.ToDTO(new List<string>())); // Empty list
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
@ -188,7 +199,9 @@ namespace ManagerService.Controllers
|
||||
|
||||
// TODO HANDLE MqttClientService.PublishMessage($"config/{configurationModified.Id}", JsonConvert.SerializeObject(new PlayerMessageDTO() { configChanged = true }));
|
||||
|
||||
return new OkObjectResult(configurationModified.ToDTO());
|
||||
List<string> sectionIds = _sectionService.GetAllIdsFromConfiguration(configuration.Id);
|
||||
|
||||
return new OkObjectResult(configurationModified.ToDTO(sectionIds));
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
|
||||
@ -29,6 +29,11 @@ namespace Manager.Services
|
||||
return _Sections.Find(s => !s.IsSubSection && s.ConfigurationId == configurationId).ToList();
|
||||
}
|
||||
|
||||
public List<string> GetAllIdsFromConfiguration(string configurationId)
|
||||
{
|
||||
return _Sections.Find(s => !s.IsSubSection && s.ConfigurationId == configurationId).ToList().Select(s => s.Id).ToList();
|
||||
}
|
||||
|
||||
public List<Section> GetAllSubSection(string parentId)
|
||||
{
|
||||
return _Sections.Find(s => s.IsSubSection && s.ParentId == parentId).ToList();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user