76 lines
2.6 KiB
C#
76 lines
2.6 KiB
C#
|
|
using BeWo.Data.Access;
|
|||
|
|
using BeWo.Data.Entities;
|
|||
|
|
using BeWo.Service.DCEntityMapper;
|
|||
|
|
using BS.Shared.DataContracts.Compact;
|
|||
|
|
using BS.Shared.DataContracts;
|
|||
|
|
using BS.Shared;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
using BeWo.Service.Core;
|
|||
|
|
|
|||
|
|
namespace BeWo.Service.ServiceUtils
|
|||
|
|
{
|
|||
|
|
public static class DataContractLoader
|
|||
|
|
{
|
|||
|
|
//public static CompactCustomerDC LoadCompactCustomerDC(BeWoRefDC beWoRef)
|
|||
|
|
// => LoadDataContact<CompactCustomerDC_Customer, Customer, CompactCustomerDC>(MapperFactory.CompactCustomerDC_Customer, beWoRef);
|
|||
|
|
public static CompactSupportConceptDC LoadSupportConceptDC(BeWoRefDC beWoRef)
|
|||
|
|
=> LoadDataContact<CompactSupportConceptDC_SupportConcept, SupportConcept, CompactSupportConceptDC>(MapperFactory.CompactSupportConceptDC_SupportConcept, beWoRef);
|
|||
|
|
public static IEnumerable<ServiceRecordDC> LoadServiceRecordDCs(IEnumerable<BeWoRefDC> beWoRefs)
|
|||
|
|
=> LoadDataContacts<ServiceRecordDC_ServiceRecord, ServiceRecord, ServiceRecordDC>(MapperFactory.ServiceRecordDC_ServiceRecord, beWoRefs);
|
|||
|
|
|
|||
|
|
private static IEnumerable<TDC> LoadDataContacts<TMapper, TEntity, TDC>(TMapper mapper, IEnumerable<BeWoRefDC> beWoRefs, bool checkVersion = true)
|
|||
|
|
where TMapper : AbstractIDCEntityMapper<TEntity, TDC>
|
|||
|
|
where TEntity : BeWoEntityBase, new()
|
|||
|
|
where TDC : class, new()
|
|||
|
|
{
|
|||
|
|
var entities = LoadEntitiesByRef<TEntity>(beWoRefs, checkVersion);
|
|||
|
|
var dcs = mapper.MapToNewDCs(entities);
|
|||
|
|
|
|||
|
|
return dcs;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private static TDC LoadDataContact<TMapper, TEntity, TDC>(TMapper mapper, BeWoRefDC beWoRef, bool checkVersion = true)
|
|||
|
|
where TMapper : AbstractIDCEntityMapper<TEntity, TDC>
|
|||
|
|
where TEntity : BeWoEntityBase, new()
|
|||
|
|
where TDC : class, new()
|
|||
|
|
{
|
|||
|
|
var entity = LoadEntityByRef<TEntity>(beWoRef, checkVersion);
|
|||
|
|
var dc = mapper.MapToNewDC(entity);
|
|||
|
|
|
|||
|
|
return dc;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private static IEnumerable<TEntity> LoadEntitiesByRef<TEntity>(IEnumerable<BeWoRefDC> beWoRefs, bool checkVersion = true)
|
|||
|
|
where TEntity : BeWoEntityBase, new()
|
|||
|
|
{
|
|||
|
|
var tid = GetTableID<TEntity>();
|
|||
|
|
var entities = beWoRefs.Select(x => LoadEntityByRef<TEntity>(x, checkVersion));
|
|||
|
|
|
|||
|
|
return entities;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private static TEntity LoadEntityByRef<TEntity>(BeWoRefDC beWoRef, bool checkVersion = true)
|
|||
|
|
where TEntity : BeWoEntityBase, new()
|
|||
|
|
{
|
|||
|
|
var tid = GetTableID<TEntity>();
|
|||
|
|
var oid = beWoRef.Oid;
|
|||
|
|
var entity = DAOFactory.GenericDAO.LoadByID<TEntity>(oid);
|
|||
|
|
|
|||
|
|
if (checkVersion)
|
|||
|
|
ServiceLogic.ConcurrencyCheck(beWoRef.Version, entity);
|
|||
|
|
|
|||
|
|
return entity;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private static TableID GetTableID<TEntity>()
|
|||
|
|
where TEntity : BeWoEntityBase, new()
|
|||
|
|
{
|
|||
|
|
return new TEntity().Tid;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|