Adds MediaTypeFactory implementation U4-981

This commit is contained in:
Morten@Thinkpad-X220
2012-10-09 10:10:18 -02:00
parent 62c69edf02
commit 9ca4fbff9d
6 changed files with 267 additions and 2 deletions

View File

@@ -9,13 +9,13 @@ namespace Umbraco.Core.Persistence.Factories
{
private readonly Guid _nodeObjectType;
#region Implementation of IEntityFactory<IContentType,DocumentTypeDto>
public ContentTypeFactory(Guid nodeObjectType)
{
_nodeObjectType = nodeObjectType;
}
#region Implementation of IEntityFactory<IContentType,DocumentTypeDto>
public IContentType BuildEntity(DocumentTypeDto dto)
{
var contentType = new ContentType

View File

@@ -0,0 +1,82 @@
using System;
using System.Globalization;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
namespace Umbraco.Core.Persistence.Factories
{
internal class MediaTypeFactory : IEntityFactory<IMediaType, ContentTypeDto>
{
private readonly Guid _nodeObjectType;
public MediaTypeFactory(Guid nodeObjectType)
{
_nodeObjectType = nodeObjectType;
}
#region Implementation of IEntityFactory<IMediaType,ContentTypeDto>
public IMediaType BuildEntity(ContentTypeDto dto)
{
var contentType = new MediaType
{
Id = dto.NodeDto.NodeId,
Key =
dto.NodeDto.UniqueId.HasValue
? dto.NodeDto.UniqueId.Value
: dto.NodeDto.NodeId.ToGuid(),
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,
ParentId = dto.NodeDto.ParentId,
UserId =
dto.NodeDto.UserId.HasValue
? dto.NodeDto.UserId.Value
: 0,
Trashed = dto.NodeDto.Trashed
};
return contentType;
}
public ContentTypeDto BuildDto(IMediaType entity)
{
var contentTypeDto = new ContentTypeDto
{
Alias = entity.Alias,
Description = entity.Description,
Icon = entity.Icon,
Thumbnail = entity.Thumbnail,
NodeId = entity.Id,
NodeDto = BuildNodeDto(entity)
};
return contentTypeDto;
}
#endregion
private NodeDto BuildNodeDto(IMediaType entity)
{
var nodeDto = new NodeDto
{
CreateDate = entity.CreateDate,
NodeId = entity.Id,
Level = short.Parse(entity.Level.ToString(CultureInfo.InvariantCulture)),
NodeObjectType = _nodeObjectType,
ParentId = entity.ParentId,
Path = entity.Path,
SortOrder = entity.SortOrder,
Text = entity.Name,
Trashed = false,
UniqueId = entity.Key,
UserId = entity.UserId
};
return nodeDto;
}
}
}

View File

@@ -39,6 +39,7 @@ namespace Umbraco.Core.Persistence.Repositories
return null;
//TODO Get ContentType composition according to new table
//TODO Add AllowedContentTypes
var propertySql = new Sql();
propertySql.Select("*");
@@ -103,6 +104,7 @@ namespace Umbraco.Core.Persistence.Repositories
//NOTE: If IsDefault=true we won't get ContentTypes like File, Folder etc. but only DocumentTypes.
//Which is why "AND cmsDocumentType.IsDefault = @IsDefault" has been removed from sql below.
//But might need to add it if we create a MediaTypeRepository
//NOTE: Think the above is incorrect as ContentType and MediaType have different NodeObjectTypes.
sql.Select(isCount ? "COUNT(*)" : "*");
sql.From("cmsDocumentType");
sql.RightJoin("cmsContentType ON ([cmsContentType].[nodeId] = [cmsDocumentType].[contentTypeNodeId])");

View File

@@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence.Caching;
using Umbraco.Core.Persistence.Querying;
using Umbraco.Core.Persistence.UnitOfWork;
namespace Umbraco.Core.Persistence.Repositories
{
/// <summary>
/// Represents a repository for doing CRUD operations for <see cref="IMedia"/>
/// </summary>
internal class MediaRepository : PetaPocoRepositoryBase<int, IMedia>, IMediaRepository
{
public MediaRepository(IUnitOfWork work) : base(work)
{
}
public MediaRepository(IUnitOfWork work, IRepositoryCacheProvider cache) : base(work, cache)
{
}
#region Overrides of RepositoryBase<int,IMedia>
protected override IMedia PerformGet(int id)
{
throw new NotImplementedException();
}
protected override IEnumerable<IMedia> PerformGetAll(params int[] ids)
{
throw new NotImplementedException();
}
protected override IEnumerable<IMedia> PerformGetByQuery(IQuery<IMedia> query)
{
throw new NotImplementedException();
}
#endregion
#region Overrides of PetaPocoRepositoryBase<int,IMedia>
protected override Sql GetBaseQuery(bool isCount)
{
throw new NotImplementedException();
}
protected override Sql GetBaseWhereClause(object id)
{
throw new NotImplementedException();
}
protected override IEnumerable<string> GetDeleteClauses()
{
throw new NotImplementedException();
}
protected override Guid NodeObjectTypeId
{
get { throw new NotImplementedException(); }
}
#endregion
#region Unit of Work Implementation
protected override void PersistNewItem(IMedia entity)
{
throw new NotImplementedException();
}
protected override void PersistUpdatedItem(IMedia entity)
{
throw new NotImplementedException();
}
#endregion
}
}

View File

@@ -0,0 +1,98 @@
using System;
using System.Collections.Generic;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence.Caching;
using Umbraco.Core.Persistence.Querying;
using Umbraco.Core.Persistence.UnitOfWork;
namespace Umbraco.Core.Persistence.Repositories
{
/// <summary>
/// Represents a repository for doing CRUD operations for <see cref="IMediaType"/>
/// </summary>
internal class MediaTypeRepository : PetaPocoRepositoryBase<int, IMediaType>, IMediaTypeRepository
{
public MediaTypeRepository(IUnitOfWork work) : base(work)
{
}
public MediaTypeRepository(IUnitOfWork work, IRepositoryCacheProvider cache) : base(work, cache)
{
}
#region Overrides of RepositoryBase<int,IMedia>
protected override IMediaType PerformGet(int id)
{
throw new NotImplementedException();
}
protected override IEnumerable<IMediaType> PerformGetAll(params int[] ids)
{
throw new NotImplementedException();
}
protected override IEnumerable<IMediaType> PerformGetByQuery(IQuery<IMediaType> query)
{
throw new NotImplementedException();
}
#endregion
#region Overrides of PetaPocoRepositoryBase<int,IMedia>
protected override Sql GetBaseQuery(bool isCount)
{
var sql = new Sql();
sql.Select(isCount ? "COUNT(*)" : "*");
sql.From("cmsContentType");
sql.InnerJoin("umbracoNode ON ([cmsContentType].[nodeId] = [umbracoNode].[id])");
sql.Where("[umbracoNode].[nodeObjectType] = @NodeObjectType", new { NodeObjectType = NodeObjectTypeId });
return sql;
}
protected override Sql GetBaseWhereClause(object id)
{
var sql = new Sql();
sql.Where("[umbracoNode].[id] = @Id", new { Id = id });
return sql;
}
protected override IEnumerable<string> GetDeleteClauses()
{
var list = new List<string>
{
string.Format("DELETE FROM umbracoUser2NodeNotify WHERE nodeId = @Id"),
string.Format("DELETE FROM umbracoUser2NodePermission WHERE nodeId = @Id"),
string.Format("DELETE FROM cmsTagRelationship WHERE nodeId = @Id"),
string.Format("DELETE FROM cmsContentTypeAllowedContentType WHERE Id = @Id"),
string.Format("DELETE FROM cmsPropertyType WHERE contentTypeId = @Id"),
string.Format("DELETE FROM cmsTab WHERE contenttypeNodeId = @Id"),
string.Format("DELETE FROM cmsContentType WHERE NodeId = @Id"),
string.Format("DELETE FROM umbracoNode WHERE id = @Id")
};
return list;
}
protected override Guid NodeObjectTypeId
{
get { return new Guid("4EA4382B-2F5A-4C2B-9587-AE9B3CF3602E"); }
}
#endregion
#region Unit of Work Implementation
protected override void PersistNewItem(IMediaType entity)
{
throw new NotImplementedException();
}
protected override void PersistUpdatedItem(IMediaType entity)
{
throw new NotImplementedException();
}
#endregion
}
}

View File

@@ -108,6 +108,7 @@
<Compile Include="Persistence\Factories\DictionaryTranslationFactory.cs" />
<Compile Include="Persistence\Factories\IEntityFactory.cs" />
<Compile Include="Persistence\Factories\LanguageFactory.cs" />
<Compile Include="Persistence\Factories\MediaTypeFactory.cs" />
<Compile Include="Persistence\Factories\PropertyFactory.cs" />
<Compile Include="Persistence\Factories\PropertyGroupFactory.cs" />
<Compile Include="Persistence\Factories\RelationFactory.cs" />
@@ -141,6 +142,8 @@
<Compile Include="Persistence\Repositories\Interfaces\ITemplateRepository.cs" />
<Compile Include="Persistence\Repositories\LanguageRepository.cs" />
<Compile Include="Persistence\Repositories\MacroRepository.cs" />
<Compile Include="Persistence\Repositories\MediaRepository.cs" />
<Compile Include="Persistence\Repositories\MediaTypeRepository.cs" />
<Compile Include="Persistence\Repositories\PetaPocoRepositoryBase.cs" />
<Compile Include="Persistence\Repositories\RelationRepository.cs" />
<Compile Include="Persistence\Repositories\RelationTypeRepository.cs" />