Exemplo n.º 1
0
        public void ImportProductPrices(DateTime?fromDate)
        {
            _log.InfoFormat("Enter ImportProductPrices() for fromDate: {0}", fromDate);

            this.Db.ReadOnly = true;

            if (fromDate == null)
            {
                try
                {
                    _log.Debug("fromDate is Null.Setting fromDate equal to Latest ModifiedOn Date on Products table");
                    fromDate = this.Db.Context.Products.Max(m => m.ModifiedOn);
                    _log.DebugFormat("fromDate: {0}", fromDate);
                }
                catch (Exception ex)
                {
                    _log.Debug("Setting fromDate equal to Latest ModifiedOn Date on Products table Failed.Set fromdate to Null");
                    fromDate = null;
                }
            }

            if (fromDate < DateTime.Today.AddDays(-365))
            {
                Log.Debug("fromDate is one year older than Current Date.Set fromDate to Null");
                fromDate = null;
            }

            // load all products
            var import = this.GetProducts(fromDate);

            if (import.Count == 0)
            {
                return;
            }

            // Ignore products with blank product numbers
            var daikinProducts = import.Where(p => !string.IsNullOrWhiteSpace(p.ProductNumber)).ToList();

            // Add/update products
            var products = new List <DPO.Data.Product>();

            // Map imported products to DPO Product and Spec structure
            foreach (var daikinProduct in daikinProducts)
            {
                var product = new DPO.Data.Product
                {
                    ListPrice     = daikinProduct.Price ?? 0,
                    ProductNumber = daikinProduct.ProductNumber ?? string.Empty
                };

                products.Add(product);
            }

            _log.Info("Start Update Product Prices");
            Db.UpdateProductPrices(products);
            _log.Info("Finished ImportProductPrices()");
        }
Exemplo n.º 2
0
        public void ImportProductData(DateTime?fromDate, Dictionary <string, DPO.Data.Product> currentProductsLookup)
        {
            _log.InfoFormat("Enter ImportProductData for fromDate: {0}", fromDate);

            this.Db.ReadOnly = true;

            if (fromDate == null)
            {
                try
                {
                    _log.Debug("fromDate is null. try Set fromDate equal to Maximum ModifiedOn date on Products table ");
                    fromDate = this.Db.Context.Products.Max(m => m.ModifiedOn);
                }
                catch (Exception ex)
                {
                    fromDate = null;
                    Log.Debug("can not set fromdate. default to null");
                }
            }

            if (fromDate < DateTime.Today.AddDays(-365))
            {
                fromDate = null;
                _log.Debug("fromDate is one year older than current date. Set fromDate to null");
            }

            // load all products
            var import = this.GetProducts(fromDate);

            if (import.Count == 0)
            {
                _log.DebugFormat("No product have been loaded from CRM for fromDate: {0}. Return to caller", fromDate);
                return;
            }

            // Import any new and get all specification labels
            _log.Debug("Get ProductSpecificationLabels");
            var specficationLabels = ProcessProductSpecificationLabels();

            _log.Debug("Get ProductSpecificationLabelLookup");
            var specificationLabelLookup = Db.Context.ProductSpecificationLabels.Local.ToDictionary(d => d.Name);

            // Ignore products withj blank product numbers
            var daikinProducts = import.Where(p => !string.IsNullOrWhiteSpace(p.ProductNumber)).ToList();

            // Add/update products
            var products = new List <DPO.Data.Product>();

            // Map imported products to DPO Product and Spec structure
            foreach (var daikinProduct in daikinProducts)
            {
                var product = new DPO.Data.Product
                {
                    BrandId           = daikinProduct.Brand ?? 1,
                    ProductCategoryId = daikinProduct.UnitCategory ?? 1,
                    ProductClassCode  = daikinProduct.ProductClassCode ?? string.Empty,
                    ProductFamilyId   = daikinProduct.Family ?? 1,
                    ProductNumber     = daikinProduct.ProductNumber ?? string.Empty,
                    Name       = daikinProduct.Name ?? string.Empty,
                    ModifiedOn = daikinProduct.ModifiedOn,

                    EERNonDucted              = daikinProduct.EERNonducted,
                    IEERNonDucted             = daikinProduct.IEERNonducted,
                    SEERNonDucted             = daikinProduct.SEERNonducted,
                    COP47NonDucted            = daikinProduct.COP47Nonducted,
                    HSPFNonDucted             = daikinProduct.HSPFNonducted,
                    CoolingCapacityRated      = daikinProduct.CoolingCapacityRated,
                    HeatingCapacityRated      = daikinProduct.HeatingCapacityRated,
                    ProductPowerVoltageTypeId = daikinProduct.PowerVoltage,

                    ProductSpecifications    = new List <ProductSpecification>(),
                    ProductModelTypeId       = daikinProduct.ModelType ?? 1,
                    ProductMarketTypeId      = daikinProduct.MarketType ?? 1,
                    ProductStatusId          = daikinProduct.ReleaseStatus ?? (int)ProductStatusTypeEnum.Other,
                    SubmittalSheetTypeId     = daikinProduct.SubmittalDatasheetTemplate ?? (int)SubmittalSheetTypeEnum.Other,
                    AllowCommissionScheme    = (daikinProduct.AllowExternalCommission.HasValue && daikinProduct.AllowExternalCommission.Value == true),
                    UnitInstallationTypeId   = daikinProduct.UnitInstallationType ?? 1,
                    ProductCompressorStageId = daikinProduct.CompressorType,
                    ProductMotorSpeedTypeId  = daikinProduct.MotorType,
                    ProductGasValveTypeId    = daikinProduct.GasValveType,
                    ProductInstallationConfigurationTypeId = daikinProduct.InstallationConfiguration,
                    ProductHeatExchangerTypeId             = daikinProduct.HeatExchangerType,

                    CoolingCapacityNominal = daikinProduct.CoolingCapacityNominal.HasValue ? daikinProduct.CoolingCapacityNominal.Value : 0,
                    AirFlowRateHighCooling = daikinProduct.AirFlowRateHigh.HasValue ? daikinProduct.AirFlowRateHigh.Value : 0
                };

                // Fill Product specifications
                foreach (var prop in specficationLabels)
                {
                    var value = (prop.GetValue.Invoke(daikinProduct) + string.Empty).Trim();

                    // Ignore empty properties, if changed to empty they will be removed
                    if (!string.IsNullOrWhiteSpace(value))
                    {
                        product.ProductSpecifications.Add(new ProductSpecification
                        {
                            ProductSpecificationLabelId = specificationLabelLookup[prop.PropertyName].ProductSpecificationLabelId,
                            Value = value
                        });
                    }
                }

                products.Add(product);
            }

            _log.Debug("Start UpdateProductAndProductSpecifications for all products");
            Db.UpdateProductAndProductSpecifications(products, currentProductsLookup);
            _log.Info("Finished execute ImportProductData()");
        }