Example #1
0
        public async Task <IActionResult> SubscriptionDelete(string id)
        {
            var subscription = await _newsLetterSubscriptionService.GetNewsLetterSubscriptionById(id);

            if (subscription == null)
            {
                throw new ArgumentException("No subscription found with the specified id");
            }
            await _newsLetterSubscriptionService.DeleteNewsLetterSubscription(subscription);

            return(new NullJsonResult());
        }
        public ActionResult SubscriptionDelete(int id, GridCommand command)
        {
            var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionById(id);

            _newsLetterSubscriptionService.DeleteNewsLetterSubscription(subscription);

            var listModel = new NewsLetterSubscriptionListModel();

            PrepareNewsLetterSubscriptionListModel(listModel);

            return(SubscriptionList(command, listModel));
        }
        public ActionResult SubscriptionDelete(int id, GridCommand command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageNewsletterSubscribers))
            {
                return(AccessDeniedView());
            }

            var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionById(id);

            _newsLetterSubscriptionService.DeleteNewsLetterSubscription(subscription);

            return(SubscriptionList(command, new NewsLetterSubscriptionListModel()));
        }
        public async Task DeleteNewsLetterSubscription_InvokeRepositoryAndEmailUnsubscribedEvent()
        {
            var email = "*****@*****.**";
            var newsLetterSubscription = new NewsLetterSubscription()
            {
                Email = email, Active = false
            };
            await _newsLetterSubscriptionService.DeleteNewsLetterSubscription(newsLetterSubscription);

            _subscriptionRepository.Verify(r => r.DeleteAsync(newsLetterSubscription), Times.Once);
            _mediatorMock.Verify(m => m.Publish <EmailUnsubscribedEvent>(It.IsAny <EmailUnsubscribedEvent>(), default(CancellationToken)), Times.Once);
            _mediatorMock.Verify(c => c.Publish(It.IsAny <EntityDeleted <NewsLetterSubscription> >(), default(CancellationToken)), Times.Once);
        }
        public virtual IActionResult SubscriptionDelete(int id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageNewsletterSubscribers))
            {
                return(AccessDeniedView());
            }

            var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionById(id)
                               ?? throw new ArgumentException("No subscription found with the specified id", nameof(id));

            _newsLetterSubscriptionService.DeleteNewsLetterSubscription(subscription);

            return(new NullJsonResult());
        }
Example #6
0
        public ActionResult SubscriptionDelete(int id, GridCommand command)
        {
            if (_permissionService.Authorize(StandardPermissionProvider.ManageNewsletterSubscribers))
            {
                var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionById(id);

                _newsLetterSubscriptionService.DeleteNewsLetterSubscription(subscription);
            }

            var listModel = new NewsLetterSubscriptionListModel();

            PrepareNewsLetterSubscriptionListModel(listModel);

            return(SubscriptionList(command, listModel));
        }
        public ActionResult SubscriptionDelete(int id, GridCommand command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageNewsletterSubscribers))
            {
                return(AccessDeniedView());
            }

            var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionById(id);

            if (subscription == null)
            {
                throw new ArgumentException("No subscription found with the specified id");
            }
            _newsLetterSubscriptionService.DeleteNewsLetterSubscription(subscription);

            return(SubscriptionList(command, new NewsLetterSubscriptionListModel()));
        }
        public virtual void DeleteAccount(Customer customer)
        {
            //send notification to customer
            _workflowMessageService.SendCustomerDeleteStoreOwnerNotification(customer, EngineContext.Current.Resolve <LocalizationSettings>().DefaultAdminLanguageId);

            //delete emails
            EngineContext.Current.Resolve <IQueuedEmailService>().DeleteCustomerEmail(customer.Email);

            //delete newsletter subscription
            var newsletter = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(customer.Email, _storeContext.CurrentStore.Id);

            if (newsletter != null)
            {
                _newsLetterSubscriptionService.DeleteNewsLetterSubscription(newsletter);
            }

            //delete account
            EngineContext.Current.Resolve <ICustomerService>().DeleteCustomer(customer);
        }
Example #9
0
        public virtual async Task DeleteAccount(Customer customer)
        {
            //send notification to customer
            await _workflowMessageService.SendCustomerDeleteStoreOwnerNotification(customer, _serviceProvider.GetRequiredService <LocalizationSettings>().DefaultAdminLanguageId);

            //delete emails
            await _serviceProvider.GetRequiredService <IQueuedEmailService>().DeleteCustomerEmail(customer.Email);

            //delete newsletter subscription
            var newsletter = await _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(customer.Email, _storeContext.CurrentStore.Id);

            if (newsletter != null)
            {
                await _newsLetterSubscriptionService.DeleteNewsLetterSubscription(newsletter);
            }

            //delete account
            await _serviceProvider.GetRequiredService <ICustomerService>().DeleteCustomer(customer);
        }
        public virtual async Task <SubscriptionActivationModel> PrepareSubscriptionActivation(NewsLetterSubscription subscription, bool active)
        {
            var model = new SubscriptionActivationModel();

            if (active)
            {
                subscription.Active = true;
                await _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscription);
            }
            else
            {
                await _newsLetterSubscriptionService.DeleteNewsLetterSubscription(subscription);
            }

            model.Result = active
                ? _localizationService.GetResource("Newsletter.ResultActivated")
                : _localizationService.GetResource("Newsletter.ResultDeactivated");

            return(model);
        }
Example #11
0
        public async Task <bool> Handle(DeleteAccountCommand request, CancellationToken cancellationToken)
        {
            //send notification to customer
            await _workflowMessageService.SendCustomerDeleteStoreOwnerNotification(request.Customer, _localizationSettings.DefaultAdminLanguageId);

            //delete emails
            await _queuedEmailService.DeleteCustomerEmail(request.Customer.Email);

            //delete newsletter subscription
            var newsletter = await _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(request.Customer.Email, request.Store.Id);

            if (newsletter != null)
            {
                await _newsLetterSubscriptionService.DeleteNewsLetterSubscription(newsletter);
            }

            //delete account
            await _customerService.DeleteCustomer(request.Customer);

            return(true);
        }
Example #12
0
        public virtual ActionResult SubscriptionActivation(Guid token, bool active)
        {
            var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByGuid(token);

            if (subscription == null)
            {
                return(RedirectToRoute("HomePage"));
            }

            if (active)
            {
                subscription.Active = true;
                _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscription);
            }
            else
            {
                _newsLetterSubscriptionService.DeleteNewsLetterSubscription(subscription);
            }

            var model = _newsletterModelFactory.PrepareSubscriptionActivationModel(active);

            return(View(model));
        }
        public virtual Models.Newsletter.SubscriptionActivationModel SubscriptionActivation(Guid token, bool active)
        {
            var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByGuid(token);

            if (subscription == null)
            {
                return(null);
            }

            if (active)
            {
                subscription.Active = true;
                _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscription);
            }
            else
            {
                _newsLetterSubscriptionService.DeleteNewsLetterSubscription(subscription);
            }

            var model = _newsletterModelFactory.PrepareSubscriptionActivationModel(active);

            return(model);
        }
Example #14
0
        public ActionResult SubscriptionActivation(Guid token, bool active)
        {
            var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByGuid(token);

            if (subscription == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            var model = new SubscriptionActivationModel();

            if (active)
            {
                subscription.Active = active;
                _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscription);

                if (subscription.RegistrationType == "promoted5")
                {
                    StatefulStorage.PerSession.Add <Guid>("newslettersubscriptiontoken", () => token);
                    return(RedirectToAction("NewsletterPromotedDynasty"));
                }
            }
            else
            {
                _newsLetterSubscriptionService.DeleteNewsLetterSubscription(subscription);
            }

            if (active)
            {
                model.Result = _localizationService.GetResource("Newsletter.ResultActivated");
            }
            else
            {
                model.Result = _localizationService.GetResource("Newsletter.ResultDeactivated");
            }

            return(View(model));
        }
        /// <summary>
        /// Delete unsubscribed user (in SendInBlue) from nopCommerce subscription list
        /// </summary>
        /// <param name="unsubscriberUser">User information</param>
        public void UnsubscribeWebhook(string unsubscriberUser)
        {
            if (!IsConfigured)
            {
                return;
            }

            //parse string to JSON object
            dynamic unsubscriber = JObject.Parse(unsubscriberUser);

            //we pass the store identifier in the X-Mailin-Tag at sending emails, now get it here
            int storeId;

            if (!int.TryParse(unsubscriber.tag, out storeId))
            {
                return;
            }

            var store = _storeService.GetStoreById(storeId);

            if (store == null)
            {
                return;
            }

            //get subscription by email and store identifier
            var email        = (string)unsubscriber.email;
            var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(email, store.Id);

            if (subscription != null)
            {
                //delete subscription
                _newsLetterSubscriptionService.DeleteNewsLetterSubscription(subscription, false);
                _logger.Information(string.Format("SendInBlue unsubscription: email {0}, store {1}, date {2}",
                                                  email, store.Name, (string)unsubscriber.date_event));
            }
        }
        public ActionResult Index(string webHookKey)
        {
            if (String.IsNullOrWhiteSpace(_settings.WebHookKey))
            {
                return(Content("Invalid Request."));
            }
            if (!string.Equals(_settings.WebHookKey, webHookKey, StringComparison.InvariantCultureIgnoreCase))
            {
                return(Content("Invalid Request."));
            }

            if (IsUnsubscribe())
            {
                var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmail(FindEmail());

                if (subscription != null)
                {
                    // Do not publish unsubscribe event. Or duplicate events will occur.
                    _newsLetterSubscriptionService.DeleteNewsLetterSubscription(subscription, false);
                    return(Content("OK"));
                }
            }
            return(Content("Invalid Request."));
        }
        public async Task <bool> Handle(DeleteAccountCommand request, CancellationToken cancellationToken)
        {
            //activity log
            await _customerActivityService.InsertActivity("PublicStore.DeleteAccount", "", _translationService.GetResource("ActivityLog.DeleteAccount"), request.Customer);

            //send notification to customer
            await _messageProviderService.SendCustomerDeleteStoreOwnerMessage(request.Customer, _languageSettings.DefaultAdminLanguageId);

            //delete emails
            await _queuedEmailService.DeleteCustomerEmail(request.Customer.Email);

            //delete newsletter subscription
            var newsletter = await _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(request.Customer.Email, request.Store.Id);

            if (newsletter != null)
            {
                await _newsLetterSubscriptionService.DeleteNewsLetterSubscription(newsletter);
            }

            //delete account
            await _customerService.DeleteCustomer(request.Customer);

            return(true);
        }
Example #18
0
        /// <summary>
        /// Permanent delete of customer
        /// </summary>
        /// <param name="customer">Customer</param>
        public virtual void PermanentDeleteCustomer(Customer customer)
        {
            if (customer == null)
            {
                throw new ArgumentNullException(nameof(customer));
            }

            //blog comments
            var blogComments = _blogService.GetAllComments(customerId: customer.Id);

            _blogService.DeleteBlogComments(blogComments);

            //news comments
            var newsComments = _newsService.GetAllComments(customerId: customer.Id);

            _newsService.DeleteNewsComments(newsComments);



            //external authentication record
            foreach (var ear in customer.ExternalAuthenticationRecords)
            {
                _externalAuthenticationService.DeleteExternalAuthenticationRecord(ear);
            }

            //forum subscriptions
            var forumSubscriptions = _forumService.GetAllSubscriptions(customer.Id);

            foreach (var forumSubscription in forumSubscriptions)
            {
                _forumService.DeleteSubscription(forumSubscription);
            }


            //private messages (sent)
            foreach (var pm in _forumService.GetAllPrivateMessages(0, customer.Id, 0, null, null, null, null))
            {
                _forumService.DeletePrivateMessage(pm);
            }

            //private messages (received)
            foreach (var pm in _forumService.GetAllPrivateMessages(0, 0, customer.Id, null, null, null, null))
            {
                _forumService.DeletePrivateMessage(pm);
            }

            //newsletter
            var allStores = _storeService.GetAllStores();

            foreach (var store in allStores)
            {
                var newsletter = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(customer.Email, store.Id);
                if (newsletter != null)
                {
                    _newsLetterSubscriptionService.DeleteNewsLetterSubscription(newsletter);
                }
            }

            //addresses
            foreach (var address in customer.Addresses)
            {
                _customerService.RemoveCustomerAddress(customer, address);
                _customerService.UpdateCustomer(customer);
                //now delete the address record
                _addressService.DeleteAddress(address);
            }

            //generic attributes
            var keyGroup          = customer.GetUnproxiedEntityType().Name;
            var genericAttributes = _genericAttributeService.GetAttributesForEntity(customer.Id, keyGroup);

            _genericAttributeService.DeleteAttributes(genericAttributes);

            //ignore ActivityLog
            //ignore ForumPost, ForumTopic, ignore ForumPostVote
            //ignore Log
            //ignore PollVotingRecord
            //ignore ProductReviewHelpfulness
            //ignore RecurringPayment
            //ignore ReturnRequest
            //ignore RewardPointsHistory
            //and we do not delete orders

            //remove from Registered role, add to Guest one
            if (customer.IsRegistered())
            {
                var registeredRole = _customerService.GetCustomerRoleBySystemName(GSCustomerDefaults.RegisteredRoleName);
                customer.CustomerCustomerRoleMappings
                .Remove(customer.CustomerCustomerRoleMappings.FirstOrDefault(mapping => mapping.CustomerRoleId == registeredRole.Id));
            }

            if (!customer.IsGuest())
            {
                var guestRole = _customerService.GetCustomerRoleBySystemName(GSCustomerDefaults.GuestsRoleName);
                customer.CustomerCustomerRoleMappings.Add(new CustomerCustomerRoleMapping {
                    CustomerRole = guestRole
                });
            }

            var email = customer.Email;

            //clear other information
            customer.Email             = string.Empty;
            customer.EmailToRevalidate = string.Empty;
            customer.Username          = string.Empty;
            customer.Active            = false;
            customer.Deleted           = true;
            _customerService.UpdateCustomer(customer);

            //raise event
            _eventPublisher.Publish(new CustomerPermanentlyDeleted(customer.Id, email));
        }
Example #19
0
        /// <summary>
        /// Permanent delete of customer
        /// </summary>
        /// <param name="customer">Customer</param>
        public virtual void PermanentDeleteCustomer(Customer customer)
        {
            if (customer == null)
            {
                throw new ArgumentNullException(nameof(customer));
            }

            //blog comments
            var blogComments = _blogService.GetAllComments(customerId: customer.Id);

            _blogService.DeleteBlogComments(blogComments);

            //news comments
            var newsComments = _newsService.GetAllComments(customerId: customer.Id);

            _newsService.DeleteNewsComments(newsComments);

            //back in stock subscriptions
            var backInStockSubscriptions = _backInStockSubscriptionService.GetAllSubscriptionsByCustomerId(customer.Id);

            foreach (var backInStockSubscription in backInStockSubscriptions)
            {
                _backInStockSubscriptionService.DeleteSubscription(backInStockSubscription);
            }

            //product review
            var productReviews   = _productService.GetAllProductReviews(customerId: customer.Id, approved: null);
            var reviewedProducts = _productService.GetProductsByIds(productReviews.Select(p => p.ProductId).Distinct().ToArray());

            _productService.DeleteProductReviews(productReviews);
            //update product totals
            foreach (var product in reviewedProducts)
            {
                _productService.UpdateProductReviewTotals(product);
            }

            //external authentication record
            foreach (var ear in customer.ExternalAuthenticationRecords)
            {
                _externalAuthenticationService.DeleteExternalAuthenticationRecord(ear);
            }

            //forum subscriptions
            var forumSubscriptions = _forumService.GetAllSubscriptions(customerId: customer.Id);

            foreach (var forumSubscription in forumSubscriptions)
            {
                _forumService.DeleteSubscription(forumSubscription);
            }

            //shopping cart items
            foreach (var sci in customer.ShoppingCartItems)
            {
                _shoppingCartService.DeleteShoppingCartItem(sci);
            }

            //private messages (sent)
            foreach (var pm in _forumService.GetAllPrivateMessages(storeId: 0, fromCustomerId: customer.Id, toCustomerId: 0,
                                                                   isRead: null, isDeletedByAuthor: null, isDeletedByRecipient: null, keywords: null))
            {
                _forumService.DeletePrivateMessage(pm);
            }
            //private messages (received)
            foreach (var pm in _forumService.GetAllPrivateMessages(storeId: 0, fromCustomerId: 0, toCustomerId: customer.Id,
                                                                   isRead: null, isDeletedByAuthor: null, isDeletedByRecipient: null, keywords: null))
            {
                _forumService.DeletePrivateMessage(pm);
            }

            //newsletter
            var allStores = _storeService.GetAllStores();

            foreach (var store in allStores)
            {
                var newsletter = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(customer.Email, store.Id);
                if (newsletter != null)
                {
                    _newsLetterSubscriptionService.DeleteNewsLetterSubscription(newsletter);
                }
            }

            //addresses
            foreach (var address in customer.Addresses)
            {
                customer.RemoveAddress(address);
                _customerService.UpdateCustomer(customer);
                //now delete the address record
                _addressService.DeleteAddress(address);
            }

            //generic attributes
            var keyGroup          = customer.GetUnproxiedEntityType().Name;
            var genericAttributes = _genericAttributeService.GetAttributesForEntity(customer.Id, keyGroup);

            _genericAttributeService.DeleteAttributes(genericAttributes);

            //ignore ActivityLog
            //ignore ForumPost, ForumTopic, ignore ForumPostVote
            //ignore Log
            //ignore PollVotingRecord
            //ignore ProductReviewHelpfulness
            //ignore RecurringPayment
            //ignore ReturnRequest
            //ignore RewardPointsHistory
            //and we do not delete orders

            //remove from Registered role, add to Guest one
            if (customer.IsRegistered())
            {
                var registeredRole = _customerService.GetCustomerRoleBySystemName(NopCustomerDefaults.RegisteredRoleName);
                customer.CustomerCustomerRoleMappings
                .Remove(customer.CustomerCustomerRoleMappings.FirstOrDefault(mapping => mapping.CustomerRoleId == registeredRole.Id));
            }
            if (!customer.IsGuest())
            {
                var guestRole = _customerService.GetCustomerRoleBySystemName(NopCustomerDefaults.GuestsRoleName);
                customer.CustomerCustomerRoleMappings.Add(new CustomerCustomerRoleMapping {
                    CustomerRole = guestRole
                });
            }

            var email = customer.Email;

            //clear other information
            customer.Email             = "";
            customer.EmailToRevalidate = "";
            customer.Username          = "";
            customer.Active            = false;
            customer.Deleted           = true;
            _customerService.UpdateCustomer(customer);

            //raise event
            _eventPublisher.Publish(new CustomerPermanentlyDeleted(customer.Id, email));
        }
Example #20
0
 /// <summary>
 /// Deletes a newsletter subscription
 /// </summary>
 /// <param name="newsLetterSubscription">NewsLetter subscription</param>
 /// <param name="publishSubscriptionEvents">if set to <c>true</c> [publish subscription events].</param>
 public void DeleteNewsLetterSubscription(NewsLetterSubscription newsLetterSubscription, bool publishSubscriptionEvents = true)
 {
     _newsLetterSubscriptionService.DeleteNewsLetterSubscription(newsLetterSubscription, publishSubscriptionEvents);
 }