Create new relation type

This commit is contained in:
James Coxhead
2018-11-29 23:11:03 +00:00
parent 12d11b7c88
commit c3a3f4cf22
6 changed files with 75 additions and 10 deletions

View File

@@ -77,6 +77,26 @@ function relationTypeResource($q, $http, umbRequestHelper, umbDataFormatter) {
);
},
/**
* @ngdoc method
* @name umbraco.resources.relationTypeResource#create
* @methodof umbraco.resources.relationTypeResource
*
* @description
* Creates a new relation type.
*
* @param {Object} relationType The relation type object to create.
* @returns {Promise} A resourcePromise object.
*/
create: function (relationType) {
var createModel = umbDataFormatter.formatRelationTypePostData(relationType);
return umbRequestHelper.resourcePromise(
$http.post(umbRequestHelper.getApiUrl("relationTypeApiBaseUrl", "PostCreate"), createModel),
"Failed to create new realtion"
);
},
deleteById: function (id) {
}

View File

@@ -441,7 +441,9 @@
name: relationType.name,
alias: relationType.alias,
key : relationType.key,
isBidirectional: relationType.isBidirectional
isBidirectional: relationType.isBidirectional,
parentObjectType: relationType.parentObjectType,
childObjectType: relationType.childObjectType
};
return saveModel;

View File

@@ -1,4 +1,4 @@
function RelationTypeCreateController($scope, relationTypeResource, navigationService, formHelper, appState) {
function RelationTypeCreateController($scope, $location, relationTypeResource, navigationService, formHelper, appState, notificationsService) {
var vm = this;
vm.relationType = {};
vm.objectTypes = {};

View File

@@ -27,20 +27,20 @@
<!-- Parent -->
<umb-control-group label="Parent">
<select name="relationType-parent"
ng-model="vm.relationType.parent"
ng-options="objectType.name for objectType in vm.objectTypes track by objectType.id"
ng-model="vm.relationType.parentObjectType"
class="umb-property-editor umb-dropdown"
required>
<option ng-repeat="objectType in vm.objectTypes" value="{{objectType.id}}">{{objectType.name}}</option>
</select>
</umb-control-group>
<!-- Child -->
<umb-control-group label="Child">
<select name="relationType-child"
ng-model="vm.relationType.child"
ng-options="objectType.name for objectType in vm.objectTypes track by objectType.id"
ng-model="vm.relationType.childObjectType"
class="umb-property-editor umb-dropdown"
required>
<option ng-repeat="objectType in vm.objectTypes" value="{{objectType.id}}">{{objectType.name}}</option>
</select>
</umb-control-group>

View File

@@ -1,11 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Net.Http;
using System.Web.Http;
using AutoMapper;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Web.Models.ContentEditing;
using Umbraco.Web.Mvc;
@@ -69,6 +68,37 @@ namespace Umbraco.Web.Editors
return objectTypes;
}
/// <summary>
/// Creates a new relation type.
/// </summary>
/// <param name="relationType">The relation type to create.</param>
/// <returns>A <see cref="HttpResponseMessage"/> containing the persisted relation type's ID.</returns>
public HttpResponseMessage PostCreate(RelationTypeSave relationType)
{
var relationTypePersisted = new Core.Models.RelationType(relationType.ChildObjectType, relationType.ParentObjectType, relationType.Name.ToSafeAlias(true))
{
Name = relationType.Name,
IsBidirectional = relationType.IsBidirectional
};
try
{
Services.RelationService.Save(relationTypePersisted);
return Request.CreateResponse(HttpStatusCode.OK, relationTypePersisted.Id);
}
catch (Exception ex)
{
Logger.Error(GetType(), ex, "Error creating relation type with {Name}", relationType.Name);
return Request.CreateNotificationValidationErrorResponse("Error creating dictionary item");
}
}
/// <summary>
/// Updates an existing relation type.
/// </summary>
/// <param name="relationType">The relation type to update.</param>
/// <returns>A display object containing the updated relation type.</returns>
public RelationTypeDisplay PostSave(RelationTypeSave relationType)
{
var relationTypePersisted = Services.RelationService.GetRelationTypeById(relationType.Key);

View File

@@ -1,4 +1,5 @@
using System.Runtime.Serialization;
using System;
using System.Runtime.Serialization;
namespace Umbraco.Web.Models.ContentEditing
{
@@ -10,5 +11,17 @@ namespace Umbraco.Web.Models.ContentEditing
/// </summary>
[DataMember(Name = "isBidirectional", IsRequired = true)]
public bool IsBidirectional { get; set; }
/// <summary>
/// Gets or sets the parent object type ID.
/// </summary>
[DataMember(Name = "parentObjectType", IsRequired = false)]
public Guid ParentObjectType { get; set; }
/// <summary>
/// Gets or sets the child object type ID.
/// </summary>
[DataMember(Name = "childObjectType", IsRequired = false)]
public Guid ChildObjectType { get; set; }
}
}