Ejemplo n.º 1
0
        public APIResult UnsubscribeEvent(SubscribeUserModel model)
        {
            try
            {
                if (model == null)
                    throw new Exception("Please pass model");

                using (var bo = new ApplicationBusinessObject())
                {
                    if (!bo.Check(model.ApplicationId, model.ApplicationSecretKey))
                        throw new Exception("Invalid application credentials");
                }

                int eventId;
                using (var bo = new EventBusinessObject())
                {
                    var ev = bo.GetByKey(model.ApplicationId, model.EventKey);
                    if (ev == null)
                        throw new Exception("Event not found");

                    eventId = ev.Id;
                }

                int userId;
                using (var bo = new UserBusinessObject())
                {
                    var user = bo.GetByExternalUserId(model.ApplicationId, model.ExternalUserId);
                    if (user == null)
                        throw new Exception("User not found");

                    userId = user.Id;
                }

                Provider provider;
                using (var bo = new ProviderBusinessObject())
                {
                    provider = bo.GetByKey(model.ProviderKey);
                    if (provider == null)
                        throw new Exception("Provider not found");
                }

                var subscription = new Subscription
                {
                    EventId = eventId,
                    UserId = userId,
                    ProviderId = provider.Id
                };

                using (var bo = new SubscriptionBusinessObject())
                {
                    bo.Unsubscribe(subscription);
                }

            }
            catch (Exception ex)
            {
                return new APIResult(ex.Message, ex.ToString());
            }

            return new APIResult();
        }
Ejemplo n.º 2
0
        public APIResult<List<SubscriptionResult>> Subscriptions(GetSubscriptionsModel model)
        {
            try
            {
                if (model == null)
                    throw new Exception("Please pass model");

                using (var bo = new ApplicationBusinessObject())
                {
                    if (!bo.Check(model.ApplicationId, model.ApplicationSecretKey))
                        throw new Exception("Invalid application credentials");
                }

                var eventKeys = new List<string>();
                var providerKeys = new List<string>();
                var userKeys = new List<string>();

                if (!String.IsNullOrEmpty(model.EventKeys))
                    eventKeys = model.EventKeys.Split(',').ToList();

                if (!String.IsNullOrEmpty(model.ProviderKeys))
                    providerKeys = model.ProviderKeys.Split(',').ToList();

                if (!String.IsNullOrEmpty(model.ExternalUserIds))
                    userKeys = model.ExternalUserIds.Split(',').ToList();

                using (var bo = new SubscriptionBusinessObject())
                {
                    var items = bo.GetList(model.ApplicationId, eventKeys, providerKeys, userKeys);

                    var result = items.Select(x => new SubscriptionResult
                    {
                        EventKey = x.Event.Key,
                        ProviderKey = x.Provider.Key,
                        ExternalUserId = x.User.ExternalUserId
                    }).ToList();

                    return new APIResult<List<SubscriptionResult>>(result);
                }

            }
            catch (Exception ex)
            {
                return new APIResult<List<SubscriptionResult>>(ex.Message, ex.ToString());
            }
        }