コード例 #1
0
        protected override async Task HandleInput(SubscriptionDeleteParams input)
        {
            using (var conenction = database.GetConnection()) {
                ISpaceRepo        spaceRepo = database.GetRepo <ISpaceRepo>(conenction);
                ISubscriptionRepo subRepo   = database.GetRepo <ISubscriptionRepo>(conenction);

                //Pull in the space first
                Space?space = await spaceRepo.FindByName(input.Space);

                if (space == null)
                {
                    throw new InvalidOperationException($"No space with name {input.Space} exists.");
                }

                //Try to pull in the subscription
                Subscription?sub = await subRepo.FindByUserAndSpace(input.User.Username, input.Space);

                if (sub == null)
                {
                    throw new InvalidOperationException("Subscription does not exist");
                }

                await subRepo.Delete(sub);

                space.SubscriptionCount--;

                await spaceRepo.Update(space);
            }
        }
コード例 #2
0
        public async Task DeleteSubscription(string space, User user) {
            Subscription? s = await repo.FindByUserAndSpace(user.Username, space);

            if (s == null) {
                throw new NotFoundException($"No subscription for {space} found.");
            }

            await repo.Delete(s);
            await bus.Dispatch(new SubscriptionDeleteEvent(s));
        }
コード例 #3
0
        protected override async Task <SubscriptionView> HandleInput(SubscriptionCreateParams input)
        {
            using (var connection = database.GetConnection()) {
                ISpaceRepo        spaceRepo = database.GetRepo <ISpaceRepo>(connection);
                ISubscriptionRepo subRepo   = database.GetRepo <ISubscriptionRepo>(connection);

                //Check to see if the Space exists first
                Space?space = await spaceRepo.FindByName(input.Space);

                if (space == null)
                {
                    throw new InvalidOperationException($"No space with name {input.Space} exists.");
                }

                //Ensure no sub for this combo is already in place
                Subscription?existingSub = await subRepo.FindByUserAndSpace(input.User.Username, input.Space);

                if (existingSub != null)
                {
                    return(subscriptionMapper.Map(existingSub));
                }

                //Create the subscription
                Subscription sub = new Subscription()
                {
                    Space = space,
                    User  = input.User
                };

                await subRepo.Add(sub);

                //Update sub count
                space.SubscriptionCount++;

                await spaceRepo.Update(space);

                return(subscriptionMapper.Map(sub));
            }
        }