private void CreateOrUpdateOpenAttributeDefect(Lot lot, AttributeName attribute, double value, IAttributeRange range, ref List <LotAttributeDefect> lotAttributeDefects) { var nameKey = attribute.ToAttributeNameKey(); var attributeDefect = lotAttributeDefects.FirstOrDefault(d => d.LotDefect.Resolution == null && nameKey.Equals(d)); if (attributeDefect == null) { var newDefect = lot.AddNewDefect(attribute.DefectType, attribute.Name); attributeDefect = new LotAttributeDefect { LotDateCreated = lot.LotDateCreated, LotDateSequence = lot.LotDateSequence, LotTypeId = lot.LotTypeId, DefectId = newDefect.DefectId, LotDefect = newDefect, AttributeShortName = nameKey.AttributeNameKey_ShortName }; lotAttributeDefects.Add(attributeDefect); } attributeDefect.OriginalAttributeValue = value; attributeDefect.OriginalAttributeMinLimit = range.RangeMin; attributeDefect.OriginalAttributeMaxLimit = range.RangeMax; CloseOpenAttributeDefects(nameKey, lotAttributeDefects.Where(a => a != attributeDefect)); }