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); } }
ContentPartDefinition Build(ContentPartDefinitionRecord source) { return source == null ? null : new ContentPartDefinition( source.Name, source.ContentPartFieldDefinitionRecords.Select(Build), source.Settings); }
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; }
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; }
ContentPartDefinition Build(ContentPartDefinitionRecord source) { return source == null ? null : new ContentPartDefinition( source.Name, source.ContentPartFieldDefinitionRecords.Select(Build), JsonConvert.DeserializeObject<SettingsDictionary>(source.Settings ?? "{ }")); }