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 { /// /// Used by more than one Service... ? Businesslogic schicht? /// 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(Dictionary pOid2Version, ActivationTypeId activationType) where T : BeWoEntityBase, new() { var lOriginals = DAOFactory.GenericDAO.LoadByIDs(pOid2Version.Select(e => e.Key)).Where(e => e.SystemEntryID == null).ToList(); pOid2Version.Keys.DoForEach(SettingsLogic.RemoveFromAllHistories); lOriginals.DoForEach(or => ConcurrencyCheck(pOid2Version[or.Oid.Value], or)); lOriginals.DoForEach(or => or.IsActive = activationType); DAOFactory.GenericDAO.Update(lOriginals); } public static void SetActivationType(long pOid, long pVersion, ActivationTypeId activationType) where T : BeWoEntityBase, new() { SetActivationType( new Dictionary { { pOid, pVersion } }, activationType); } } }