Gets more doc type folders working, can create and delete, now to get doc types to be moved.

This commit is contained in:
Shannon
2015-11-10 16:14:03 +01:00
parent f54cde050a
commit b4755fc5c4
7 changed files with 76 additions and 16 deletions

View File

@@ -7,11 +7,17 @@ namespace Umbraco.Core.Models
/// </summary>
public sealed class EntityContainer : UmbracoEntity, IAggregateRoot
{
public EntityContainer(int parentId, string name, int userId)
public EntityContainer()
{
}
public EntityContainer(int id, int parentId, string name, int userId, string path)
{
Id = id;
ParentId = parentId;
Name = name;
CreatorId = userId;
Path = path;
}
}
}

View File

@@ -54,7 +54,12 @@ namespace Umbraco.Core.Persistence.Repositories
public EntityContainer CreateFolder(int parentId, string name, int userId)
{
var container = new EntityContainer(parentId, name, userId);
var container = new EntityContainer
{
ParentId = parentId,
Name = name,
CreatorId = userId
};
_containerRepository.AddOrUpdate(container);
return container;
}

View File

@@ -1,9 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Cache;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.EntityBase;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.Factories;
using Umbraco.Core.Persistence.Querying;
using Umbraco.Core.Persistence.SqlSyntax;
using Umbraco.Core.Persistence.UnitOfWork;
@@ -14,7 +17,7 @@ namespace Umbraco.Core.Persistence.Repositories
/// An internal repository for managing entity containers such as doc type, media type, data type containers
/// </summary>
/// <remarks>
/// All we're supporting here is creating and deleting
/// All we're supporting here is a single get, creating and deleting
/// </remarks>
internal class EntityContainerRepository : PetaPocoRepositoryBase<int, EntityContainer>
{
@@ -29,9 +32,32 @@ namespace Umbraco.Core.Persistence.Repositories
_entityObjectType = entityObjectType;
}
/// <summary>
/// Do not cache anything
/// </summary>
protected override IRuntimeCacheProvider RuntimeCache
{
get { return new NullCacheProvider(); }
}
protected override EntityContainer PerformGet(int id)
{
throw new NotImplementedException();
var sql = GetBaseQuery(false);
sql.Where(GetBaseWhereClause(), new { Id = id, NodeObjectType = _containerObjectType });
var containerDto = Database.Fetch<NodeDto>(sql).FirstOrDefault();
if (containerDto == null)
return null;
var entity = new EntityContainer(containerDto.NodeId,
containerDto.ParentId, containerDto.Text, containerDto.UserId ?? 0,
containerDto.Path);
//on initial construction we don't want to have dirty properties tracked
// http://issues.umbraco.org/issue/U4-1946
entity.ResetDirtyProperties(false);
return entity;
}
protected override IEnumerable<EntityContainer> PerformGetAll(params int[] ids)
@@ -46,12 +72,21 @@ namespace Umbraco.Core.Persistence.Repositories
protected override Sql GetBaseQuery(bool isCount)
{
throw new NotImplementedException();
var sql = new Sql();
if (isCount)
{
sql.Select("COUNT(*)").From<NodeDto>(SqlSyntax);
}
else
{
sql.Select("*").From<NodeDto>(SqlSyntax);
}
return sql;
}
protected override string GetBaseWhereClause()
{
throw new NotImplementedException();
return "umbracoNode.id = @Id and nodeObjectType = @NodeObjectType";
}
protected override IEnumerable<string> GetDeleteClauses()
@@ -77,7 +112,8 @@ namespace Umbraco.Core.Persistence.Repositories
var children = Database.Fetch<NodeDto>(
new Sql().Select("*")
.From<NodeDto>(SqlSyntax)
.Where<NodeDto>(dto => dto.ParentId == entity.Id && (dto.NodeObjectType == _entityObjectType || dto.NodeObjectType == _containerObjectType)));
.Where("parentID=@parentID AND (nodeObjectType=@entityObjectType OR nodeObjectType=@containerObjectType)",
new {parentID = entity.ParentId, entityObjectType = _entityObjectType, containerObjectType = _containerObjectType}));
foreach (var childDto in children)
{
@@ -136,11 +172,15 @@ namespace Umbraco.Core.Persistence.Repositories
UserId = entity.CreatorId
};
Database.Save(nodeDto);
var id = Convert.ToInt32(Database.Insert(nodeDto));
//update the path
nodeDto.Path = nodeDto.Path + "," + nodeDto.NodeId;
Database.Save(nodeDto);
entity.Id = id;
entity.Path = nodeDto.Path;
entity.ResetDirtyProperties();
}

View File

@@ -67,7 +67,7 @@ namespace Umbraco.Core.Persistence.Repositories
//on initial construction we don't want to have dirty properties tracked
// http://issues.umbraco.org/issue/U4-1946
((TracksChangesEntityBase)entity).ResetDirtyProperties(false);
entity.ResetDirtyProperties(false);
return entity;
}

View File

@@ -43,11 +43,13 @@ namespace Umbraco.Core.Services
public Attempt<int> CreateContentTypeFolder(int parentId, string name, int userId = 0)
{
using (var repo = RepositoryFactory.CreateContentTypeRepository(UowProvider.GetUnitOfWork()))
var uow = UowProvider.GetUnitOfWork();
using (var repo = RepositoryFactory.CreateContentTypeRepository(uow))
{
try
{
var container = repo.CreateFolder(parentId, name, userId);
uow.Commit();
return Attempt.Succeed(container.Id);
}
catch (Exception ex)
@@ -60,11 +62,13 @@ namespace Umbraco.Core.Services
public Attempt<int> CreateMediaTypeFolder(int parentId, string name, int userId = 0)
{
using (var repo = RepositoryFactory.CreateMediaTypeRepository(UowProvider.GetUnitOfWork()))
var uow = UowProvider.GetUnitOfWork();
using (var repo = RepositoryFactory.CreateMediaTypeRepository(uow))
{
try
{
var container = repo.CreateFolder(parentId, name, userId);
uow.Commit();
return Attempt.Succeed(container.Id);
}
catch (System.Exception ex)
@@ -77,18 +81,22 @@ namespace Umbraco.Core.Services
public void DeleteContentTypeFolder(int folderId, int userId = 0)
{
using (var repo = RepositoryFactory.CreateContentTypeRepository(UowProvider.GetUnitOfWork()))
var uow = UowProvider.GetUnitOfWork();
using (var repo = RepositoryFactory.CreateContentTypeRepository(uow))
{
repo.DeleteFolder(folderId);
uow.Commit();
//TODO: Audit trail ?
}
}
public void DeleteMediaTypeFolder(int folderId, int userId = 0)
{
using (var repo = RepositoryFactory.CreateMediaTypeRepository(UowProvider.GetUnitOfWork()))
var uow = UowProvider.GetUnitOfWork();
using (var repo = RepositoryFactory.CreateMediaTypeRepository(uow))
{
repo.DeleteFolder(folderId);
uow.Commit();
//TODO: Audit trail ?
}
}

View File

@@ -33,7 +33,7 @@
<div class="umb-pane" ng-if="model.creatingFolder">
<form novalidate name="createFolderForm"
ng-submit="createFolder()"
ng-submit="createContainer()"
val-form-manager>
<div ng-show="error">

View File

@@ -3,12 +3,13 @@
<div class="umb-dialog-body">
<p class="umb-abstract">
Are you sure you want to delete <strong>{{currentNode.name}}</strong> ?
<localize key="defaultdialogs_confirmdelete">Are you sure you want to delete</localize>
<strong>{{currentNode.name}}</strong> ?
</p>
<ng-switch on="currentNode.nodeType">
<div ng-switch-when="container">
<p>This action cannot be undone, click ok to delete.</p>
<p>Any item that exists in this folder will be moved to the parent folder</p>
<umb-confirm
on-confirm="performContainerDelete"