Exemple #1
0
        public tblProduct GetProduct(ChileProduct chileProduct)
        {
            tblProduct product;

            Products.TryGetValue(chileProduct.Product.ProductCode, out product);
            return(product);
        }
        public void SyncIngredients(ChileProduct chileProduct, tblProduct oldProduct, List <AdditiveTypeKey> deletedIngredients)
        {
            var entryDate = DateTime.Now.RoundMillisecondsForSQL();

            foreach (var ingredient in chileProduct.Ingredients)
            {
                var oldIngredient = oldProduct.tblProductIngrs.FirstOrDefault(i => i.IngrID == ingredient.AdditiveTypeId);
                if (oldIngredient == null)
                {
                    oldIngredient = new tblProductIngr
                    {
                        EntryDate  = entryDate,
                        EmployeeID = ingredient.EmployeeId,
                        ProdID     = oldProduct.ProdID,
                        IngrID     = ingredient.AdditiveTypeId,
                        s_GUID     = Guid.NewGuid()
                    };
                    entryDate = entryDate.AddSeconds(1);
                    _oldContext.tblProductIngrs.AddObject(oldIngredient);
                }

                oldIngredient.Percentage = (decimal?)ingredient.Percentage;
            }

            foreach (var deleted in deletedIngredients ?? new List <AdditiveTypeKey>())
            {
                var oldIngredient = oldProduct.tblProductIngrs.FirstOrDefault(i => i.IngrID == deleted.AdditiveTypeKey_AdditiveTypeId);
                if (oldIngredient != null)
                {
                    _oldContext.tblProductIngrs.DeleteObject(oldIngredient);
                }
            }
        }
 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 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 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));
            }
        public static ChileProduct EmptyProduct(this ChileProduct chileProduct)
        {
            if (chileProduct == null)
            {
                throw new ArgumentNullException("chileProduct");
            }

            chileProduct.ProductAttributeRanges = null;
            chileProduct.Ingredients            = null;

            return(chileProduct);
        }
            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 static void AssertEqual(this ChileProduct chileProduct, IChileProductReturn productReturn)
        {
            if (chileProduct == null)
            {
                throw new ArgumentNullException("chileProduct");
            }
            if (productReturn == null)
            {
                throw new ArgumentNullException("productReturn");
            }

            Assert.AreEqual(chileProduct.ToProductKey().KeyValue, productReturn.ProductKey);
            Assert.AreEqual(chileProduct.Product.Name, productReturn.ProductName);
            Assert.AreEqual(chileProduct.ChileState, productReturn.ChileState);
        }
 private static void SetChileProductSpec(ChileProduct chileProduct, tblProduct oldProduct)
 {
     foreach (var setRange in new List <SetRange>
     {
         new SetRange(StaticAttributeNames.Granularity, p => p.GranStart, p => p.GranEnd),
         new SetRange(StaticAttributeNames.Asta, p => p.AstaStart, p => p.AstaEnd),
         new SetRange(StaticAttributeNames.AB, p => p.ABStart, p => p.ABEnd),
         new SetRange(StaticAttributeNames.Scoville, p => p.ScovStart, p => p.ScovEnd),
         new SetRange(StaticAttributeNames.H2O, p => p.H2OStart, p => p.H2OEnd),
         new SetRange(StaticAttributeNames.Scan, p => p.ScanStart, p => p.ScanEnd),
     })
     {
         setRange.Set(chileProduct.ProductAttributeRanges.FirstOrDefault(r => r.AttributeShortName == setRange.Attribute.AttributeNameKey_ShortName), oldProduct);
     }
 }
        public static void AssertEqual(this ChileProduct chileProduct, IInventoryProductReturn productReturn)
        {
            if (chileProduct == null)
            {
                throw new ArgumentNullException("chileProduct");
            }
            if (productReturn == null)
            {
                throw new ArgumentNullException("productReturn");
            }

            Assert.AreEqual(chileProduct.ToProductKey().KeyValue, productReturn.ProductKey);
            Assert.AreEqual(chileProduct.Product.Name, productReturn.ProductName);
            Assert.AreEqual(chileProduct.Product.ProductType, productReturn.ProductType);
            Assert.AreEqual(chileProduct.ChileType.Description, productReturn.ProductSubType);
        }
            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));
            }
            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);
                        }
                    }
                }
            }
        internal IResult <ChileProduct> Execute(ChileProduct chileProduct, IUserIdentifiable user, DateTime timeStamp, IEnumerable <SetChileProductAttributeRangeParameters> ranges)
        {
            var employeeResult = new GetEmployeeCommand(_productUnitOfWork).GetEmployee(user);

            if (!employeeResult.Success)
            {
                return(employeeResult.ConvertTo <ChileProduct>());
            }

            AttributeNameKey[] notFound;
            var attributeNames = _productUnitOfWork.AttributeNameRepository.FindByKeys(out notFound, ranges.Select(r => r.AttributeNameKey).ToArray());

            if (notFound.Any())
            {
                return(new InvalidResult <ChileProduct>(null, string.Format(UserMessages.AttributeNameNotFound, notFound.First())));
            }

            var invalidForChile = attributeNames.FirstOrDefault(n => !n.ValidForChileInventory);

            if (invalidForChile != null)
            {
                return(new InvalidResult <ChileProduct>(null, string.Format(UserMessages.AttributeNameNotValidForChile, invalidForChile.ToAttributeNameKey())));
            }

            foreach (var match in (chileProduct.ProductAttributeRanges ?? new List <ChileProductAttributeRange>()).BestMatches(ranges,
                                                                                                                               (e, n) => e.AttributeShortName == n.AttributeNameKey.AttributeNameKey_ShortName,
                                                                                                                               (e, n) => e.RangeMin == n.Parameters.RangeMin,
                                                                                                                               (e, n) => e.RangeMax == n.Parameters.RangeMax))
            {
                if (match.Item2 == null)
                {
                    _productUnitOfWork.ChileProductAttributeRangeRepository.Remove(match.Item1);
                }
                else
                {
                    bool update;
                    var  range = match.Item1;
                    if (range == null || !match.Item2.AttributeNameKey.Equals(range))
                    {
                        if (range != null)
                        {
                            _productUnitOfWork.ChileProductAttributeRangeRepository.Remove(range);
                        }

                        update = true;
                        range  = _productUnitOfWork.ChileProductAttributeRangeRepository.Add(new ChileProductAttributeRange
                        {
                            ChileProductId     = chileProduct.Id,
                            AttributeShortName = match.Item2.AttributeNameKey.AttributeNameKey_ShortName
                        });
                    }
                    else
                    {
                        update = range.RangeMin != match.Item2.Parameters.RangeMin || range.RangeMax != match.Item2.Parameters.RangeMax;
                    }

                    if (update)
                    {
                        range.EmployeeId = employeeResult.ResultingObject.EmployeeId;
                        range.TimeStamp  = timeStamp;
                        range.RangeMin   = match.Item2.Parameters.RangeMin;
                        range.RangeMax   = match.Item2.Parameters.RangeMax;
                    }
                }
            }

            return(new SuccessResult <ChileProduct>(chileProduct));
        }
Exemple #14
0
        internal IResult <ChileProduct> Execute(ChileProduct chileProduct, IUserIdentifiable user, DateTime timeStamp, IEnumerable <SetChileProductIngredientCommandParameters> ingredients, out List <AdditiveTypeKey> deletedIngredients)
        {
            deletedIngredients = new List <AdditiveTypeKey>();

            var employeeResult = new GetEmployeeCommand(_productUnitOfWork).GetEmployee(user);

            if (!employeeResult.Success)
            {
                return(employeeResult.ConvertTo <ChileProduct>());
            }

            AdditiveTypeKey[] missingAdditiveTypes;
            _productUnitOfWork.AdditiveTypeRepository.FindByKeys(out missingAdditiveTypes, ingredients.Select(i => i.AdditiveTypeKey).ToArray());
            if (missingAdditiveTypes.Any())
            {
                return(new InvalidResult <ChileProduct>(null, string.Format(UserMessages.AdditiveTypeNotFound, missingAdditiveTypes.First())));
            }

            foreach (var match in (chileProduct.Ingredients ?? new List <ChileProductIngredient>()).BestMatches(ingredients,
                                                                                                                (e, n) => e.AdditiveTypeId == n.AdditiveTypeKey.AdditiveTypeKey_AdditiveTypeId,
                                                                                                                (e, n) => e.Percentage == n.Parameters.Percentage))
            {
                if (match.Item2 == null)
                {
                    deletedIngredients.Add(match.Item1.ToAdditiveTypeKey());
                    _productUnitOfWork.ChileProductIngredientRepository.Remove(match.Item1);
                }
                else
                {
                    bool update;
                    var  ingredient = match.Item1;
                    if (ingredient == null || ingredient.AdditiveTypeId != match.Item2.AdditiveTypeKey.AdditiveTypeKey_AdditiveTypeId)
                    {
                        if (ingredient != null)
                        {
                            deletedIngredients.Add(ingredient.ToAdditiveTypeKey());
                            _productUnitOfWork.ChileProductIngredientRepository.Remove(ingredient);
                        }

                        update     = true;
                        ingredient = _productUnitOfWork.ChileProductIngredientRepository.Add(new ChileProductIngredient
                        {
                            ChileProductId = chileProduct.Id,
                            AdditiveTypeId = match.Item2.AdditiveTypeKey.AdditiveTypeKey_AdditiveTypeId
                        });
                    }
                    else
                    {
                        update = ingredient.Percentage != match.Item2.Parameters.Percentage;
                    }

                    if (update)
                    {
                        ingredient.EmployeeId = employeeResult.ResultingObject.EmployeeId;
                        ingredient.TimeStamp  = timeStamp;
                        ingredient.Percentage = match.Item2.Parameters.Percentage;
                    }
                }
            }

            return(new SuccessResult().ConvertTo(chileProduct));
        }
Exemple #15
0
 public static string BuildKey(this ChileProduct chileProduct)
 {
     return(new ChileProductKey(chileProduct).ToString());
 }
        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));
        }
        protected IResult <ChileMaterialsReceived> Set(ChileMaterialsReceived received, ChileProduct chileProduct, ISetChileMaterialsReceivedParameters parameters, Employee employee, DateTime timeStamp)
        {
            if (received.ChileProductId != chileProduct.Id)
            {
                if (MaterialsReceivedUnitOfWork.PickedInventoryItemRepository.Filter(PickedInventoryItemPredicates.FilterByLotKey(received)).Any())
                {
                    return(new InvalidResult <ChileMaterialsReceived>(null, string.Format(UserMessages.LotHasExistingPickedInventory, received.ToLotKey())));
                }
            }

            var previousTreatment = received.ToInventoryTreatmentKey();
            var treatment         = MaterialsReceivedUnitOfWork.InventoryTreatmentRepository.FindByKey(parameters.TreatmentKey);

            if (treatment == null)
            {
                return(new InvalidResult <ChileMaterialsReceived>(null, string.Format(UserMessages.InventoryTreatmentNotFound, parameters.TreatmentKey)));
            }

            var supplier = MaterialsReceivedUnitOfWork.CompanyRepository.FindByKey(parameters.SupplierKey, c => c.CompanyTypes);

            if (supplier == null)
            {
                return(new InvalidResult <ChileMaterialsReceived>(null, string.Format(UserMessages.SupplierCompanyNotFound, parameters.SupplierKey)));
            }

            if (parameters.ChileMaterialsReceivedType == ChileMaterialsReceivedType.Dehydrated && supplier.CompanyTypes.All(c => c.CompanyTypeEnum != CompanyType.Dehydrator))
            {
                return(new InvalidResult <ChileMaterialsReceived>(null, string.Format(UserMessages.CompanyNotOfType, parameters.SupplierKey, CompanyType.Dehydrator)));
            }

            received.EmployeeId = employee.EmployeeId;
            received.TimeStamp  = timeStamp;

            received.ChileMaterialsReceivedType = parameters.ChileMaterialsReceivedType;
            received.DateReceived = parameters.DateReceived;
            received.LoadNumber   = parameters.LoadNumber;
            received.ChileLot.Lot.PurchaseOrderNumber = parameters.PurchaseOrder;
            received.ChileLot.Lot.ShipperNumber       = parameters.ShipperNumber;

            received.TreatmentId = treatment.Id;

            received.ChileProductId          = chileProduct.Id;
            received.ChileLot.ChileProductId = chileProduct.Id;

            received.Supplier   = supplier;
            received.SupplierId = supplier.Id;

            var setItemsResult = SetItems(received, parameters.Items, previousTreatment, employee, timeStamp);

            if (!setItemsResult.Success)
            {
                return(setItemsResult.ConvertTo <ChileMaterialsReceived>());
            }

            return(new SuccessResult <ChileMaterialsReceived>(received));
        }