public static void ExpireOverlappingInstances(ICategorizedTemporalList <T> list, T newInstance) { DateTime effectiveDate = newInstance.EffectivePeriod.EffectiveDate; TreeListNode newCat = ((ICategorizedTemporal)newInstance).Category; //Validate foreach (T i in list) { if (i.EffectivePeriod.EffectiveDate > effectiveDate && ((ICategorizedTemporal)i).Category == newCat) { throw new iSabayaException("The effective date of the added instance is less than existing effective date"); } } //Expire the current one foreach (T i in list) { ICategorizedTemporal item = (ICategorizedTemporal)i; if (item.EffectivePeriod.IsEffectiveOn(effectiveDate) && item.Category == newCat) { item.EffectivePeriod.ExpiryDate = effectiveDate; } } }
public static T GetInstance(ICategorizedTemporalList <T> list, DateTime when, TreeListNode category) { foreach (T i in list) { ICategorizedTemporal item = (ICategorizedTemporal)i; if (item.EffectivePeriod.IsEffectiveOn(when) && item.Category == category) { return(i); } } return(default(T)); }
public static IList <T> GetInstances(ICategorizedTemporalList <T> list, DateTime when, TreeListNode parentCategory) { CategorizedTemporalList <T> matches = new CategorizedTemporalList <T>(); foreach (T i in list) { ICategorizedTemporal item = (ICategorizedTemporal)i; if (item.EffectivePeriod.IsEffectiveOn(when) && item.Category.Parent == parentCategory) { matches.Add(i); } } return(matches); }
public static bool ContainsCategoryParent(ICategorizedTemporalList <T> list, DateTime when, TreeListNode parentCategory) { bool exist = false; foreach (T i in list) { ICategorizedTemporal item = (ICategorizedTemporal)i; if (item.EffectivePeriod.IsEffectiveOn(when) && item.Category.Parent == parentCategory) { exist = true; break; } } return(exist); }