Fixes macro parameter id assignment at the repo level.

This commit is contained in:
Shannon
2013-09-20 13:40:32 +10:00
parent 6a343ef2b6
commit 661bc3149f
4 changed files with 29 additions and 7 deletions

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
@@ -125,13 +126,17 @@ namespace Umbraco.Core.Models
private static readonly PropertyInfo XsltPathSelector = ExpressionHelper.GetPropertyInfo<Macro, string>(x => x.XsltPath);
private static readonly PropertyInfo PropertiesSelector = ExpressionHelper.GetPropertyInfo<Macro, MacroPropertyCollection>(x => x.Properties);
protected void PropertiesChanged(object sender, NotifyCollectionChangedEventArgs e)
void PropertiesChanged(object sender, NotifyCollectionChangedEventArgs e)
{
OnPropertyChanged(PropertiesSelector);
if (e.Action == NotifyCollectionChangedAction.Add)
{
var alias = e.NewItems.Cast<IMacroProperty>().Select(x => x.Alias).First();
//listen for changes
var prop = e.NewItems.Cast<MacroProperty>().First();
prop.PropertyChanged += PropertyDataChanged;
var alias = prop.Alias;
//remove from the removed/added props (since people could add/remove all they want in one request)
_removedProperties.RemoveAll(s => s == alias);
@@ -142,7 +147,11 @@ namespace Umbraco.Core.Models
}
else if (e.Action == NotifyCollectionChangedAction.Remove)
{
var alias = e.OldItems.Cast<IMacroProperty>().Select(x => x.Alias).First();
//remove listening for changes
var prop = e.OldItems.Cast<MacroProperty>().First();
prop.PropertyChanged -= PropertyDataChanged;
var alias = prop.Alias;
//remove from the removed/added props (since people could add/remove all they want in one request)
_removedProperties.RemoveAll(s => s == alias);
@@ -152,6 +161,16 @@ namespace Umbraco.Core.Models
_removedProperties.Add(alias);
}
}
/// <summary>
/// When some data of a property has changed ensure our Properties flag is dirty
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void PropertyDataChanged(object sender, PropertyChangedEventArgs e)
{
OnPropertyChanged(PropertiesSelector);
}
internal override void ResetDirtyProperties(bool rememberPreviouslyChangedProperties)
{

View File

@@ -148,7 +148,8 @@ namespace Umbraco.Core.Persistence.Repositories
{
//need to set the id explicitly here
propDto.Macro = id;
Database.Insert(propDto);
var propId = Convert.ToInt32(Database.Insert(propDto));
entity.Properties[propDto.Alias].Id = propId;
}
((ICanBeDirty)entity).ResetDirtyProperties();
@@ -173,8 +174,8 @@ namespace Umbraco.Core.Persistence.Repositories
if (macro.AddedProperties.Contains(propDto.Alias))
{
//we need to insert since this was added and re-assign the new id
Database.Insert(propDto);
macro.Properties[propDto.Alias].Id = propDto.Id;
var propId = Convert.ToInt32(Database.Insert(propDto));
macro.Properties[propDto.Alias].Id = propId;
}
else
{

View File

@@ -142,7 +142,7 @@ namespace Umbraco.Core.Persistence
internal virtual IMacroRepository CreateMacroRepository(IDatabaseUnitOfWork uow)
{
return new MacroRepository(uow, RuntimeCacheProvider.Current);
return new MacroRepository(uow, _disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current);
}
internal virtual IMemberRepository CreateMemberRepository(IDatabaseUnitOfWork uow)

View File

@@ -164,12 +164,14 @@ namespace Umbraco.Tests.Persistence.Repositories
{
// Act
var macro = new Macro("test", "Test", "~/usercontrol/blah.ascx", "MyAssembly", "test.xslt", "~/views/macropartials/test.cshtml");
macro.Properties.Add(new MacroProperty("test", "Test", 0, "test"));
repository.AddOrUpdate(macro);
unitOfWork.Commit();
// Assert
Assert.That(macro.HasIdentity, Is.True);
Assert.That(macro.Id, Is.EqualTo(4));//With 3 existing entries the Id should be 4
Assert.Greater(macro.Properties.Single().Id, 0);
}
}