public void Update(UserAccount user, int subscriptionId, string newName, string newDescription, int?newParentFolderId) { var subscription = Get(user, subscriptionId); if (subscription == null) { throw new ArgumentException("Subscription not found"); } subscription.Name = newName; subscription.Description = newDescription; subscription.ParentFolderId = newParentFolderId; ValidateName(subscription.Name, subscription.ParentFolderId, subscriptionId); dataContext.SaveChanges(); SubscriptionUpdated?.Invoke(this, new SubscriptionUpdatedEventArgs() { User = user, Subscription = subscription }); }
public void UpdateFilter() { System.Console.WriteLine($"Subscription Filter updated to display related Subscriptions"); SubscriptionUpdated?.Invoke(this, EventArgs.Empty); }
public async Task DeleteFolders(UserAccount userAccount, int[] ids, bool recursive, bool deleteFiles) { if (recursive) { if (deleteFiles) { await DeleteSubscriptionFolderFilesJob.Schedule(scheduler, ids, true); } else { DeleteFoldersInternal(userAccount, ids); } } else { // Reparent subscriptions and folders (move them to the parent) var folders = dataContext.SubscriptionFolders.AsQueryable() .Where(x => x.UserId == userAccount.Id) .Where(x => ids.Contains(x.Id)) .ToArray(); foreach (var folder in folders) { dataContext.SubscriptionFolders.AsQueryable() .Where(x => x.ParentId.HasValue && x.ParentId.Value == folder.Id) .ForEach(x => { x.ParentId = folder.ParentId; FolderUpdated?.Invoke(this, new SubscriptionFolderUpdatedEventArgs() { User = userAccount, Folder = x }); }); dataContext.Subscriptions.AsQueryable() .Where(x => x.ParentFolderId.HasValue && x.ParentFolderId.Value == folder.Id) .ForEach(x => { x.ParentFolderId = folder.ParentId; SubscriptionUpdated?.Invoke(this, new SubscriptionUpdatedEventArgs() { User = userAccount, Subscription = x }); }); } // Delete folders var foldersToDelete = dataContext.SubscriptionFolders.AsQueryable() .Where(x => ids.Contains(x.Id)); dataContext.SubscriptionFolders.RemoveRange(foldersToDelete); dataContext.SaveChanges(); FoldersDeleted?.Invoke(this, new SubscriptionFoldersDeletedEventArgs() { User = userAccount, FolderIds = ids }); } }
private void NotifySubscriptionUpdated(ApiSubscription subscription) { SubscriptionUpdated?.Invoke(this, subscription); }