private void ReconcileInHouseContaminationDefects(LotDTO oldLot, Lot newLot)
            {
                string description = null;

                switch (oldLot.LotStat)
                {
                case LotStat.See_Desc:
                    description = string.IsNullOrEmpty(oldLot.Notes) ? "Reason Unspecified" : oldLot.Notes;
                    break;

                case LotStat.Dark_Specs:
                case LotStat.Smoke_Cont:
                case LotStat.Hard_BBs:
                case LotStat.Soft_BBs:
                    description = _lotStatusDescriptions[oldLot.LotStat.Value];
                    break;
                }

                if (description != null)
                {
                    LotMother.AddRead(EntityTypes.LotDefect);
                    if (!newLot.LotDefects.Any(d => d.DefectType == DefectTypeEnum.InHouseContamination && d.Resolution == null && d.Description == description))
                    {
                        newLot.AddNewDefect(DefectTypeEnum.InHouseContamination, description);
                    }
                }
            }
 private void AddInHouseContaminationDefect(LotDTO oldLot, Lot newLot)
 {
     if (oldLot.LotStat.IsInHouseContamination())
     {
         LotMother.AddRead(EntityTypes.LotDefect);
         newLot.AddNewDefect(DefectTypeEnum.InHouseContamination, _lotStatusDescriptions[oldLot.LotStat.Value]);
     }
 }
            private void AddNewLotAttribute(ILotAttributes oldAttributes, Lot newLot, ChileProductAttributeRange range, AttributeName attributeName, AttributeCommonData attributeData, double value, ref List <LotAttributeDefect> lotAttributeDefects)
            {
                var attribute = newLot.AddNewAttribute(oldAttributes, attributeName, attributeData, LotMother);

                if (attribute == null)
                {
                    return;
                }

                if (range.ValueOutOfRange(attribute.AttributeValue))
                {
                    LotMother.AddRead(EntityTypes.LotDefect);
                    LotMother.AddRead(EntityTypes.LotAttributeDefect);

                    CreateOrUpdateOpenAttributeDefect(newLot, attributeName, value, range, ref lotAttributeDefects);
                }
                else
                {
                    CloseOpenAttributeDefects(attribute, lotAttributeDefects);
                }
            }
            private void AddLotAttributeDefects(Lot newLot, ChileProduct chileProduct, DefectTypeEnum defectType, ref List <LotAttributeDefect> lotAttributeDefects)
            {
                var defectAttributes  = LotMother.AttributeNames.Values.Where(a => a.DefectType == defectType);
                var chileProductSpecs = chileProduct.ProductAttributeRanges.Join(defectAttributes,
                                                                                 r => r.AttributeShortName,
                                                                                 a => a.ShortName,
                                                                                 (r, a) => new { Range = r, Attribute = a }).ToList();

                foreach (var productSpec in chileProductSpecs)
                {
                    var attributeRange = productSpec.Range;
                    var attribute      = productSpec.Attribute;
                    var lotAttribute   = newLot.Attributes.FirstOrDefault(a => a.AttributeShortName == attributeRange.AttributeShortName);
                    if (lotAttribute != null)
                    {
                        if (attributeRange.ValueOutOfRange(lotAttribute.AttributeValue))
                        {
                            LotMother.AddRead(EntityTypes.LotDefect);
                            LotMother.AddRead(EntityTypes.LotAttributeDefect);

                            var lotDefect = newLot.AddNewDefect(defectType, attribute.Name);

                            var lotAttributeDefect = new LotAttributeDefect
                            {
                                LotDateCreated            = lotDefect.LotDateCreated,
                                LotDateSequence           = lotDefect.LotDateSequence,
                                LotTypeId                 = lotDefect.LotTypeId,
                                DefectId                  = lotDefect.DefectId,
                                AttributeShortName        = attribute.ShortName,
                                LotDefect                 = lotDefect,
                                OriginalAttributeValue    = lotAttribute.AttributeValue,
                                OriginalAttributeMinLimit = attributeRange.RangeMin,
                                OriginalAttributeMaxLimit = attributeRange.RangeMax
                            };

                            lotAttributeDefects.Add(lotAttributeDefect);
                        }
                    }
                }
            }