public async Task Handle(UserRegisterEvent domainEvent) { IEnumerable <Space> defaultSpaces = await spaceRepo.FindDefault(); IEnumerable <Subscription> subs = defaultSpaces.Select(s => subscriptionFactory.CreateFor(domainEvent.User, s)); foreach (Subscription s in subs) { await subscriptionRepo.Add(s); } }
public async Task<Subscription> CreateSubscription(SubscriptionCreate create, User user) { Space? space = await spaceRepo.FindByName(create.Space); if (space == null) { throw new NotFoundException($"No space with name {create.Space} found."); } Subscription s = factory.CreateFor(user, space); await repo.Add(s); await bus.Dispatch(new SubscriptionCreateEvent(s)); return s; }