public PricingEverydayValueDriverWrapper(PricingEverydayValueDriver baseDriver) { if (baseDriver == null) { throw new ArgumentNullException("baseDriver"); } BaseDriver = baseDriver; }
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); } } }
public static DTO.PricingEverydayValueDriver ToDto(this Display.PricingEverydayValueDriver displayEntity) { var groups = new List <DTO.PricingValueDriverGroup>(); foreach (Display.PricingValueDriverGroup group in displayEntity.Groups) { groups.Add(group.ToDto()); } var dto = new DTO.PricingEverydayValueDriver( displayEntity.Id, displayEntity.Key, displayEntity.IsSelected, displayEntity.Name, displayEntity.Title, displayEntity.Sort, displayEntity.IsKey, groups); return(dto); }
/// <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; } }
public static Display.PricingEverydayValueDriver ToDisplayEntity(this DTO.PricingEverydayValueDriver dto) { var displayEntity = new Display.PricingEverydayValueDriver(); displayEntity.Key = dto.Key; displayEntity.Id = dto.Id; displayEntity.Name = dto.Name; displayEntity.Title = dto.Title; displayEntity.Sort = dto.Sort; displayEntity.IsSelected = dto.IsSelected; displayEntity.IsKey = dto.IsKey; foreach (var group in dto.Groups) { displayEntity.Groups.Add(group.ToDisplayEntity()); } displayEntity.IsDirty = false; return(displayEntity); }