2016-06-27 01:45:38 +02:00
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.ServiceModel ;
using BeWo.Data.Access ;
using BeWo.Data.Entities ;
using BeWo.Service.Core ;
using BeWo.Service.DCEntityMapper ;
using BeWo.Service.ServiceContracts ;
using BS.Shared ;
using BS.Shared.DataContracts ;
using BS.Shared.Extensions ;
namespace BeWo.Service.ServiceImplementations
{
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single)]
public class ValueListServiceImp : IValueListService
{
public void DeactivateValueListEntries ( Dictionary < long , long > pOid2Version )
{
try
{
ServiceLogic . SetActivationType < ValueListEntry > ( pOid2Version , ActivationTypeId . Deleted ) ;
}
catch ( Exception e )
{
throw Utils . CreateBeWoFaultException ( e ) ;
}
}
public void DeactivateValueListEntry ( long pOid , long pVersion )
{
try
{
ServiceLogic . SetActivationType < ValueListEntry > ( new Dictionary < long , long > { { pOid , pVersion } } , ActivationTypeId . Deleted ) ;
}
catch ( Exception e )
{
throw Utils . CreateBeWoFaultException ( e ) ;
}
throw new NotImplementedException ( ) ;
}
public void DeleteValueListEntries ( Dictionary < long , long > pOid2Version )
{
try
{
var lOriginals = DAOFactory . GenericDAO . LoadByIDs < ValueListEntry > ( pOid2Version . Select ( e = > e . Key ) ) ;
lOriginals . DoForEach ( or = > MapperFactory . ValueListEntryDC_ValueListEntry . ConcurrencyCheck ( pOid2Version [ or . Oid . Value ] , or ) ) ;
DAOFactory . GenericDAO . Delete ( lOriginals ) ;
}
catch ( Exception e )
{
throw Utils . CreateBeWoFaultException ( e ) ;
}
}
public void DeleteValueListEntry ( long pOid , long pVersion )
{
try
{
this . DeleteValueListEntries ( new Dictionary < long , long > { { pOid , pVersion } } ) ;
}
catch ( Exception e )
{
throw Utils . CreateBeWoFaultException ( e ) ;
}
}
public ValueListEntryDC [ ] GetAllValueListEntrysByType ( ValueListEntryType pType )
{
try
{
2019-10-10 22:07:42 +02:00
var list = MapperFactory . ValueListEntryDC_ValueListEntry . MapToNewDCs ( DAOFactory . SearchDAO . FindValueListEntry ( pType ) . Where ( ve = > ve . IsActive = = ActivationTypeId . Active ) ) . ToArray ( ) ;
return list . OrderBy ( ve = > String . Format ( "{0}-{1}" , ve . Abbreviation , ve . TypeDescription ) ) . ToArray ( ) ;
2016-06-27 01:45:38 +02:00
}
catch ( Exception e )
{
throw Utils . CreateBeWoFaultException ( e ) ;
}
}
public ValueListEntryDC [ ] GetAllValueListEntrysByTypes ( List < ValueListEntryType > pTypes )
{
try
{
2025-04-15 00:51:19 +02:00
if ( pTypes ! = null & & pTypes . Count = = 2 & & pTypes [ 0 ] = = ValueListEntryType . SupportConceptGoalType & & pTypes [ 1 ] = = ValueListEntryType . SupportConceptGoalCategoryType )
{
//FixFalscheZiele();
}
2019-10-10 22:07:42 +02:00
var list = MapperFactory . ValueListEntryDC_ValueListEntry . MapToNewDCs ( DAOFactory . SearchDAO . FindValueListEntries ( pTypes ) . Where ( ve = > ve . IsActive = = ActivationTypeId . Active ) ) . ToArray ( ) ;
return list . OrderBy ( ve = > String . Format ( "{0}-{1}" , ve . Abbreviation , ve . TypeDescription ) ) . ToArray ( ) ;
}
2016-06-27 01:45:38 +02:00
catch ( Exception e )
{
throw Utils . CreateBeWoFaultException ( e ) ;
}
}
2025-04-15 00:51:19 +02:00
private void FixFalscheZiele ( )
{
if ( "9417634361" . Equals ( Plugins . PluginLoader . Tenant ) )
{
var entries = DAOFactory . SearchDAO . FindValueListEntries ( new [ ]
{
ValueListEntryType . SupportConceptGoalCategoryType ,
ValueListEntryType . SupportConceptIndividualGoalCategoryType
} . ToList ( ) ) . Where ( ve = > ve . IsActive = = ActivationTypeId . Active ) . ToList ( ) ; ;
var gemeinschaft = entries . Where ( e = > e . Oid = = 566 ) . FirstOrDefault ( ) ;
var lebensbereich = entries . Where ( e = > e . Oid = = 567 ) . FirstOrDefault ( ) ;
var interaktion = entries . Where ( e = > e . Oid = = 568 ) . FirstOrDefault ( ) ;
var hausleben = entries . Where ( e = > e . Oid = = 569 ) . FirstOrDefault ( ) ;
var selbst = entries . Where ( e = > e . Oid = = 570 ) . FirstOrDefault ( ) ;
var mobil = entries . Where ( e = > e . Oid = = 571 ) . FirstOrDefault ( ) ;
var kommunikation = entries . Where ( e = > e . Oid = = 572 ) . FirstOrDefault ( ) ;
var aufgaben = entries . Where ( e = > e . Oid = = 573 ) . FirstOrDefault ( ) ;
var lernen = entries . Where ( e = > e . Oid = = 574 ) . FirstOrDefault ( ) ;
foreach ( var item in entries )
{
if ( item . Type = = ValueListEntryType . SupportConceptGoalCategoryType )
{
if ( "eutende Lebensbereiche" . Equals ( item . Value ) )
{
MergeSubZieleUndMassnahmen ( lebensbereich , item , entries ) ;
}
else if ( "erpersonelle Interaktionen und Beziehungen" . Equals ( item . Value ) )
{
MergeSubZieleUndMassnahmen ( interaktion , item , entries ) ;
}
else if ( "bilität" . Equals ( item . Value ) | | "ilität" . Equals ( item . Value ) )
{
MergeSubZieleUndMassnahmen ( mobil , item , entries ) ;
}
else if ( "bstversorgung" . Equals ( item . Value ) | | "lbstversorgung" . Equals ( item . Value ) )
{
MergeSubZieleUndMassnahmen ( selbst , item , entries ) ;
}
else if ( "einschafts-, soziales und staatsbürgerliches Leben" . Equals ( item . Value ) | | "Gemeinschafts-, soziales und staatsbürgerliches Leben" . Equals ( item . Value ) )
{
MergeSubZieleUndMassnahmen ( gemeinschaft , item , entries ) ;
}
else if ( "lgemeine Aufgaben u. Anforderungen" . Equals ( item . Value ) | | "Allgemeine Aufgaben u. Anforderungen" . Equals ( item . Value ) )
{
MergeSubZieleUndMassnahmen ( aufgaben , item , entries ) ;
}
else if ( "munikation" . Equals ( item . Value ) )
{
MergeSubZieleUndMassnahmen ( kommunikation , item , entries ) ;
}
else if ( "sliches Leben" . Equals ( item . Value ) )
{
MergeSubZieleUndMassnahmen ( hausleben , item , entries ) ;
}
else if ( "rnen und Wissensanwendung" . Equals ( item . Value ) )
{
MergeSubZieleUndMassnahmen ( lernen , item , entries ) ;
}
}
//if (item.)
}
}
}
private void MergeSubZieleUndMassnahmen ( ValueListEntry lebensbereich , ValueListEntry item2Merge , IList < ValueListEntry > alleEntries )
{
foreach ( var item in alleEntries )
{
if ( item . ParentOid . HasValue & & item . ParentOid = = item2Merge . Oid )
{
item . ParentOid = lebensbereich . Oid ;
DAOFactory . GenericDAO . Update ( item ) ;
}
}
foreach ( var v2o in item2Merge . ValueListEntry2Objects )
{
var sql = String . Format ( "update valuelistentry2object set valuelistentryoid = {0} where oid = {1}" , lebensbereich . Oid , v2o . Oid ) ;
var result = DAOFactory . SearchDAO . GetSqlResult ( sql ) ;
//
//update customer set debitornumber = '5' + debitornumber where debitornumber is not null
}
item2Merge . IsActive = ActivationTypeId . Deleted ;
DAOFactory . GenericDAO . Update ( item2Merge ) ;
}
public ValueListEntryDC GetValueListEntryByOid ( long pOid )
2016-06-27 01:45:38 +02:00
{
try
{
return MapperFactory . ValueListEntryDC_ValueListEntry . MapToNewDC ( DAOFactory . GenericDAO . LoadByID < ValueListEntry > ( pOid ) ) ;
}
catch ( Exception e )
{
throw Utils . CreateBeWoFaultException ( e ) ;
}
}
public List < long > InsertNewValueListEntries ( List < ValueListEntryDC > pEntries )
{
try
{
var lEntities = MapperFactory . ValueListEntryDC_ValueListEntry . MapToNewEntities ( pEntries ) ;
DAOFactory . GenericDAO . Insert ( lEntities ) ;
return lEntities . Select ( e = > e . Oid . Value ) . ToList ( ) ;
}
catch ( Exception e )
{
throw Utils . CreateBeWoFaultException ( e ) ;
}
}
public List < ValueListEntryDC > InsertAndLoadNewValueListEntries ( IEnumerable < ValueListEntryDC > pEntries )
{
try
{
var lEntities = MapperFactory . ValueListEntryDC_ValueListEntry . MapToNewEntities ( pEntries ) ;
DAOFactory . GenericDAO . Insert ( lEntities ) ;
return MapperFactory . ValueListEntryDC_ValueListEntry . MapToNewDCs ( lEntities ) ;
}
catch ( Exception e )
{
throw Utils . CreateBeWoFaultException ( e ) ;
}
}
public ValueListEntryDC InsertNewValueListEntry ( ValueListEntryDC pEntry )
{
try
{
var lEntity = MapperFactory . ValueListEntryDC_ValueListEntry . MapToNewEntity ( pEntry ) ;
2021-11-16 17:00:05 +01:00
DAOFactory . GenericDAO . Insert ( lEntity ) ; // Hier Fehler bei Komponente E
2016-06-27 01:45:38 +02:00
return MapperFactory . ValueListEntryDC_ValueListEntry . MapToNewDC ( lEntity ) ;
}
catch ( Exception e )
{
throw Utils . CreateBeWoFaultException ( e ) ;
}
}
public void UpdateValueListEntries ( List < ValueListEntryDC > pEntries )
{
try
{
var lOriginals = DAOFactory . GenericDAO . LoadByIDs < ValueListEntry > ( pEntries . Select ( en = > en . ValueListEntryOid . Value ) ) ;
MapperFactory . ValueListEntryDC_ValueListEntry . MergeWithEntitys ( pEntries , lOriginals ) ;
DAOFactory . GenericDAO . Update ( lOriginals ) ;
}
catch ( Exception e )
{
throw Utils . CreateBeWoFaultException ( e ) ;
}
}
public ValueListEntryDC [ ] GetAllValueListEntriesByOidForType ( long pOid )
{
var original = DAOFactory . GenericDAO . GetByID < ValueListEntry > ( pOid ) ;
return GetAllValueListEntrysByType ( original . Type ) ;
}
2024-06-05 14:45:33 +02:00
public List < ValueListEntryDC > GetValueListEntriesByOids ( IEnumerable < long > oids )
{
try
{
var entities = DAOFactory . GenericDAO . LoadByIDs < ValueListEntry > ( oids ) ;
return MapperFactory . ValueListEntryDC_ValueListEntry . MapToNewDCs ( entities ) ;
}
catch ( Exception e )
{
throw Utils . CreateBeWoFaultException ( e ) ;
}
}
public List < ValueListEntryDC > GetGoalCategoriesByOids ( List < long > oids )
{
try
{
var entities = DAOFactory . SearchDAO . GetGoalCategoriesByOids ( oids ) ;
return MapperFactory . ValueListEntryDC_ValueListEntry . MapToNewDCs ( entities ) ;
}
catch ( Exception e )
{
throw Utils . CreateBeWoFaultException ( e ) ;
}
}
2016-06-27 01:45:38 +02:00
}
}