PR review amends on key value model and repository classes.

This commit is contained in:
Andy Butland
2020-03-28 14:55:03 +01:00
parent bc05370995
commit 3e40389819
4 changed files with 7 additions and 20 deletions

View File

@@ -8,7 +8,5 @@ namespace Umbraco.Core.Models
string Identifier { get; set; }
string Value { get; set; }
DateTime UpdateDate { get; set; }
}
}

View File

@@ -9,11 +9,10 @@ namespace Umbraco.Core.Models
/// </summary>
[Serializable]
[DataContract(IsReference = true)]
public class KeyValue : EntityBase, IKeyValue
public class KeyValue : EntityBase, IKeyValue, IEntity
{
private string _identifier;
private string _value;
private DateTime _updateDate;
/// <inheritdoc />
public string Identifier
@@ -28,5 +27,7 @@ namespace Umbraco.Core.Models
get => _value;
set => SetPropertyValueAndDetectChanges(value, ref _value, nameof(Value));
}
bool IEntity.HasIdentity => !string.IsNullOrEmpty(Identifier);
}
}

View File

@@ -33,21 +33,9 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
return database.FirstOrDefault<KeyValueDto>(sql)?.Value;
}
#region Overrides of IReadWriteQueryRepository<string, IKeyValue>
public override void Save(IKeyValue entity)
{
if (Get(entity.Identifier) == null)
PersistNewItem(entity);
else
PersistUpdatedItem(entity);
}
#endregion
#region Overrides of NPocoRepositoryBase<string, IKeyValue>
protected override Guid NodeObjectTypeId => throw new NotImplementedException();
protected override Guid NodeObjectTypeId => throw new NotSupportedException();
protected override Sql<ISqlContext> GetBaseQuery(bool isCount)
{
@@ -70,7 +58,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
protected override IEnumerable<string> GetDeleteClauses()
{
return new List<string>();
return Enumerable.Empty<string>();
}
protected override IKeyValue PerformGet(string id)
@@ -89,7 +77,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
protected override IEnumerable<IKeyValue> PerformGetByQuery(IQuery<IKeyValue> query)
{
throw new NotImplementedException();
throw new NotSupportedException();
}
protected override void PersistNewItem(IKeyValue entity)

View File

@@ -132,7 +132,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
/// </summary>
/// <remarks>This method is backed by an <see cref="IAppPolicyCache"/> cache</remarks>
/// <param name="entity"></param>
public virtual void Save(TEntity entity)
public void Save(TEntity entity)
{
if (entity.HasIdentity == false)
CachePolicy.Create(entity, PersistNewItem);