Exemplo n.º 1
0
        private void Serialize(ChileProductKey chileProductKey, CustomerKey customerKey, out int prodId, out string companyIA)
        {
            var chileProduct = UnitOfWork.ChileProductRepository.FindByKey(chileProductKey, c => c.Product);
            var customer     = UnitOfWork.CustomerRepository.FindByKey(customerKey,
                                                                       c => c.Company,
                                                                       c => c.ProductSpecs);

            var pId      = prodId = int.Parse(chileProduct.Product.ProductCode);
            var cIA      = companyIA = customer.Company.Name;
            var existing = OldContext.SerializedCustomerProdSpecs.FirstOrDefault(s => s.ProdID == pId && s.Company_IA == cIA);

            var specs = customer.ProductSpecs.Where(s => s.ChileProductId == chileProduct.Id).ToList();

            if (!specs.Any())
            {
                if (existing != null)
                {
                    OldContext.SerializedCustomerProdSpecs.DeleteObject(existing);
                }
            }
            else
            {
                if (existing == null)
                {
                    existing = new SerializedCustomerProdSpecs
                    {
                        ProdID     = prodId,
                        Company_IA = companyIA
                    };
                    OldContext.SerializedCustomerProdSpecs.AddObject(existing);
                }

                existing.Serialized = SerializableCustomerSpec.Serialize(specs);
            }
        }
Exemplo n.º 2
0
        protected override IEnumerable <CustomerProductAttributeRange> BirthRecords()
        {
            _loadCount.Reset();

            foreach (var oldContextSpec in OldContext.CreateObjectSet <SerializedCustomerProdSpecs>().ToList())
            {
                var chileProduct = _newContextHelper.GetChileProduct(oldContextSpec.ProdID);
                if (chileProduct == null)
                {
                    Log(new CallbackParameters(CallbackReason.ChileProductNotLoaded)
                    {
                        Spec = oldContextSpec
                    });
                    continue;
                }

                var customer = _newContextHelper.GetCompany(oldContextSpec.Company_IA, CompanyType.Customer);
                if (customer == null)
                {
                    Log(new CallbackParameters(CallbackReason.CustomerNotLoaded)
                    {
                        Spec = oldContextSpec
                    });
                    continue;
                }

                var dataModels = SerializableCustomerSpec.Deserialize(oldContextSpec.Serialized).ToDataModels(chileProduct, customer);
                foreach (var dataModel in dataModels)
                {
                    _loadCount.AddRead(EntityTypes.CustomerProductAttributeRange);
                    _loadCount.AddLoaded(EntityTypes.CustomerProductAttributeRange);
                    yield return(dataModel);
                }
            }

            _loadCount.LogResults(l => Log(new CallbackParameters(l)));
        }