Skip to content

Instantly share code, notes, and snippets.

@takeshik
Created April 4, 2011 02:24
Show Gist options
  • Save takeshik/901057 to your computer and use it in GitHub Desktop.
Save takeshik/901057 to your computer and use it in GitHub Desktop.
protected virtual Tuple<Activity, Boolean> CreateObject(Account account, IEnumerable<ActivityId> ancestorIds, String name, Object value)
{
ActivityId id = ActivityId.Create(account.Id, ancestorIds, name, value);
StorageObject obj;
Boolean created = false;
if ((obj = this.Load(id)) == null && !this.AddingObjects.TryGetValue(id, out obj))
{
obj = Activity.Create(account.Id, ancestorIds, name, value);
this.AddingObjects.Add(obj.ObjectId, obj);
obj.Context = this;
created = true;
}
else if (obj.Context == null || obj.Context.IsDisposed)
{
obj.Context = this;
}
Activity activity = (Activity) obj;
if (account.Activities.Contains(activity))
{
account.Activities.Add(activity);
}
return Tuple.Create(activity, created);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment