コード例 #1
0
        public void UnSubscribe(EmailSubscriptionViewModel subscription)
        {
            if (Request.IsAjaxRequest())
            {
                try
                {
                    // Add logic to add subscr
                    var isCategory = subscription.SubscriptionType.Contains("category");
                    var isTag      = subscription.SubscriptionType.Contains("tag");
                    var id         = subscription.Id;
                    var dbUser     = MembershipService.GetUser(User.Identity.Name);
                    if (isCategory)
                    {
                        // get the category
                        var cat = _categoryService.Get(id);

                        if (cat != null)
                        {
                            // get the notifications by user
                            var notifications =
                                _categoryNotificationService.GetByUserAndCategory(dbUser, cat, true);

                            if (notifications.Any())
                            {
                                foreach (var categoryNotification in notifications)
                                {
                                    // Delete
                                    _categoryNotificationService.Delete(categoryNotification);
                                }
                            }
                        }
                    }
                    else if (isTag)
                    {
                        // get the tag
                        var tag = _topicTagService.Get(id);

                        if (tag != null)
                        {
                            // get the notifications by user
                            var notifications =
                                _tagNotificationService.GetByUserAndTag(dbUser, tag, true);

                            if (notifications.Any())
                            {
                                foreach (var n in notifications)
                                {
                                    // Delete
                                    _tagNotificationService.Delete(n);
                                }
                            }
                        }
                    }
                    else
                    {
                        // get the topic
                        var topic = _topicService.Get(id);

                        if (topic != null)
                        {
                            // get the notifications by user
                            var notifications =
                                _topicNotificationService.GetByUserAndTopic(dbUser, topic, true);

                            if (notifications.Any())
                            {
                                foreach (var topicNotification in notifications)
                                {
                                    // Delete
                                    _topicNotificationService.Delete(topicNotification);
                                }
                            }
                        }
                    }

                    Context.SaveChanges();
                }
                catch (Exception ex)
                {
                    Context.RollBack();
                    LoggingService.Error(ex);
                    throw new Exception(LocalizationService.GetResourceString("Errors.GenericMessage"));
                }
            }
            else
            {
                throw new Exception(LocalizationService.GetResourceString("Errors.GenericMessage"));
            }
        }
コード例 #2
0
ファイル: EmailController.cs プロジェクト: yaobos/mvcforum
        public void UnSubscribe(UnSubscribeEmailViewModel subscription)
        {
            if (Request.IsAjaxRequest())
            {
                using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
                {
                    try
                    {
                        // Add logic to add subscr
                        var isCategory = subscription.SubscriptionType.Contains("category");
                        var isTag      = subscription.SubscriptionType.Contains("tag");
                        var id         = subscription.Id;
                        var dbUser     = MembershipService.GetUser(LoggedOnReadOnlyUser.Id);
                        if (isCategory)
                        {
                            // get the category
                            var cat = _categoryService.Get(id);

                            if (cat != null)
                            {
                                // get the notifications by user
                                var notifications = _categoryNotificationService.GetByUserAndCategory(LoggedOnReadOnlyUser, cat, true);

                                if (notifications.Any())
                                {
                                    foreach (var categoryNotification in notifications)
                                    {
                                        // Delete
                                        _categoryNotificationService.Delete(categoryNotification);
                                    }
                                }
                            }
                        }
                        else if (isTag)
                        {
                            // get the tag
                            var tag = _topicTagService.Get(id);

                            if (tag != null)
                            {
                                // get the notifications by user
                                var notifications = _tagNotificationService.GetByUserAndTag(LoggedOnReadOnlyUser, tag, true);

                                if (notifications.Any())
                                {
                                    foreach (var n in notifications)
                                    {
                                        // Delete
                                        _tagNotificationService.Delete(n);
                                    }
                                }
                            }
                        }
                        else
                        {
                            // get the topic
                            var topic = _topicService.Get(id);

                            if (topic != null)
                            {
                                // get the notifications by user
                                var notifications = _topicNotificationService.GetByUserAndTopic(LoggedOnReadOnlyUser, topic, true);

                                if (notifications.Any())
                                {
                                    foreach (var topicNotification in notifications)
                                    {
                                        // Delete
                                        _topicNotificationService.Delete(topicNotification);
                                    }
                                }
                            }
                        }

                        unitOfWork.Commit();
                    }
                    catch (Exception ex)
                    {
                        unitOfWork.Rollback();
                        LoggingService.Error(ex);
                        throw new Exception(LocalizationService.GetResourceString("Errors.GenericMessage"));
                    }
                }
            }
            else
            {
                throw new Exception(LocalizationService.GetResourceString("Errors.GenericMessage"));
            }
        }