public override IEnumerable <InventoryItem> Validate(IEnumerable <InventoryItem> inventoryItems) { ValidItemClasses = GetValidClassifications().Select(y => y.ItemClassID); // 06/05/19 AT: Added .ToList() call in order to prevent these validations being deferred // thus calling these validation rules twice. var validList = inventoryItems.Where(x => ValidItemClasses.Contains(x.ItemClassID) && IsGroupChildrenValid(x)).ToList(); if (validList.Count == 0) { return(validList); } else { return(base.Validate(validList)); } }
/// <summary> /// Check whether all Grouped item's children are having item classes, which are mapped to the any Classification /// </summary> /// <param name="itemClasses"></param> /// <param name="product"></param> /// <returns></returns> private bool IsGroupChildrenValid(InventoryItem product) { IEnumerable <KNSIGroupedItems> childItems = Graph.GroupedItemChilds.Select(product.InventoryID).RowCast <KNSIGroupedItems>(); return(!childItems.Any() || childItems.All(x => ValidItemClasses.Contains(x.ItemClass))); }