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);
        }
Example #2
0
        /// <summary>Загружает информацию о локомотиве из базы</summary>
        private void LoadLocomotive(LocomotiveModel LoadingLocomotive, LocoDataContext db)
        {
            Locomotive loc = db.Locomotive.First(l => l.Id == LoadingLocomotive.Id);

            var xxx = loc
                .GetTargetProperties(db)
                .Select(
                    p =>
                    new
                    {
                        PropertyValue = p,
                        p.DicPropertyKind,
                        p.DicPropertyKind.Storage,
                        p.DicPropertyKind.DicValueType,
                        p.DicPropertyKind.Group,
                    })
                .ToList();

            Properties =
                xxx.Select(x =>
                           new PropertyModel(x.DicPropertyKind.Id, x.DicPropertyKind.Name, x.Group.Name,
                                             PropertyEncoding.GetEncoder(x.DicValueType.TypeName),
                                             x.Storage != null
                                                 ? new PropertyPlacement(x.Storage.StorageIndex, x.Storage.Offset, x.Storage.Length)
                                                 : null,
                                             DisplayIndex: x.DicPropertyKind.DisplayIndex,
                                             TargetValue: x.PropertyValue.GetPropertyValueObject(PropertyValueBase.GetPropertyType(x.DicValueType)),
                                             StringFormat: x.DicPropertyKind.StringFormat,
                                             DictionaryValues: db.GetDictionaryValues(x.DicPropertyKind) != null
                                                                   ? db.GetDictionaryValues(x.DicPropertyKind).ToDictionary(
                                                                       dv => PropertyValueBase.GetPropertyValueObject(PropertyValueBase.GetPropertyType(x.DicValueType), dv.Value),
                                                                       dv => dv.Key)
                                                                   : null))
                   .ToList();

            Properties.Add(SystemProperties.LocomotiveNumberProperty.GetPropertyModel(LoadingLocomotive.Number));
            Properties.Add(SystemProperties.SectionNumberProperty.GetPropertyModel(LoadingLocomotive.Section ?? ""));
            Properties.Add(SystemProperties.CombinedLocomotiveNumberProperty.GetPropertyModel(
                SystemProperties.CombineLocomotiveNumber(LoadingLocomotive.Number, LoadingLocomotive.Section)));
            Properties.Add(SystemProperties.KindUidProperty.GetPropertyModel(LoadingLocomotive.KindUid));

            Stores = Properties.Where(p => p.Placement != null)
                               .GroupBy(p => p.Placement.StorageIndex)
                               .ToDictionary(pg => pg.Key, pg => new StorageModel(pg.Key, pg.ToArray()));
        }