Пример #1
0
        List<Tuple<int?, string>> GetUserInfos(int applicationId, List<string> externalUserIds, int providerId)
        {
            var result = new List<Tuple<int?, string>>();

            foreach (var item in externalUserIds)
            {
                using (var bo = new UserBusinessObject())
                {
                    var user = bo.GetByExternalUserId(applicationId, item);
                    if (user == null)
                        continue;

                    var to = GetToByProvider(user, providerId);
                    if (String.IsNullOrEmpty(to))
                        continue;

                    result.Add(new Tuple<int?, string>(user.Id, to));
                }
            }

            return result;
        }
Пример #2
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();
        }