56 lines
1.5 KiB
C#
56 lines
1.5 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
|
|
using BS.Shared;
|
|
using BS.Shared.Extensions;
|
|
|
|
using NHibernate;
|
|
|
|
namespace BeWo.Service.Core
|
|
{
|
|
/// <summary>
|
|
/// Used by more than one Service... ? Businesslogic schicht?
|
|
/// </summary>
|
|
public static class ServiceLogic
|
|
{
|
|
public static bool ConcurrencyCheck(long? pDataContractVersion, BeWoEntityBase pEntity)
|
|
{
|
|
if (pDataContractVersion != null && pDataContractVersion != pEntity.Version)
|
|
{
|
|
throw new StaleObjectStateException(pEntity.GetType().ToString(), pEntity.Oid);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
public static void SetActivationType<T>(Dictionary<long, long> pOid2Version, ActivationTypeId activationType)
|
|
where T : BeWoEntityBase, new()
|
|
{
|
|
var lOriginals = DAOFactory.GenericDAO.LoadByIDs<T>(pOid2Version.Select(e => e.Key)).Where(e => e.SystemEntryID == null).ToList();
|
|
|
|
pOid2Version.Keys.DoForEach(SettingsLogic.RemoveFromAllHistories<T>);
|
|
|
|
lOriginals.DoForEach(or => ConcurrencyCheck(pOid2Version[or.Oid.Value], or));
|
|
lOriginals.DoForEach(or => or.IsActive = activationType);
|
|
|
|
DAOFactory.GenericDAO.Update(lOriginals);
|
|
}
|
|
|
|
public static void SetActivationType<T>(long pOid, long pVersion, ActivationTypeId activationType)
|
|
where T : BeWoEntityBase, new()
|
|
{
|
|
SetActivationType<T>(
|
|
new Dictionary<long, long>
|
|
{
|
|
{
|
|
pOid, pVersion
|
|
}
|
|
},
|
|
activationType);
|
|
}
|
|
}
|
|
} |