public StorageUserModel(IStorage storage, StorageContext storageContext, Guid id) : base(storage, storageContext, id) { this.accounts = new StorageEntityCollection<StorageAccountModel, IAccountModel>(storageContext) { FetchIdCollection = () => storage.User.GetAccounts(id), GetId = account => account.Id, GetModel = storageContext.InternalAccounts.InternalFind, ReverseAdd = account => account.InternalUsers.CacheAdd(this), ReverseRemove = account => account.InternalUsers.CacheRemove(this), SaveAdd = account => storage.Account.Add(account.Id, id), SaveRemove = account => storage.Account.Remove(account.Id, id), }; }
public StorageListModel(IStorage storage, StorageContext storageContext, Guid listId) : base(storage, storageContext, listId) { this.followers = new StorageEntityCollection<StorageAccountModel, IAccountModel>(storageContext) { FetchIdCollection = () => storage.List.GetFollowingAccounts(listId), GetId = account => account.Id, GetModel = storageContext.InternalAccounts.InternalFind, ReverseAdd = account => { // TODO: this shouldn't involve storage calls account.InternalAllFollowedLists.CacheAdd(this); if (!this.IsPrivate) { account.InternalPublicFollowedLists.CacheAdd(this); } }, ReverseRemove = account => { // TODO: this shouldn't involve storage calls account.InternalAllFollowedLists.CacheRemove(this); if (!this.IsPrivate) { account.InternalPublicFollowedLists.CacheRemove(this); } }, SaveAdd = account => storage.List.Follow(listId, account.Id), SaveRemove = account => storage.List.Unfollow(listId, account.Id) }; this.members = new StorageEntityCollection<StorageAccountModel, IAccountModel>(storageContext) { FetchIdCollection = () => storage.List.GetAccounts(listId), GetId = account => account.Id, GetModel = storageContext.InternalAccounts.InternalFind, ReverseAdd = account => account.InternalMemberOfLists.CacheAdd(this), ReverseRemove = account => account.InternalMemberOfLists.CacheRemove(this), SaveAdd = account => storage.List.Add(listId, account.Id), SaveRemove = account => storage.List.Remove(listId, account.Id) }; }