Add work plane property saving

This commit is contained in:
Evgeny Redikultsev
2025-01-25 19:21:34 +05:00
parent bbc6ade283
commit 3a946a29bc
37 changed files with 765 additions and 324 deletions

View File

@@ -1,49 +1,32 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using DataAccess.DTOs.Converters;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.WorkPlanes;
using StructureHelperLogics.Models.CrossSections;
namespace DataAccess.DTOs
{
public class CrossSectionToDTOConvertStrategy : IConvertStrategy<CrossSectionDTO, ICrossSection>
public class CrossSectionToDTOConvertStrategy : ConvertStrategy<CrossSectionDTO, ICrossSection>
{
private IUpdateStrategy<ICrossSection> updateStrategy; //don't use since CrossSection does not have any properties
private IConvertStrategy<CrossSectionRepositoryDTO, ICrossSectionRepository> convertRepositoryStrategy;
private DictionaryConvertStrategy<CrossSectionRepositoryDTO, ICrossSectionRepository> convertLogic;
private ICheckConvertLogic<CrossSectionDTO, ICrossSection> checkLogic;
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; }
private IConvertStrategy<WorkPlanePropertyDTO, IWorkPlaneProperty> workPlanePropertyConvertStrategy;
public CrossSectionToDTOConvertStrategy(IUpdateStrategy<ICrossSection> updateStrategy,
IConvertStrategy<CrossSectionRepositoryDTO, ICrossSectionRepository> convertRepositoryStrategy,
ICheckConvertLogic<CrossSectionDTO, ICrossSection> checkLogic)
ICheckConvertLogic<CrossSectionDTO, ICrossSection> checkLogic,
IConvertStrategy<WorkPlanePropertyDTO, IWorkPlaneProperty> workPlanePropertyConvertStrategy)
{
this.updateStrategy = updateStrategy;
this.convertRepositoryStrategy = convertRepositoryStrategy;
this.checkLogic = checkLogic;
this.workPlanePropertyConvertStrategy = workPlanePropertyConvertStrategy;
}
public CrossSectionToDTOConvertStrategy() : this(
new CrossSectionUpdateStrategy(),
new CrossSectionRepositoryToDTOConvertStrategy(),
new CheckConvertLogic<CrossSectionDTO, ICrossSection>())
{
}
public CrossSectionToDTOConvertStrategy() { }
public CrossSectionDTO Convert(ICrossSection source)
{
Check();
CrossSectionDTO newItem = new()
{
Id = source.Id
};
convertRepositoryStrategy.ReferenceDictionary = ReferenceDictionary;
convertRepositoryStrategy.TraceLogger = TraceLogger;
convertLogic = new DictionaryConvertStrategy<CrossSectionRepositoryDTO, ICrossSectionRepository>(this, convertRepositoryStrategy);
newItem.SectionRepository = convertLogic.Convert(source.SectionRepository);
return newItem;
}
private void Check()
{
@@ -51,5 +34,40 @@ namespace DataAccess.DTOs
checkLogic.TraceLogger = TraceLogger;
checkLogic.Check();
}
public override CrossSectionDTO GetNewItem(ICrossSection source)
{
InitializeStrategies();
try
{
GetNewItemBySource(source);
return NewItem;
}
catch (Exception ex)
{
TraceErrorByEntity(this, ex.Message);
throw;
}
}
private void InitializeStrategies()
{
updateStrategy ??= new CrossSectionUpdateStrategy();
convertRepositoryStrategy ??= new CrossSectionRepositoryToDTOConvertStrategy(ReferenceDictionary, TraceLogger);
checkLogic ??= new CheckConvertLogic<CrossSectionDTO, ICrossSection>();
workPlanePropertyConvertStrategy ??= new WorkPlanePropertyToDTOConvertStrategy(ReferenceDictionary, TraceLogger);
}
private void GetNewItemBySource(ICrossSection source)
{
Check();
NewItem = new()
{
Id = source.Id
};
convertLogic = new DictionaryConvertStrategy<CrossSectionRepositoryDTO, ICrossSectionRepository>(this, convertRepositoryStrategy);
NewItem.SectionRepository = convertLogic.Convert(source.SectionRepository);
NewItem.WorkPlaneProperty = workPlanePropertyConvertStrategy.Convert(source.WorkPlaneProperty);
}
}
}