* Rename Umbraco.Core namespace to Umbraco.Cms.Core * Move extension methods in core project to Umbraco.Extensions * Move extension methods in core project to Umbraco.Extensions * Rename Umbraco.Examine namespace to Umbraco.Cms.Examine * Move examine extensions to Umbraco.Extensions namespace * Reflect changed namespaces in Builder and fix unit tests * Adjust namespace in Umbraco.ModelsBuilder.Embedded * Adjust namespace in Umbraco.Persistence.SqlCe * Adjust namespace in Umbraco.PublishedCache.NuCache * Align namespaces in Umbraco.Web.BackOffice * Align namespaces in Umbraco.Web.Common * Ensure that SqlCeSupport is still enabled after changing the namespace * Align namespaces in Umbraco.Web.Website * Align namespaces in Umbraco.Web.UI.NetCore * Align namespaces in Umbraco.Tests.Common * Align namespaces in Umbraco.Tests.UnitTests * Align namespaces in Umbraco.Tests.Integration * Fix errors caused by changed namespaces * Fix integration tests * Undo the Umbraco.Examine.Lucene namespace change This breaks integration tests on linux, since the namespace wont exists there because it's only used on windows. * Fix merge * Fix Merge
80 lines
3.2 KiB
C#
80 lines
3.2 KiB
C#
using System.Configuration;
|
|
using System.Linq;
|
|
using System.Web.Mvc;
|
|
using Umbraco.Cms.Core;
|
|
using Umbraco.Cms.Core.Models;
|
|
using Umbraco.Extensions;
|
|
using Umbraco.Web.Mvc;
|
|
|
|
namespace Umbraco.TestData
|
|
{
|
|
public class SegmentTestController : SurfaceController
|
|
{
|
|
|
|
public ActionResult EnableDocTypeSegments(string alias, string propertyTypeAlias)
|
|
{
|
|
if (ConfigurationManager.AppSettings["Umbraco.TestData.Enabled"] != "true")
|
|
return HttpNotFound();
|
|
|
|
var ct = Services.ContentTypeService.Get(alias);
|
|
if (ct == null)
|
|
return Content($"No document type found by alias {alias}");
|
|
|
|
var propType = ct.PropertyTypes.FirstOrDefault(x => x.Alias == propertyTypeAlias);
|
|
if (propType == null)
|
|
return Content($"The document type {alias} does not have a property type {propertyTypeAlias ?? "null"}");
|
|
|
|
if (ct.Variations.VariesBySegment())
|
|
return Content($"The document type {alias} already allows segments, nothing has been changed");
|
|
|
|
ct.SetVariesBy(ContentVariation.Segment);
|
|
propType.SetVariesBy(ContentVariation.Segment);
|
|
|
|
Services.ContentTypeService.Save(ct);
|
|
return Content($"The document type {alias} and property type {propertyTypeAlias} now allows segments");
|
|
}
|
|
|
|
public ActionResult DisableDocTypeSegments(string alias)
|
|
{
|
|
if (ConfigurationManager.AppSettings["Umbraco.TestData.Enabled"] != "true")
|
|
return HttpNotFound();
|
|
|
|
var ct = Services.ContentTypeService.Get(alias);
|
|
if (ct == null)
|
|
return Content($"No document type found by alias {alias}");
|
|
|
|
if (!ct.VariesBySegment())
|
|
return Content($"The document type {alias} does not allow segments, nothing has been changed");
|
|
|
|
ct.SetVariesBy(ContentVariation.Segment, false);
|
|
|
|
Services.ContentTypeService.Save(ct);
|
|
return Content($"The document type {alias} no longer allows segments");
|
|
}
|
|
|
|
public ActionResult AddSegmentData(int contentId, string propertyAlias, string value, string segment, string culture = null)
|
|
{
|
|
var content = Services.ContentService.GetById(contentId);
|
|
if (content == null)
|
|
return Content($"No content found by id {contentId}");
|
|
|
|
if (propertyAlias.IsNullOrWhiteSpace() || !content.HasProperty(propertyAlias))
|
|
return Content($"The content by id {contentId} does not contain a property with alias {propertyAlias ?? "null"}");
|
|
|
|
if (content.ContentType.VariesByCulture() && culture.IsNullOrWhiteSpace())
|
|
return Content($"The content by id {contentId} varies by culture but no culture was specified");
|
|
|
|
if (value.IsNullOrWhiteSpace())
|
|
return Content("'value' cannot be null");
|
|
|
|
if (segment.IsNullOrWhiteSpace())
|
|
return Content("'segment' cannot be null");
|
|
|
|
content.SetValue(propertyAlias, value, culture, segment);
|
|
Services.ContentService.Save(content);
|
|
|
|
return Content($"Segment value has been set on content {contentId} for property {propertyAlias}");
|
|
}
|
|
}
|
|
}
|