Fix availability and names

This commit is contained in:
Stephan
2018-04-18 18:43:17 +02:00
parent dea47dfafe
commit a68e37c67b
2 changed files with 27 additions and 2 deletions

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using Umbraco.Core.Exceptions;
namespace Umbraco.Core.Models
{
@@ -213,7 +214,10 @@ namespace Umbraco.Core.Models
// sets a publish name
// internal for repositories
internal void SetPublishName(int? languageId, string name)
{
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentNullOrEmptyException(nameof(name));
if (languageId == null)
{
PublishName = name;
@@ -412,8 +416,9 @@ namespace Umbraco.Core.Models
// copy names
ClearNames();
foreach (var (languageId, name) in other.Names)
foreach (var (languageId, name) in other.Names)
SetName(languageId, name);
Name = other.Name;
}
/// <inheritdoc />

View File

@@ -136,6 +136,12 @@ namespace Umbraco.Core.Models
/// <inheritdoc />
public virtual void SetName(int? languageId, string name)
{
if (string.IsNullOrWhiteSpace(name))
{
ClearName(languageId);
return;
}
if (languageId == null)
{
Name = name;
@@ -152,6 +158,20 @@ namespace Umbraco.Core.Models
OnPropertyChanged(Ps.Value.NamesSelector);
}
private void ClearName(int? languageId)
{
if (languageId == null)
{
Name = null;
return;
}
if (_names == null) return;
_names.Remove(languageId.Value);
if (_names.Count == 0)
_names = null;
}
protected virtual void ClearNames()
{
_names = null;