protected override void PersistUpdatedItem(IMediaType entity) { //Updates Modified date ((MediaType)entity).UpdatingEntity(); //Look up parent to get and set the correct Path if ParentId has changed if (((ICanBeDirty)entity).IsPropertyDirty("ParentId")) { var parent = Database.First <NodeDto>("WHERE id = @ParentId", new { ParentId = entity.ParentId }); entity.Path = string.Concat(parent.Path, ",", entity.Id); entity.Level = parent.Level + 1; var maxSortOrder = Database.ExecuteScalar <int>( "SELECT coalesce(max(sortOrder),0) FROM umbracoNode WHERE parentid = @ParentId AND nodeObjectType = @NodeObjectType", new { ParentId = entity.ParentId, NodeObjectType = NodeObjectTypeId }); entity.SortOrder = maxSortOrder + 1; } var factory = new MediaTypeFactory(NodeObjectTypeId); var dto = factory.BuildDto(entity); PersistUpdatedBaseContentType(dto, entity); ((ICanBeDirty)entity).ResetDirtyProperties(); }
protected override IMediaType PerformGet(int id) { var contentTypeSql = GetBaseQuery(false); contentTypeSql.Where(GetBaseWhereClause(), new { Id = id }); var dto = Database.Fetch <ContentTypeDto, NodeDto>(contentTypeSql).FirstOrDefault(); if (dto == null) { return(null); } var factory = new MediaTypeFactory(NodeObjectTypeId); var contentType = factory.BuildEntity(dto); contentType.AllowedContentTypes = GetAllowedContentTypeIds(id); contentType.PropertyGroups = GetPropertyGroupCollection(id, contentType.CreateDate, contentType.UpdateDate); ((MediaType)contentType).PropertyTypes = GetPropertyTypeCollection(id, contentType.CreateDate, contentType.UpdateDate); var list = Database.Fetch <ContentType2ContentTypeDto>("WHERE childContentTypeId = @Id", new{ Id = id }); foreach (var contentTypeDto in list) { bool result = contentType.AddContentType(Get(contentTypeDto.ParentId)); //Do something if adding fails? (Should hopefully not be possible unless someone create a circular reference) } ((ICanBeDirty)contentType).ResetDirtyProperties(); return(contentType); }
protected override void PersistNewItem(IMediaType entity) { ((MediaType)entity).AddingEntity(); var factory = new MediaTypeFactory(NodeObjectTypeId); var dto = factory.BuildDto(entity); PersistNewBaseContentType(dto, entity); ((ICanBeDirty)entity).ResetDirtyProperties(); }