Fixes deep clone of User object

This commit is contained in:
Shannon
2014-05-09 13:25:18 +10:00
parent b1603a21a2
commit 8e9a9dc996
2 changed files with 42 additions and 10 deletions

View File

@@ -59,9 +59,9 @@ namespace Umbraco.Core.Models.Membership
private IUserType _userType;
private string _name;
private Type _userTypeKey;
private readonly List<string> _addedSections;
private readonly List<string> _removedSections;
private readonly ObservableCollection<string> _sectionCollection;
private List<string> _addedSections;
private List<string> _removedSections;
private ObservableCollection<string> _sectionCollection;
private int _sessionTimeout;
private int _startContentId;
private int _startMediaId;
@@ -423,24 +423,44 @@ namespace Umbraco.Core.Models.Membership
if (e.Action == NotifyCollectionChangedAction.Add)
{
var item = e.NewItems.Cast<string>().First();
//remove from the removed/added sections (since people could add/remove all they want in one request)
_removedSections.RemoveAll(s => s == e.NewItems.Cast<string>().First());
_addedSections.RemoveAll(s => s == e.NewItems.Cast<string>().First());
_removedSections.Remove(item);
_addedSections.Remove(item);
//add to the added sections
_addedSections.Add(e.NewItems.Cast<string>().First());
_addedSections.Add(item);
}
else if (e.Action == NotifyCollectionChangedAction.Remove)
{
var item = e.OldItems.Cast<string>().First();
//remove from the removed/added sections (since people could add/remove all they want in one request)
_removedSections.RemoveAll(s => s == e.OldItems.Cast<string>().First());
_addedSections.RemoveAll(s => s == e.OldItems.Cast<string>().First());
_removedSections.Remove(item);
_addedSections.Remove(item);
//add to the added sections
_removedSections.Add(e.OldItems.Cast<string>().First());
_removedSections.Add(item);
}
}
public override object DeepClone()
{
var clone = (User)base.DeepClone();
//need to create new collections otherwise they'll get copied by ref
clone._addedSections = new List<string>();
clone._removedSections = new List<string>();
clone._sectionCollection = new ObservableCollection<string>();
//re-create the event handler
clone._sectionCollection.CollectionChanged += clone.SectionCollectionChanged;
clone.ResetDirtyProperties(false);
return clone;
}
/// <summary>
/// Internal class used to wrap the user in a profile
/// </summary>