예제 #1
0
        private void RecalculateLinkedValueDrivers(PricingEverydayValueDriver driver)
        {
            PricingEverydayLinkedValueDriver existing = LinkedValueDrivers.FirstOrDefault(d => d.ValueDriverId == driver.Id);

            if (driver.IsSelected)
            {
                if (existing == null)
                {
                    PricingEverydayLinkedValueDriver linkedDriver = null;

                    PricingEverydayValueDriverWrapper cachedItem = _valueDriversCache.Find(item => item.Id == driver.Id);
                    if (cachedItem.LinkedDriver != null)
                    {
                        //Get the linked driver from the cache.
                        linkedDriver = cachedItem.LinkedDriver;
                    }
                    else
                    {
                        //Create new linked driver and add it to the cache.
                        linkedDriver = new PricingEverydayLinkedValueDriver {
                            ValueDriverId = driver.Id, Name = driver.Name
                        };
                        cachedItem.LinkedDriver = linkedDriver;
                    }
                    LinkedValueDrivers.Add(linkedDriver);
                }
            }
            else if (existing != null)
            {
                LinkedValueDrivers.Remove(existing);
            }
            if (KeyValueDriver != null)
            {
                //Remove previously marked key driver from the linked drivers.
                var keyDriver = LinkedValueDrivers.FirstOrDefault(d => d.ValueDriverId == KeyValueDriver.ValueDriverId);
                if (keyDriver != null)
                {
                    LinkedValueDrivers.Remove(keyDriver);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Sets this price routine's key value driver to the specified value driver.
        /// </summary>
        /// <param name="newKey"></param>
        public void SetKeyValueDriver(PricingEverydayValueDriver newKey)
        {
            PricingEverydayValueDriverWrapper currentKey = null;

            if (KeyValueDriver != null)
            {
                //Clear the current key driver.
                currentKey            = ValueDriversCache.Find(item => item.Id == KeyValueDriver.ValueDriverId);
                currentKey.IsKey      = false;
                currentKey.IsSelected = false;
            }

            //Get the new key driver's item from the cache.
            PricingEverydayValueDriverWrapper newKeyWrapper = ValueDriversCache.Find(item => item.Id == newKey.Id);

            newKeyWrapper.IsKey      = true;
            newKeyWrapper.IsSelected = true;

            if (newKeyWrapper.KeyDriver == null)
            {
                //Update the key driver concrete instance in the cache.
                var keyDriverInstance = new PricingEverydayKeyValueDriver {
                    ValueDriverId = newKey.Id
                };
                foreach (PricingValueDriverGroup sourceGroup in _selectedValueDriver.Groups)
                {
                    keyDriverInstance.Groups.Add(new PricingEverydayKeyValueDriverGroup {
                        ValueDriverGroupId = sourceGroup.Id, ValueDriverGroupValue = sourceGroup.Value
                    });
                }
                newKeyWrapper.KeyDriver = keyDriverInstance;
            }

            KeyValueDriver = newKeyWrapper.KeyDriver;

            if (SelectedValueDriver != newKeyWrapper.BaseDriver)
            {
                SelectedValueDriver = newKeyWrapper.BaseDriver;
            }
        }
예제 #3
0
        private List <PricingEverydayValueDriverWrapper> InitializeDriverContainer()
        {
            var list = new List <PricingEverydayValueDriverWrapper>();

            if (ValueDrivers != null && ValueDriversCache != null)
            {
                foreach (PricingEverydayValueDriver baseDriver in ValueDrivers)
                {
                    var wrapper = new PricingEverydayValueDriverWrapper(baseDriver);
                    list.Add(wrapper);
                }

                if (KeyValueDriver != null && KeyValueDriver.ValueDriverId > 0)
                {
                    var existing = list.Find(i => i.BaseDriver.Id == KeyValueDriver.ValueDriverId);
                    if (existing != null)
                    {
                        existing.KeyDriver = KeyValueDriver;
                    }
                }
                if (LinkedValueDrivers != null)
                {
                    foreach (PricingEverydayLinkedValueDriver linkedDriver in LinkedValueDrivers)
                    {
                        var existing = list.Find(i => i.BaseDriver.Id == linkedDriver.ValueDriverId);
                        if (existing != null)
                        {
                            existing.LinkedDriver = linkedDriver;
                            existing.IsSelected   = true;
                        }
                    }
                }
                OnPropertyChanged("ValueDriversCache");
            }
            return(list);
        }