Пример #1
0
 private void AppendDisplayNameAttributes(string fieldName, string recordType, List <Action <RecordEntryViewModelBase> > onChanges)
 {
     foreach (var property in ObjectRecordService.GetFields(recordType))
     {
         var propertyInfo = ObjectRecordService.GetPropertyInfo(property, recordType);
         var attributes   = propertyInfo
                            .GetCustomAttributes <DisplayNameForPropertyValueAttribute>()
                            .Where(a => a.Property == fieldName);
         if (attributes.Any())
         {
             onChanges.Add((re) =>
             {
                 foreach (var attribute in attributes)
                 {
                     var dependencyViewModel = re.GetFieldViewModel(fieldName);
                     var dependantViewModel  = re.GetFieldViewModel(propertyInfo.Name);
                     if (dependencyViewModel.ValueObject != null &&
                         dependencyViewModel.ValueObject.Equals(attribute.Value))
                     {
                         dependantViewModel.Label = attribute.Label;
                     }
                 }
             });
         }
     }
 }
Пример #2
0
 private void AppendInitialiseAttributes(string fieldName, string recordType, List <Action <RecordEntryViewModelBase> > onChanges)
 {
     foreach (var property in ObjectRecordService.GetFields(recordType))
     {
         var propertyInfo            = ObjectRecordService.GetPropertyInfo(property, recordType);
         var initialiseForAttributes = propertyInfo
                                       .GetCustomAttributes <InitialiseFor>()
                                       .Where(a => a.PropertyDependency == fieldName);
         if (initialiseForAttributes.Any())
         {
             onChanges.Add((re) =>
             {
                 foreach (var initialiseForAttribute in initialiseForAttributes)
                 {
                     var dependencyViewModel = re.GetFieldViewModel(fieldName);
                     var dependantViewModel  = re.GetFieldViewModel(propertyInfo.Name);
                     if (dependencyViewModel.ValueObject != null &&
                         dependencyViewModel.ValueObject.Equals(initialiseForAttribute.ForValue) &&
                         (initialiseForAttribute.AlwaysSetIfNotEmpty || dependantViewModel.ValueObject.IsEmpty()))
                     {
                         dependantViewModel.ValueObject = initialiseForAttribute.InitialValue;
                     }
                 }
             });
         }
     }
 }