示例#1
0
        public async Task <IActionResult> DeleteCustomer(int id)
        {
            if (id <= 0)
            {
                return(Error(HttpStatusCode.BadRequest, "id", "invalid id"));
            }

            var customer = await _customerApiService.GetCustomerEntityByIdAsync(id);

            if (customer == null)
            {
                return(Error(HttpStatusCode.NotFound, "customer", "not found"));
            }

            await CustomerService.DeleteCustomerAsync(customer);

            //remove newsletter subscription (if exists)
            foreach (var store in await StoreService.GetAllStoresAsync())
            {
                var subscription = await _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreIdAsync(customer.Email, store.Id);

                if (subscription != null)
                {
                    await _newsLetterSubscriptionService.DeleteNewsLetterSubscriptionAsync(subscription);
                }
            }

            //activity log
            await CustomerActivityService.InsertActivityAsync("DeleteCustomer", await LocalizationService.GetResourceAsync("ActivityLog.DeleteCustomer"), customer);

            return(new RawJsonActionResult("{}"));
        }
        /// <returns>A task that represents the asynchronous operation</returns>
        public virtual async Task <IActionResult> SubscriptionDelete(int id)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageNewsletterSubscribers))
            {
                return(AccessDeniedView());
            }

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

            await _newsLetterSubscriptionService.DeleteNewsLetterSubscriptionAsync(subscription);

            return(new NullJsonResult());
        }
示例#3
0
        public virtual async Task <IActionResult> SubscriptionActivation(Guid token, bool active)
        {
            var subscription = await _newsLetterSubscriptionService.GetNewsLetterSubscriptionByGuidAsync(token);

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

            if (active)
            {
                subscription.Active = true;
                await _newsLetterSubscriptionService.UpdateNewsLetterSubscriptionAsync(subscription);
            }
            else
            {
                await _newsLetterSubscriptionService.DeleteNewsLetterSubscriptionAsync(subscription);
            }

            var model = await _newsletterModelFactory.PrepareSubscriptionActivationModelAsync(active);

            return(View(model));
        }