line endings

This commit is contained in:
Claus
2016-01-11 12:02:33 +01:00
parent 323257a0bf
commit 81395169ba

View File

@@ -1,66 +1,66 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.Http;
using AutoMapper;
using Newtonsoft.Json;
using Umbraco.Core;
using Umbraco.Core.Dictionary;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using Umbraco.Web.Models.ContentEditing;
using Umbraco.Web.Mvc;
using Umbraco.Web.WebApi;
using Constants = Umbraco.Core.Constants;
namespace Umbraco.Web.Editors
{
/// <summary>
/// Am abstract API controller providing functionality used for dealing with content and media types
/// </summary>
[PluginController("UmbracoApi")]
[PrefixlessBodyModelValidator]
public abstract class ContentTypeControllerBase : UmbracoAuthorizedJsonController
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.Http;
using AutoMapper;
using Newtonsoft.Json;
using Umbraco.Core;
using Umbraco.Core.Dictionary;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using Umbraco.Web.Models.ContentEditing;
using Umbraco.Web.Mvc;
using Umbraco.Web.WebApi;
using Constants = Umbraco.Core.Constants;
namespace Umbraco.Web.Editors
{
/// <summary>
/// Am abstract API controller providing functionality used for dealing with content and media types
/// </summary>
[PluginController("UmbracoApi")]
[PrefixlessBodyModelValidator]
public abstract class ContentTypeControllerBase : UmbracoAuthorizedJsonController
{
private ICultureDictionary _cultureDictionary;
/// <summary>
/// Constructor
/// </summary>
protected ContentTypeControllerBase()
: this(UmbracoContext.Current)
{
}
/// <summary>
/// Constructor
/// </summary>
/// <param name="umbracoContext"></param>
protected ContentTypeControllerBase(UmbracoContext umbracoContext)
: base(umbracoContext)
{
}
private ICultureDictionary _cultureDictionary;
/// <summary>
/// Constructor
/// </summary>
protected ContentTypeControllerBase()
: this(UmbracoContext.Current)
{
}
/// <summary>
/// Constructor
/// </summary>
/// <param name="umbracoContext"></param>
protected ContentTypeControllerBase(UmbracoContext umbracoContext)
: base(umbracoContext)
{
}
/// <summary>
/// Returns the available composite content types for a given content type
/// </summary>
/// <returns></returns>
protected IEnumerable<EntityBasic> PerformGetAvailableCompositeContentTypes(int contentTypeId, UmbracoObjectTypes type)
{
IContentTypeComposition source = null;
/// <returns></returns>
protected IEnumerable<EntityBasic> PerformGetAvailableCompositeContentTypes(int contentTypeId, UmbracoObjectTypes type)
{
IContentTypeComposition source = null;
//below is all ported from the old doc type editor and comes with the same weaknesses /insanity / magic
IContentTypeComposition[] allContentTypes;
switch (type)
{
case UmbracoObjectTypes.DocumentType:
if (contentTypeId > 0)
case UmbracoObjectTypes.DocumentType:
if (contentTypeId > 0)
{
source = Services.ContentTypeService.GetContentType(contentTypeId);
if (source == null) throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
@@ -68,40 +68,40 @@ namespace Umbraco.Web.Editors
allContentTypes = Services.ContentTypeService.GetAllContentTypes().Cast<IContentTypeComposition>().ToArray();
break;
case UmbracoObjectTypes.MediaType:
if (contentTypeId > 0)
{
source = Services.ContentTypeService.GetMediaType(contentTypeId);
if (source == null) throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
}
case UmbracoObjectTypes.MediaType:
if (contentTypeId > 0)
{
source = Services.ContentTypeService.GetMediaType(contentTypeId);
if (source == null) throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
}
allContentTypes = Services.ContentTypeService.GetAllMediaTypes().Cast<IContentTypeComposition>().ToArray();
break;
case UmbracoObjectTypes.MemberType:
if (contentTypeId > 0)
{
source = Services.MemberTypeService.Get(contentTypeId);
if (source == null) throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
}
case UmbracoObjectTypes.MemberType:
if (contentTypeId > 0)
{
source = Services.MemberTypeService.Get(contentTypeId);
if (source == null) throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
}
allContentTypes = Services.MemberTypeService.GetAll().Cast<IContentTypeComposition>().ToArray();
break;
default:
throw new ArgumentOutOfRangeException("The entity type was not a content type");
}
}
var filtered = Services.ContentTypeService.GetAvailableCompositeContentTypes(source, allContentTypes);
return filtered
.Select(Mapper.Map<IContentTypeComposition, EntityBasic>)
.Select(x =>
{
x.Name = TranslateItem(x.Name);
return x;
.Select(x =>
{
x.Name = TranslateItem(x.Name);
return x;
})
.ToList();
}
.ToList();
}
/// <summary>
/// Validates the composition and adds errors to the model state if any are found then throws an error response if there are errors
@@ -188,23 +188,23 @@ namespace Umbraco.Web.Editors
if (found == null)
throw new HttpResponseException(HttpStatusCode.NotFound);
Mapper.Map(contentTypeSave, found);
if (validateComposition)
Mapper.Map(contentTypeSave, found);
if (validateComposition)
{
//NOTE: this throws an error response if it is not valid
ValidateComposition(contentTypeSave, found);
}
saveContentType(found);
return found;
saveContentType(found);
return found;
}
else
{
if (beforeCreateNew != null)
{
beforeCreateNew(contentTypeSave);
{
if (beforeCreateNew != null)
{
beforeCreateNew(contentTypeSave);
}
//set id to null to ensure its handled as a new type
@@ -222,9 +222,9 @@ namespace Umbraco.Web.Editors
}
//save as new
var newCt = Mapper.Map<TContentType>(contentTypeSave);
if (validateComposition)
var newCt = Mapper.Map<TContentType>(contentTypeSave);
if (validateComposition)
{
//NOTE: this throws an error response if it is not valid
ValidateComposition(contentTypeSave, newCt);
@@ -238,18 +238,18 @@ namespace Umbraco.Web.Editors
//NOTE: This will throw if the composition isn't right... but it shouldn't be at this stage
newCt.AddContentType(newCt);
saveContentType(newCt);
}
return newCt;
}
return newCt;
}
}
/// <summary>
/// Change the sort order for media
/// </summary>
/// <param name="move"></param>
/// <param name="getContentType"></param>
/// <param name="doMove"></param>
/// <returns></returns>
}
/// <summary>
/// Change the sort order for media
/// </summary>
/// <param name="move"></param>
/// <param name="getContentType"></param>
/// <param name="doMove"></param>
/// <returns></returns>
protected HttpResponseMessage PerformMove<TContentType>(
MoveOrCopy move,
Func<int, TContentType> getContentType,
@@ -262,29 +262,29 @@ namespace Umbraco.Web.Editors
return Request.CreateResponse(HttpStatusCode.NotFound);
}
var result = doMove(toMove, move.ParentId);
if (result.Success)
{
var response = Request.CreateResponse(HttpStatusCode.OK);
response.Content = new StringContent(toMove.Path, Encoding.UTF8, "application/json");
return response;
}
switch (result.Result.StatusType)
{
case MoveOperationStatusType.FailedParentNotFound:
return Request.CreateResponse(HttpStatusCode.NotFound);
var result = doMove(toMove, move.ParentId);
if (result.Success)
{
var response = Request.CreateResponse(HttpStatusCode.OK);
response.Content = new StringContent(toMove.Path, Encoding.UTF8, "application/json");
return response;
}
switch (result.Result.StatusType)
{
case MoveOperationStatusType.FailedParentNotFound:
return Request.CreateResponse(HttpStatusCode.NotFound);
case MoveOperationStatusType.FailedCancelledByEvent:
//returning an object of INotificationModel will ensure that any pending
// notification messages are added to the response.
return Request.CreateValidationErrorResponse(new SimpleNotificationModel());
case MoveOperationStatusType.FailedNotAllowedByPath:
return Request.CreateValidationErrorResponse(new SimpleNotificationModel());
case MoveOperationStatusType.FailedNotAllowedByPath:
var notificationModel = new SimpleNotificationModel();
notificationModel.AddErrorNotification(Services.TextService.Localize("moveOrCopy/notAllowedByPath"), "");
notificationModel.AddErrorNotification(Services.TextService.Localize("moveOrCopy/notAllowedByPath"), "");
return Request.CreateValidationErrorResponse(notificationModel);
default:
throw new ArgumentOutOfRangeException();
}
default:
throw new ArgumentOutOfRangeException();
}
}
private ICultureDictionary CultureDictionary
@@ -295,7 +295,7 @@ namespace Umbraco.Web.Editors
_cultureDictionary ??
(_cultureDictionary = CultureDictionaryFactoryResolver.Current.Factory.CreateDictionary());
}
}
}
}
}
}