private void ReconcileLotAttributesAndDefects(LotDTO oldLot, Lot newLot, ChileProduct chileProduct, AttributeCommonData attributeData, ref List <LotAttributeDefect> lotAttributeDefects)
            {
                foreach (var name in StaticAttributeNames.AttributeNames)
                {
                    var getValue = oldLot.AttributeGet(name);
                    if (getValue == null)
                    {
                        continue;
                    }
                    var oldContextValue = getValue();

                    var nameKey = new AttributeNameKey(name);
                    var productAttributeRange = chileProduct.ProductAttributeRanges.FirstOrDefault(r => nameKey.Equals(r));
                    var newContextAttribute   = newLot.Attributes.FirstOrDefault(a => nameKey.Equals(a));

                    if (newContextAttribute == null)
                    {
                        if (oldContextValue != null)
                        {
                            AddNewLotAttribute(oldLot, newLot, productAttributeRange, name, attributeData, (double)oldContextValue, ref lotAttributeDefects);
                        }
                    }
                    else
                    {
                        if (oldContextValue != null)
                        {
                            UpdateExistingLotAttribute(newContextAttribute, name, attributeData, productAttributeRange, (double)oldContextValue, ref lotAttributeDefects);
                        }
                        else
                        {
                            RemoveExistingLotAttribute(newContextAttribute, ref lotAttributeDefects);
                        }
                    }
                }
            }
            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);
                    }
                }
            }
 public ChileLot CreateSerializedChileLot(LotDTO oldLot, Lot newLot, ChileProduct chileProduct, IEnumerable <AttributeName> attributeNames, ref List <LotAttributeDefect> lotAttributeDefects)
 {
     UpdateAttributeDefectTypes(lotAttributeDefects);
     ReconcileLotAttributesAndDefects(oldLot, newLot, chileProduct, new AttributeCommonData(oldLot, LotMother), ref lotAttributeDefects);
     ReconcileInHouseContaminationDefects(oldLot, newLot);
     return(CreateChileLot(oldLot, newLot, chileProduct, attributeNames, ref lotAttributeDefects));
 }
 private void AddInHouseContaminationDefect(LotDTO oldLot, Lot newLot)
 {
     if (oldLot.LotStat.IsInHouseContamination())
     {
         LotMother.AddRead(EntityTypes.LotDefect);
         newLot.AddNewDefect(DefectTypeEnum.InHouseContamination, _lotStatusDescriptions[oldLot.LotStat.Value]);
     }
 }
        public ChileLot CreateChileLot(LotDTO oldLot, Lot newLot, SerializableLot deserialized, ChileProduct chileProduct, IEnumerable <AttributeName> attributeNames, out List <LotAttributeDefect> lotAttributeDefects)
        {
            if (SerializableLot.UpdateLot(newLot, deserialized, oldLot.TestDate != null, out lotAttributeDefects))
            {
                return(_serializedChileLotHelper.CreateSerializedChileLot(oldLot, newLot, chileProduct, attributeNames, ref lotAttributeDefects));
            }

            return(_unserializedChileLotHelper.CreateUnserializedChileLot(oldLot, newLot, chileProduct, attributeNames, out lotAttributeDefects));
        }
            private ChileLot CreateChileLotAndDefects(LotDTO oldLot, Lot newLot, ChileProduct chileProduct, IEnumerable <AttributeName> attributeNames, out List <LotAttributeDefect> lotAttributeDefects)
            {
                lotAttributeDefects = new List <LotAttributeDefect>();
                AddLotAttributeDefects(newLot, chileProduct, DefectTypeEnum.ProductSpec, ref lotAttributeDefects);
                AddLotAttributeDefects(newLot, chileProduct, DefectTypeEnum.ActionableDefect, ref lotAttributeDefects);
                AddLotAttributeDefects(newLot, chileProduct, DefectTypeEnum.BacterialContamination, ref lotAttributeDefects);
                AddInHouseContaminationDefect(oldLot, newLot);

                return(CreateChileLot(oldLot, newLot, chileProduct, attributeNames, ref lotAttributeDefects));
            }
            protected ChileLot CreateChileLot(LotDTO oldLot, Lot newLot, ChileProduct chileProduct, IEnumerable <AttributeName> attributeNames, ref List <LotAttributeDefect> attributeDefects)
            {
                var newChileLot = new ChileLot
                {
                    LotDateCreated  = newLot.LotDateCreated,
                    LotDateSequence = newLot.LotDateSequence,
                    LotTypeId       = newLot.LotTypeId,
                    Lot             = newLot,

                    ChileProductId = chileProduct.Id,
                    ChileProduct   = chileProduct,
                };

                return(SetLotStatuses(oldLot, newChileLot, attributeNames, ref attributeDefects) ? newChileLot : null);
            }
            public ChileLot CreateUnserializedChileLot(LotDTO oldLot, Lot newLot, ChileProduct chileProduct, IEnumerable <AttributeName> attributeNames, out List <LotAttributeDefect> lotAttributeDefects)
            {
                var attributeCommonData = new AttributeCommonData(oldLot, LotMother);

                newLot.Attributes = new List <LotAttribute>();
                foreach (var attribute in StaticAttributeNames.AttributeNames)
                {
                    var newAttribute = newLot.AddNewAttribute(oldLot, attribute, attributeCommonData, LotMother);
                    if (newAttribute != null)
                    {
                        var wrapper = new ILotAttributesExtensions.LotAttributeWrapper(oldLot, oldLot.OriginalHistory, attribute);
                        newAttribute.Computed = wrapper.Computed;
                    }
                }

                return(CreateChileLotAndDefects(oldLot, newLot, chileProduct, attributeNames, out lotAttributeDefects));
            }
            public AttributeCommonData(LotDTO oldLot, ILotMother lotMother)
            {
                var testerId           = oldLot.TesterID == null ? lotMother.DefaultEmployee.EmployeeId : oldLot.TesterID.Value;
                var determinedTestDate = (oldLot.TestDate ?? oldLot.ProductionDate ?? oldLot.EntryDate ?? Models.Helpers.DataConstants.SqlMinDate).Date;
                var entryDate          = oldLot.EntryDate.ConvertLocalToUTC();

                _oldLot    = oldLot;
                _logMethod = lotMother.Log;

                _testerId           = testerId;
                _determinedTestDate = determinedTestDate;
                _entryDate          = entryDate;

                _defaultTester   = oldLot.TesterID == null;
                _defaultTestDate = determinedTestDate == Models.Helpers.DataConstants.SqlMinDate;
                _nullEntryDate   = oldLot.EntryDate == null;
                NullTestDate     = oldLot.TestDate == null;
            }
            private bool SetLotStatuses(LotDTO oldLot, ChileLot newChileLot, IEnumerable <AttributeName> attributeNames, ref List <LotAttributeDefect> attributeDefects)
            {
                newChileLot.AllAttributesAreLoBac = LotStatusHelper.DetermineChileLotIsLoBac(newChileLot, attributeNames);
                newChileLot.Lot.ProductionStatus  = oldLot._BatchStatID < 3 ? LotProductionStatus.Batched : LotProductionStatus.Produced;
                LotMother.SetLotHoldStatus(oldLot.LotStat, newChileLot.Lot);
                newChileLot.Lot.ProductSpecComplete   = LotStatusHelper.ChileLotAllProductSpecsEntered(newChileLot);
                newChileLot.Lot.ProductSpecOutOfRange = LotStatusHelper.ChileLotAttributeOutOfRange(newChileLot);

                if (!SetLotQualityStatus(oldLot.LotStat, newChileLot.Lot, ref attributeDefects))
                {
                    LotMother.Log(new CallbackParameters(oldLot, CallbackReason.ChileLotStatusConflict)
                    {
                        ChileLot = newChileLot
                    });
                    return(false);
                }

                return(true);
            }