Ejemplo n.º 1
0
        private void Apply(ContentPartDefinition model, ContentPartDefinitionRecord record)
        {
            record.Settings = model.Settings;

            var toRemove = record.ContentPartFieldDefinitionRecords
                .Where(partFieldDefinitionRecord => !model.Fields.Any(partField => partFieldDefinitionRecord.Name == partField.Name))
                .ToList();

            foreach (var remove in toRemove)
            {
                record.ContentPartFieldDefinitionRecords.Remove(remove);
            }

            foreach (var field in model.Fields)
            {
                var fieldName = field.Name;
                var partFieldRecord = record.ContentPartFieldDefinitionRecords.SingleOrDefault(r => r.Name == fieldName);
                if (partFieldRecord == null)
                {
                    partFieldRecord = new ContentPartFieldDefinitionRecord
                    {
                        ContentFieldDefinitionRecord = Acquire(field.FieldDefinition),
                        Name = field.Name
                    };
                    record.ContentPartFieldDefinitionRecords.Add(partFieldRecord);
                }
                Apply(field, partFieldRecord);
            }
        }
Ejemplo n.º 2
0
 ContentPartDefinition Build(ContentPartDefinitionRecord source)
 {
     return source == null ? null : new ContentPartDefinition(
         source.Name,
         source.ContentPartFieldDefinitionRecords.Select(Build),
         source.Settings);
 }
Ejemplo n.º 3
0
 private ContentPartDefinitionRecord Acquire(ContentPartDefinition contentPartDefinition)
 {
     var result = GetContentDefinitionRecord().ContentPartDefinitionRecords.SingleOrDefault(x => x.Name == contentPartDefinition.Name);
     if (result == null)
     {
         result = new ContentPartDefinitionRecord { Name = contentPartDefinition.Name, };
         GetContentDefinitionRecord().ContentPartDefinitionRecords.Add(result);
     }
     return result;
 }
 ContentPartDefinition Build(ContentPartDefinitionRecord source) {
     return new ContentPartDefinition(
         source.Name,
         source.ContentPartFieldDefinitionRecords.Select(Build),
         _settingsFormatter.Map(Parse(source.Settings)));
 }
 private ContentPartDefinitionRecord Acquire(ContentPartDefinition contentPartDefinition) {
     var result = _partDefinitionRepository.Table.SingleOrDefault(x => x.Name == contentPartDefinition.Name);
     if (result == null) {
         result = new ContentPartDefinitionRecord { Name = contentPartDefinition.Name };
         _partDefinitionRepository.Create(result);
     }
     return result;
 }
Ejemplo n.º 6
0
        private ContentPartDefinitionRecord Acquire(ContentPartDefinition contentPartDefinition)
        {
            var result = _contentStorageManager
                .Query<ContentPartDefinitionRecord>(x => x.Name == contentPartDefinition.Name)
                .SingleOrDefault();

            if (result == null) {
                result = new ContentPartDefinitionRecord { Name = contentPartDefinition.Name };
                _contentStorageManager.Store(result);
            }
            return result;
        }
Ejemplo n.º 7
0
 ContentPartDefinition Build(ContentPartDefinitionRecord source)
 {
     return source == null ? null : new ContentPartDefinition(
         source.Name,
         source.ContentPartFieldDefinitionRecords.Select(Build),
         JsonConvert.DeserializeObject<SettingsDictionary>(source.Settings ?? "{ }"));
 }