public IMediaType BuildEntity(ContentTypeDto dto) { var contentType = new MediaType(dto.NodeDto.ParentId) { Id = dto.NodeDto.NodeId, Key = dto.NodeDto.UniqueId, Alias = dto.Alias, Name = dto.NodeDto.Text, Icon = dto.Icon, Thumbnail = dto.Thumbnail, SortOrder = dto.NodeDto.SortOrder, Description = dto.Description, CreateDate = dto.NodeDto.CreateDate, Path = dto.NodeDto.Path, Level = dto.NodeDto.Level, CreatorId = dto.NodeDto.UserId.Value, AllowedAsRoot = dto.AllowAtRoot, IsContainer = dto.IsContainer, Trashed = dto.NodeDto.Trashed }; //on initial construction we don't want to have dirty properties tracked // http://issues.umbraco.org/issue/U4-1946 contentType.ResetDirtyProperties(false); return(contentType); }
public async Task <IActionResult> Post(ContentTypeDto model) { Guid userId = Guid.Parse(User.Claims.Single(x => x.Type == "sub").Value); var result = await this.facade.CreateContentType(userId, model); return(Ok(result)); }
private static void BuildCommonEntity(ContentTypeBase entity, ContentTypeDto dto, bool setVariations = true) { entity.Id = dto.NodeDto.NodeId; entity.Key = dto.NodeDto.UniqueId; entity.Alias = dto.Alias ?? string.Empty; entity.Name = dto.NodeDto.Text; entity.Icon = dto.Icon; entity.Thumbnail = dto.Thumbnail; entity.SortOrder = dto.NodeDto.SortOrder; entity.Description = dto.Description; entity.CreateDate = dto.NodeDto.CreateDate; entity.UpdateDate = dto.NodeDto.CreateDate; entity.Path = dto.NodeDto.Path; entity.Level = dto.NodeDto.Level; entity.CreatorId = dto.NodeDto.UserId ?? Cms.Core.Constants.Security.UnknownUserId; entity.AllowedAsRoot = dto.AllowAtRoot; entity.IsContainer = dto.IsContainer; entity.IsElement = dto.IsElement; entity.Trashed = dto.NodeDto.Trashed; if (setVariations) { entity.Variations = (ContentVariation)dto.Variations; } }
public ContentTypeDto BuildContentTypeDto(IContentTypeBase entity) { Guid nodeObjectType; if (entity is IContentType) { nodeObjectType = Constants.ObjectTypes.DocumentTypeGuid; } else if (entity is IMediaType) { nodeObjectType = Constants.ObjectTypes.MediaTypeGuid; } else if (entity is IMemberType) { nodeObjectType = Constants.ObjectTypes.MemberTypeGuid; } else { throw new Exception("Invalid entity."); } var contentTypeDto = new ContentTypeDto { Alias = entity.Alias, Description = entity.Description, Icon = entity.Icon, Thumbnail = entity.Thumbnail, NodeId = entity.Id, AllowAtRoot = entity.AllowedAsRoot, IsContainer = entity.IsContainer, NodeDto = BuildNodeDto(entity, nodeObjectType) }; return(contentTypeDto); }
protected internal ContentType(ContentTypeDto contentTypeDto, Module module) : base(contentTypeDto.Id, contentTypeDto.Metadata) { Name = contentTypeDto.Name; Module = module; _properties = new Dictionary <string, IContentTypeProperty>(); var ownProperties = contentTypeDto.OwnProperties.Select(p => new ContentTypeProperty(p, this)).ToList(); ownProperties.ForEach(p => _properties.Add(p.Name, p)); }
public async Task <IActionResult> GetBy([FromRoute] Guid tenantId, [FromRoute] int code) { ContentTypeDto contentTypeDto = await this.contentTypeService.GetBy(tenantId, code); if (contentTypeDto != null) { return(this.Ok(contentTypeDto)); } return(this.NotFound("A content type w/ the given tenant id and code was not found")); }
public async Task <IActionResult> Update([FromRoute] Guid tenantId, [FromRoute] int code, [FromBody] UpdateContentTypeDto updateContentTypeDto) { try { ContentTypeDto conditionTypeDto = await this.contentTypeService.Update(updateContentTypeDto.ToConditionTypeDto(tenantId, code)); return(this.Ok(conditionTypeDto)); } catch (NotFoundException) { return(this.NotFound("A content type w/ the given id was not found")); } }
private ContentTypeDto BuildContentTypeDto(IContentType entity) { var contentTypeDto = new ContentTypeDto { Alias = entity.Alias, Description = entity.Description, Icon = entity.Icon, Thumbnail = entity.Thumbnail, NodeId = entity.Id, AllowAtRoot = entity.AllowedAsRoot, IsContainer = entity.IsContainer, NodeDto = BuildNodeDto(entity) }; return contentTypeDto; }
public ContentTypeDto BuildDto(IMemberType entity) { var contentTypeDto = new ContentTypeDto { Alias = entity.Alias, Description = entity.Description, Icon = entity.Icon, Thumbnail = entity.Thumbnail, NodeId = entity.Id, AllowAtRoot = entity.AllowedAsRoot, IsContainer = entity.IsContainer, NodeDto = BuildNodeDto(entity) }; return(contentTypeDto); }
public async Task <ContentTypeDto> Add(ContentTypeDto contentTypeDto) { if (contentTypeDto == null) { throw new ArgumentNullException(nameof(contentTypeDto)); } ContentType contentType = this.contentTypeFactory.CreateContentType( contentTypeDto.TenantId, contentTypeDto.Code, contentTypeDto.Name); await this.contentTypeRepository.Add(contentType); return(this.ConvertToDto(contentType)); }
public static IMemberType BuildMemberTypeEntity(ContentTypeDto dto) { var contentType = new MemberType(dto.NodeDto.ParentId); try { contentType.DisableChangeTracking(); BuildCommonEntity(contentType, dto, false); contentType.ResetDirtyProperties(false); } finally { contentType.EnableChangeTracking(); } return(contentType); }
private static void BuildCommonEntity(ContentTypeBase entity, ContentTypeDto dto) { entity.Id = dto.NodeDto.NodeId; entity.Key = dto.NodeDto.UniqueId; entity.Alias = dto.Alias; entity.Name = dto.NodeDto.Text; entity.Icon = dto.Icon; entity.Thumbnail = dto.Thumbnail; entity.SortOrder = dto.NodeDto.SortOrder; entity.Description = dto.Description; entity.CreateDate = dto.NodeDto.CreateDate; entity.Path = dto.NodeDto.Path; entity.Level = dto.NodeDto.Level; entity.CreatorId = dto.NodeDto.UserId.Value; entity.AllowedAsRoot = dto.AllowAtRoot; entity.IsContainer = dto.IsContainer; entity.Trashed = dto.NodeDto.Trashed; }
public static IContentType BuildContentTypeEntity(ContentTypeDto dto) { var contentType = new ContentType(dto.NodeDto.ParentId); try { contentType.DisableChangeTracking(); BuildCommonEntity(contentType, dto); // reset dirty initial properties (U4-1946) contentType.ResetDirtyProperties(false); return(contentType); } finally { contentType.EnableChangeTracking(); } }
public async Task <ContentTypeDto> Update(ContentTypeDto contentTypeDto) { ContentTypeKey key = ContentTypeKey.New(contentTypeDto.TenantId, contentTypeDto.Code); ContentType conditionType = await this.contentTypeRepository.GetById(key); if (conditionType == null) { throw new NotFoundException(FormattableString.Invariant($"{nameof(ContentType)} was not found. Key = {key}")); } conditionType.Name = contentTypeDto.Name; return(await this.contentTypeRepository.Update(conditionType) .ContinueWith(tenantTask => { tenantTask.GetAwaiter().GetResult(); return this.ConvertToDto(conditionType); })); }
public IContentType BuildContentTypeEntity(ContentTypeDto dto) { var contentType = new ContentType(dto.NodeDto.ParentId); try { contentType.DisableChangeTracking(); BuildCommonEntity(contentType, dto); //on initial construction we don't want to have dirty properties tracked // http://issues.umbraco.org/issue/U4-1946 contentType.ResetDirtyProperties(false); return(contentType); } finally { contentType.EnableChangeTracking(); } }
public async Task <ContentTypeDto> CreateContentType(Guid userId, ContentTypeDto model) { var ctype = new ContentType { CreatedByUserId = userId, CreatedDate = DateTime.Now, Fields = model.Fields.Select(f => new ContentField { CreatedByUserId = userId, CreatedDate = DateTime.Now, FieldType = f.FieldType, Name = f.Name, Slug = f.Slug }).ToList(), Name = model.Name, Slug = model.Slug, SiteId = model.SiteId }; var created = await this.service.CreateContentType(ctype); return(new ContentTypeDto { Fields = created.Fields.Select(f => new ContentFieldDto { FieldType = f.FieldType, Id = f.Id, Name = f.Name, Slug = f.Slug }), Id = created.Id, Name = created.Name, SiteId = created.SiteId, Slug = created.Slug }); }
public static IMediaType BuildMediaTypeEntity(IShortStringHelper shortStringHelper, ContentTypeDto dto) { var contentType = new MediaType(shortStringHelper, dto.NodeDto.ParentId); try { contentType.DisableChangeTracking(); BuildCommonEntity(contentType, dto); // reset dirty initial properties (U4-1946) contentType.ResetDirtyProperties(false); } finally { contentType.EnableChangeTracking(); } return(contentType); }
public async Task <IActionResult> Add([FromRoute] Guid tenantId, [FromBody] CreateContentTypeDto createContentTypeDto) { ContentTypeDto contentTypeDto = await this.contentTypeService.Add(createContentTypeDto.ToConditionTypeDto(tenantId)); return(this.CreatedAtRoute("get-condition-type", new { tenantId = contentTypeDto.TenantId, code = contentTypeDto.Code }, contentTypeDto)); }
protected void PersistUpdatedBaseContentType(ContentTypeDto dto, IContentTypeComposition entity) { var propertyGroupFactory = new PropertyGroupFactory(entity.Id); var nodeDto = dto.NodeDto; var o = Database.Update(nodeDto); //Look up ContentType entry to get PrimaryKey for updating the DTO var dtoPk = Database.First <ContentTypeDto>("WHERE nodeId = @Id", new { Id = entity.Id }); dto.PrimaryKey = dtoPk.PrimaryKey; Database.Update(dto); //Delete the ContentType composition entries before adding the updated collection Database.Delete <ContentType2ContentTypeDto>("WHERE childContentTypeId = @Id", new { Id = entity.Id }); //Update ContentType composition in new table foreach (var composition in entity.ContentTypeComposition) { Database.Insert(new ContentType2ContentTypeDto { ParentId = composition.Id, ChildId = entity.Id }); } //Removing a ContentType from a composition (U4-1690) //1. Find content based on the current ContentType: entity.Id //2. Find all PropertyTypes on the ContentType that was removed - tracked id (key) //3. Remove properties based on property types from the removed content type where the content ids correspond to those found in step one var compositionBase = entity as ContentTypeCompositionBase; if (compositionBase != null && compositionBase.RemovedContentTypeKeyTracker != null && compositionBase.RemovedContentTypeKeyTracker.Any()) { //Find Content based on the current ContentType var sql = new Sql(); sql.Select("*") .From <ContentDto>() .InnerJoin <NodeDto>() .On <ContentDto, NodeDto>(left => left.NodeId, right => right.NodeId) .Where <NodeDto>(x => x.NodeObjectType == new Guid(Constants.ObjectTypes.Document)) .Where <ContentDto>(x => x.ContentTypeId == entity.Id); var contentDtos = Database.Fetch <ContentDto, NodeDto>(sql); //Loop through all tracked keys, which corresponds to the ContentTypes that has been removed from the composition foreach (var key in compositionBase.RemovedContentTypeKeyTracker) { //Find PropertyTypes for the removed ContentType var propertyTypes = Database.Fetch <PropertyTypeDto>("WHERE contentTypeId = @Id", new { Id = key }); //Loop through the Content that is based on the current ContentType in order to remove the Properties that are //based on the PropertyTypes that belong to the removed ContentType. foreach (var contentDto in contentDtos) { foreach (var propertyType in propertyTypes) { var nodeId = contentDto.NodeId; var propertyTypeId = propertyType.Id; var propertySql = new Sql().Select("*") .From <PropertyDataDto>() .InnerJoin <PropertyTypeDto>() .On <PropertyDataDto, PropertyTypeDto>( left => left.PropertyTypeId, right => right.Id) .Where <PropertyDataDto>(x => x.NodeId == nodeId) .Where <PropertyTypeDto>(x => x.Id == propertyTypeId); //Finally delete the properties that match our criteria for removing a ContentType from the composition Database.Delete <PropertyDataDto>(propertySql); } } } } //Delete the allowed content type entries before adding the updated collection Database.Delete <ContentTypeAllowedContentTypeDto>("WHERE Id = @Id", new { Id = entity.Id }); //Insert collection of allowed content types foreach (var allowedContentType in entity.AllowedContentTypes) { Database.Insert(new ContentTypeAllowedContentTypeDto { Id = entity.Id, AllowedId = allowedContentType.Id.Value, SortOrder = allowedContentType.SortOrder }); } if (((ICanBeDirty)entity).IsPropertyDirty("PropertyTypes") || entity.PropertyTypes.Any(x => x.IsDirty())) { //Delete PropertyTypes by excepting entries from db with entries from collections var dbPropertyTypes = Database.Fetch <PropertyTypeDto>("WHERE contentTypeId = @Id", new { Id = entity.Id }); var dbPropertyTypeAlias = dbPropertyTypes.Select(x => x.Id); var entityPropertyTypes = entity.PropertyTypes.Where(x => x.HasIdentity).Select(x => x.Id); var items = dbPropertyTypeAlias.Except(entityPropertyTypes); foreach (var item in items) { //Before a PropertyType can be deleted, all Properties based on that PropertyType should be deleted. Database.Delete <PropertyDataDto>("WHERE propertytypeid = @Id", new { Id = item }); Database.Delete <PropertyTypeDto>("WHERE contentTypeId = @Id AND id = @PropertyTypeId", new { Id = entity.Id, PropertyTypeId = item }); } } if (((ICanBeDirty)entity).IsPropertyDirty("PropertyGroups") || entity.PropertyGroups.Any(x => x.IsDirty())) { //Delete Tabs/Groups by excepting entries from db with entries from collections var dbPropertyGroups = Database.Fetch <PropertyTypeGroupDto>("WHERE contenttypeNodeId = @Id", new { Id = entity.Id }) .Select(x => new Tuple <int, string>(x.Id, x.Text)); var entityPropertyGroups = entity.PropertyGroups.Select(x => new Tuple <int, string>(x.Id, x.Name)); var tabs = dbPropertyGroups.Except(entityPropertyGroups); foreach (var tab in tabs) { Database.Update <PropertyTypeDto>("SET propertyTypeGroupId = NULL WHERE propertyTypeGroupId = @PropertyGroupId", new { PropertyGroupId = tab.Item1 }); Database.Update <PropertyTypeGroupDto>("SET parentGroupId = NULL WHERE parentGroupId = @TabId", new { TabId = tab.Item1 }); Database.Delete <PropertyTypeGroupDto>("WHERE contenttypeNodeId = @Id AND text = @Name", new { Id = entity.Id, Name = tab.Item2 }); } } //Run through all groups to insert or update entries foreach (var propertyGroup in entity.PropertyGroups) { var tabDto = propertyGroupFactory.BuildGroupDto(propertyGroup); int groupPrimaryKey = propertyGroup.HasIdentity ? Database.Update(tabDto) : Convert.ToInt32(Database.Insert(tabDto)); if (propertyGroup.HasIdentity == false) { propertyGroup.Id = groupPrimaryKey; //Set Id on new PropertyGroup } //Ensure that the PropertyGroup's Id is set on the PropertyTypes within a group //unless the PropertyGroupId has already been changed. foreach (var propertyType in propertyGroup.PropertyTypes) { if (propertyType.IsPropertyDirty("PropertyGroupId") == false) { var tempGroup = propertyGroup; propertyType.PropertyGroupId = new Lazy <int>(() => tempGroup.Id); } } } //Run through all PropertyTypes to insert or update entries foreach (var propertyType in entity.PropertyTypes) { var tabId = propertyType.PropertyGroupId != null ? propertyType.PropertyGroupId.Value : default(int); //If the Id of the DataType is not set, we resolve it from the db by its ControlId if (propertyType.DataTypeDefinitionId == 0 || propertyType.DataTypeDefinitionId == default(int)) { var datatype = Database.FirstOrDefault <DataTypeDto>("WHERE controlId = @Id", new { Id = propertyType.DataTypeId }); propertyType.DataTypeDefinitionId = datatype.DataTypeId; } var propertyTypeDto = propertyGroupFactory.BuildPropertyTypeDto(tabId, propertyType); int typePrimaryKey = propertyType.HasIdentity ? Database.Update(propertyTypeDto) : Convert.ToInt32(Database.Insert(propertyTypeDto)); if (propertyType.HasIdentity == false) { propertyType.Id = typePrimaryKey; //Set Id on new PropertyType } } }
public IMemberType BuildMemberTypeEntity(ContentTypeDto dto) { throw new NotImplementedException(); }
public void Issue8370Test() { // fixme maybe we need to create some content? // yes otherwise cannot get it to fail! var n = new NodeDto { Text = "text", CreateDate = DateTime.Now, Path = "-1", ParentId = -1, UniqueId = Guid.NewGuid() }; DatabaseContext.Database.Insert(n); var ct = new ContentTypeDto { Alias = "alias", NodeId = n.NodeId, Thumbnail = "thumb" }; DatabaseContext.Database.Insert(ct); n = new NodeDto { Text = "text", CreateDate = DateTime.Now, Path = "-1", ParentId = -1, UniqueId = Guid.NewGuid() }; DatabaseContext.Database.Insert(n); var dt = new DataTypeDto { PropertyEditorAlias = Constants.PropertyEditors.RelatedLinksAlias, DbType = "x", DataTypeId = n.NodeId }; DatabaseContext.Database.Insert(dt); var pt = new PropertyTypeDto { Alias = "alias", ContentTypeId = ct.NodeId, DataTypeId = dt.DataTypeId }; DatabaseContext.Database.Insert(pt); n = new NodeDto { Text = "text", CreateDate = DateTime.Now, Path = "-1", ParentId = -1, UniqueId = Guid.NewGuid() }; DatabaseContext.Database.Insert(n); var data = new PropertyDataDto { NodeId = n.NodeId, PropertyTypeId = pt.Id, Text = "text", VersionId = Guid.NewGuid() }; DatabaseContext.Database.Insert(data); data = new PropertyDataDto { NodeId = n.NodeId, PropertyTypeId = pt.Id, Text = "<root><node title=\"\" type=\"\" newwindow=\"\" link=\"\" /></root>", VersionId = Guid.NewGuid() }; DatabaseContext.Database.Insert(data); var migration = new UpdateRelatedLinksData(SqlSyntax, Logger); migration.UpdateRelatedLinksDataDo(DatabaseContext.Database); data = DatabaseContext.Database.Fetch <PropertyDataDto>("SELECT * FROM cmsPropertyData WHERE id=" + data.Id).FirstOrDefault(); Assert.IsNotNull(data); Debug.Print(data.Text); Assert.AreEqual("[{\"title\":\"\",\"caption\":\"\",\"link\":\"\",\"newWindow\":false,\"type\":\"external\",\"internal\":null,\"edit\":false,\"isInternal\":false}]", data.Text); }
protected void PersistNewBaseContentType(ContentTypeDto dto, IContentTypeComposition entity) { //Logic for setting Path, Level and SortOrder var parent = Database.First <NodeDto>("WHERE id = @ParentId", new { ParentId = entity.ParentId }); int level = parent.Level + 1; int sortOrder = Database.ExecuteScalar <int>("SELECT COUNT(*) FROM umbracoNode WHERE parentID = @ParentId AND nodeObjectType = @NodeObjectType", new { ParentId = entity.ParentId, NodeObjectType = NodeObjectTypeId }); //Create the (base) node data - umbracoNode var nodeDto = dto.NodeDto; nodeDto.Path = parent.Path; nodeDto.Level = short.Parse(level.ToString(CultureInfo.InvariantCulture)); nodeDto.SortOrder = sortOrder; var o = Database.IsNew(nodeDto) ? Convert.ToInt32(Database.Insert(nodeDto)) : Database.Update(nodeDto); //Update with new correct path nodeDto.Path = string.Concat(parent.Path, ",", nodeDto.NodeId); Database.Update(nodeDto); //Update entity with correct values entity.Id = nodeDto.NodeId; //Set Id on entity to ensure an Id is set entity.Path = nodeDto.Path; entity.SortOrder = sortOrder; entity.Level = level; //Insert new ContentType entry dto.NodeId = nodeDto.NodeId; Database.Insert(dto); //Insert ContentType composition in new table foreach (var composition in entity.ContentTypeComposition) { if (composition.Id == entity.Id) { continue; //Just to ensure that we aren't creating a reference to ourself. } if (composition.HasIdentity) { Database.Insert(new ContentType2ContentTypeDto { ParentId = composition.Id, ChildId = entity.Id }); } else { //Fallback for ContentTypes with no identity var contentTypeDto = Database.FirstOrDefault <ContentTypeDto>("WHERE alias = @Alias", new { Alias = composition.Alias }); if (contentTypeDto != null) { Database.Insert(new ContentType2ContentTypeDto { ParentId = contentTypeDto.NodeId, ChildId = entity.Id }); } } } //Insert collection of allowed content types foreach (var allowedContentType in entity.AllowedContentTypes) { Database.Insert(new ContentTypeAllowedContentTypeDto { Id = entity.Id, AllowedId = allowedContentType.Id.Value, SortOrder = allowedContentType.SortOrder }); } var propertyFactory = new PropertyGroupFactory(nodeDto.NodeId); //Insert Tabs foreach (var propertyGroup in entity.PropertyGroups) { var tabDto = propertyFactory.BuildGroupDto(propertyGroup); var primaryKey = Convert.ToInt32(Database.Insert(tabDto)); propertyGroup.Id = primaryKey;//Set Id on PropertyGroup //Ensure that the PropertyGroup's Id is set on the PropertyTypes within a group //unless the PropertyGroupId has already been changed. foreach (var propertyType in propertyGroup.PropertyTypes) { if (propertyType.IsPropertyDirty("PropertyGroupId") == false) { var tempGroup = propertyGroup; propertyType.PropertyGroupId = new Lazy <int>(() => tempGroup.Id); } } } //Insert PropertyTypes foreach (var propertyType in entity.PropertyTypes) { var tabId = propertyType.PropertyGroupId != null ? propertyType.PropertyGroupId.Value : default(int); //If the Id of the DataType is not set, we resolve it from the db by its ControlId if (propertyType.DataTypeDefinitionId == 0 || propertyType.DataTypeDefinitionId == default(int)) { var datatype = Database.FirstOrDefault <DataTypeDto>("WHERE controlId = @Id", new { Id = propertyType.DataTypeId }); propertyType.DataTypeDefinitionId = datatype.DataTypeId; } var propertyTypeDto = propertyFactory.BuildPropertyTypeDto(tabId, propertyType); int typePrimaryKey = Convert.ToInt32(Database.Insert(propertyTypeDto)); propertyType.Id = typePrimaryKey; //Set Id on new PropertyType //Update the current PropertyType with correct ControlId and DatabaseType var dataTypeDto = Database.FirstOrDefault <DataTypeDto>("WHERE nodeId = @Id", new { Id = propertyTypeDto.DataTypeId }); propertyType.DataTypeId = dataTypeDto.ControlId; propertyType.DataTypeDatabaseType = dataTypeDto.DbType.EnumParse <DataTypeDatabaseType>(true); } }
public ContentType(ContentTypeDto contentTypeDto) { Id = contentTypeDto.Id; Name = contentTypeDto.Name; Articles = contentTypeDto.Articles; }