private PropertiesEditorViewModel CreateViewModel(PropertiesHolder TargetHolder, Func<PropertyTargetValue, bool> IsCustomizedPredicate, LocoDataContext Context, IPropertiesSubmitter submitter) { PropertiesHolder parentHolder = TargetHolder.GetParentHolder(Context); List<int> parentProperties = parentHolder != null ? parentHolder.AgregateTargetProperties(Context) .Where(pv => pv.PropertyValue != null) .Select(pv => pv.PropertyKindId) .ToList() : new List<int>(); var xxx = TargetHolder.AgregateTargetProperties(Context) .Select( p => new { property = new EditablePropertyViewModel(p.DicPropertyKind.Name, p.DicPropertyKind.DicValueType.TypeName, p.DicPropertyKind.StringFormat, p.PropertyKindId, p.PropertyValue, Context.GetDictionaryValues(p.DicPropertyKind), p.DicPropertyKind.Сustomizeable, parentProperties.Contains(p.PropertyKindId)), isDefined = IsCustomizedPredicate(p) }) .ToList() .Where(px => _customizabilityValidator.CanPropertyBeCustomized(px.property)) .ToList(); List<EditablePropertyViewModel> customizedProperties = xxx.Where(x => x.isDefined).Select(x => x.property).ToList(); List<CustomizeablePropertyViewModel> decustomisedProperties = xxx.Where(x => !x.isDefined).Select(x => new CustomizeablePropertyViewModel(x.property)).ToList(); return new PropertiesEditorViewModel(customizedProperties, decustomisedProperties, submitter); }
// ReSharper disable once ParameterTypeCanBeEnumerable.Local public PropertiesEditorViewModel(IList<EditablePropertyViewModel> CustomizedProperties, IList<CustomizeablePropertyViewModel> DecustomisedProperties, IPropertiesSubmitter PropertiesSubmitter) { if (PropertiesSubmitter == null) throw new ApplicationException(); _propertiesSubmitter = PropertiesSubmitter; this.DecustomisedProperties = new ObservableCollection<CustomizeablePropertyViewModel>(DecustomisedProperties); this.CustomizedProperties = new ObservableCollection<EditablePropertyViewModel>(CustomizedProperties); foreach (CustomizeablePropertyViewModel decustomizedProperty in DecustomisedProperties) decustomizedProperty.CustomizationRequested += DecustomizedPropertyOnCustomizationRequested; Cancel = new DelegateCommand(OnCancel); Submit = new DelegateCommand(OnSubmit, CanSubmit); foreach (EditablePropertyViewModel property in CustomizedProperties) SubscribeToCustomizedProperty(property); }