示例#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 ActionResult Unsubscribe(Guid subID)
 {
     if (_subscriptionRepo.Get(subID) == null)
     {
         ModelState.AddModelError("SubscriptionError", $"SubscriptionID: {subID} not found");
         return(NotFound(ModelState));
     }
     _subscriptionRepo.Delete(subID);
     return(Ok());
 }
        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));
        }