Exemple #1
0
        public APIResult<List<Event>> Events(ApplicationCredentialsModel 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");
                }

                using (var bo = new EventBusinessObject())
                {
                    var result = bo.GetList();

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

            }
            catch (Exception ex)
            {
                return new APIResult<List<Event>>(ex.Message, ex.ToString());
            }
        }
Exemple #2
0
        public APIResult DeleteEvent(DeleteEventModel 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");
                }

                using (var bo = new EventBusinessObject())
                {
                    bo.Delete(model.ApplicationId, model.EventKey);
                }
            }
            catch (Exception ex)
            {
                return new APIResult(ex.Message, ex.ToString());
            }

            return new APIResult();
        }
Exemple #3
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();
        }
Exemple #4
0
        public APIResult SaveEvent(SaveEventViewModel 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");
                }

                using (var bo = new EventBusinessObject())
                {
                    var item = new Event
                    {
                        ApplicationId = model.ApplicationId,
                        Key = model.Key,
                        Description = model.Description
                    };

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

            return new APIResult();
        }