Esempio n. 1
0
        public virtual IActionResult Create(CampaignModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCampaigns))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var campaign = model.ToEntity();
                campaign.CreatedOnUtc          = DateTime.UtcNow;
                campaign.DontSendBeforeDateUtc = model.DontSendBeforeDate.HasValue ?
                                                 (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.DontSendBeforeDate.Value) : null;
                _campaignService.InsertCampaign(campaign);

                //activity log
                _customerActivityService.InsertActivity("AddNewCampaign",
                                                        string.Format(_localizationService.GetResource("ActivityLog.AddNewCampaign"), campaign.Id), campaign);

                SuccessNotification(_localizationService.GetResource("Admin.Promotions.Campaigns.Added"));
                return(continueEditing ? RedirectToAction("Edit", new { id = campaign.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            model.AllowedTokens = string.Join(", ", _messageTokenProvider.GetListOfCampaignAllowedTokens());
            //stores
            PrepareStoresModel(model);
            //customer roles
            PrepareCustomerRolesModel(model);
            //email accounts
            PrepareEmailAccountsModel(model);

            return(View(model));
        }
Esempio n. 2
0
        public virtual IActionResult Create(CampaignModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCampaigns))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var campaign = model.ToEntity <Campaign>();

                campaign.CreatedOnUtc          = DateTime.UtcNow;
                campaign.DontSendBeforeDateUtc = model.DontSendBeforeDate.HasValue ?
                                                 (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.DontSendBeforeDate.Value) : null;

                _campaignService.InsertCampaign(campaign);

                //activity log
                _customerActivityService.InsertActivity("AddNewCampaign",
                                                        string.Format(_localizationService.GetResource("ActivityLog.AddNewCampaign"), campaign.Id), campaign);

                _notificationService.SuccessNotification(_localizationService.GetResource("Admin.Promotions.Campaigns.Added"));

                return(continueEditing ? RedirectToAction("Edit", new { id = campaign.Id }) : RedirectToAction("List"));
            }

            //prepare model
            model = _campaignModelFactory.PrepareCampaignModel(model, null, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 3
0
        public ActionResult Edit(CampaignModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCampaigns))
            {
                return(AccessDeniedView());
            }

            var campaign = _campaignService.GetCampaignById(model.Id);

            if (campaign == null)
            {
                //No campaign found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                campaign = model.ToEntity(campaign);
                _campaignService.UpdateCampaign(campaign);

                SuccessNotification(_localizationService.GetResource("Admin.Promotions.Campaigns.Updated"));
                return(continueEditing ? RedirectToAction("Edit", new { id = campaign.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            model.AllowedTokens = FormatTokens(_messageTokenProvider.GetListOfCampaignAllowedTokens());
            return(View(model));
        }
Esempio n. 4
0
        public IActionResult Create(CampaignModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCampaigns))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var campaign = model.ToEntity();
                campaign.CreatedOnUtc = DateTime.UtcNow;
                _campaignService.InsertCampaign(campaign);

                SuccessNotification(_localizationService.GetResource("Admin.Promotions.Campaigns.Added"));
                return(continueEditing ? RedirectToAction("Edit", new { id = campaign.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            model.AllowedTokens = FormatTokens(_messageTokenProvider.GetListOfCampaignAllowedTokens());
            //stores
            PrepareStoresModel(model);
            //Tags
            PrepareCustomerTagsModel(model);
            //Newsletter categories
            PrepareNewsletterCategoriesModel(model);
            //Roles
            PrepareCustomerRolesModel(model);
            //email
            PrepareEmailAccounts(model);

            return(View(model));
        }
Esempio n. 5
0
        public ActionResult Edit(CampaignModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCampaigns))
            {
                return(AccessDeniedView());
            }

            var campaign = _campaignService.GetCampaignById(model.Id);

            if (campaign == null)
            {
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                campaign = model.ToEntity(campaign);
                _campaignService.UpdateCampaign(campaign);

                _storeMappingService.SaveStoreMappings <Campaign>(campaign, model.SelectedStoreIds);

                NotifySuccess(_localizationService.GetResource("Admin.Promotions.Campaigns.Updated"));
                return(continueEditing ? RedirectToAction("Edit", new { id = campaign.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            PrepareCampaignModel(model, campaign, true);

            return(View(model));
        }
Esempio n. 6
0
        public ActionResult Create(CampaignModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCampaigns))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var campaign = model.ToEntity();
                campaign.CreatedOnUtc = DateTime.UtcNow;
                _campaignService.InsertCampaign(campaign);

                UpdateLocales(campaign, model);
                SuccessNotification(_localizationService.GetResource("Admin.Promotions.Campaigns.Added"));
                return(continueEditing ? RedirectToAction("Edit", new { id = campaign.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            model.AllowedTokens = FormatTokens(_messageTokenProvider.GetListOfCampaignAllowedTokens());

            model.CategoriesTree = new List <TreeViewItemModel>();
            model.CategoriesTree = PrepareTreeView(model.CategoriesTree, 0);
            return(View(model));
        }
Esempio n. 7
0
        public ActionResult Edit(CampaignModel model, bool continueEditing)
        {
            var campaign = _campaignService.GetCampaignById(model.Id);

            if (campaign == null)
            {
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                campaign = model.ToEntity(campaign);
                _campaignService.UpdateCampaign(campaign);

                SaveAclMappings(campaign, model.SelectedCustomerRoleIds);
                SaveStoreMappings(campaign, model.SelectedStoreIds);

                NotifySuccess(T("Admin.Promotions.Campaigns.Updated"));
                return(continueEditing ? RedirectToAction("Edit", new { id = campaign.Id }) : RedirectToAction("List"));
            }

            PrepareCampaignModel(model, campaign);

            return(View(model));
        }
Esempio n. 8
0
        public virtual Campaign InsertCampaignModel(CampaignModel model)
        {
            var campaign = model.ToEntity();

            campaign.CreatedOnUtc = DateTime.UtcNow;
            _campaignService.InsertCampaign(campaign);
            return(campaign);
        }
Esempio n. 9
0
        public IActionResult Edit(CampaignModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCampaigns))
            {
                return(AccessDeniedView());
            }

            var campaign = _campaignService.GetCampaignById(model.Id);

            if (campaign == null)
            {
                //No campaign found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                campaign = model.ToEntity(campaign);
                campaign.CustomerRoles.Clear();
                foreach (var item in model.CustomerRoles)
                {
                    campaign.CustomerRoles.Add(item);
                }
                campaign.CustomerTags.Clear();
                foreach (var item in model.CustomerTags)
                {
                    campaign.CustomerTags.Add(item);
                }
                campaign.NewsletterCategories.Clear();
                foreach (var item in model.NewsletterCategories)
                {
                    campaign.NewsletterCategories.Add(item);
                }

                _campaignService.UpdateCampaign(campaign);

                SuccessNotification(_localizationService.GetResource("Admin.Promotions.Campaigns.Updated"));
                //selected tab
                SaveSelectedTabIndex();

                return(continueEditing ? RedirectToAction("Edit", new { id = campaign.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            model.AllowedTokens = FormatTokens(_messageTokenProvider.GetListOfCampaignAllowedTokens());
            //stores
            PrepareStoresModel(model);
            //Tags
            PrepareCustomerTagsModel(model);
            //Newsletter categories
            PrepareNewsletterCategoriesModel(model);
            //Roles
            PrepareCustomerRolesModel(model);
            //email
            PrepareEmailAccounts(model);
            return(View(model));
        }
Esempio n. 10
0
        public virtual async Task <Campaign> InsertCampaignModel(CampaignModel model)
        {
            var campaign = model.ToEntity();

            campaign.CreatedOnUtc = DateTime.UtcNow;
            await _campaignService.InsertCampaign(campaign);

            return(campaign);
        }
Esempio n. 11
0
        public ActionResult Create(CampaignModel model, bool continueEditing)
        {
            if (ModelState.IsValid)
            {
                var campaign = model.ToEntity();
                campaign.CreatedOnUtc = DateTime.UtcNow;
                _campaignService.InsertCampaign(campaign);

                SaveStoreMappings(campaign, model.SelectedStoreIds);

                NotifySuccess(T("Admin.Promotions.Campaigns.Added"));
                return(continueEditing ? RedirectToAction("Edit", new { id = campaign.Id }) : RedirectToAction("List"));
            }

            PrepareCampaignModel(model, null, true);

            return(View(model));
        }
Esempio n. 12
0
        public ActionResult Edit(CampaignModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCampaigns))
            {
                return(AccessDeniedView());
            }

            var campaign = _campaignService.GetCampaignById(model.Id);

            if (campaign == null)
            {
                //No campaign found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                campaign = model.ToEntity(campaign);
                campaign.DontSendBeforeDateUtc = model.DontSendBeforeDate.HasValue ?
                                                 (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.DontSendBeforeDate.Value) : null;
                _campaignService.UpdateCampaign(campaign);

                //activity log
                _customerActivityService.InsertActivity("EditCampaign", _localizationService.GetResource("ActivityLog.EditCampaign"), campaign.Id);

                SuccessNotification(_localizationService.GetResource("Admin.Promotions.Campaigns.Updated"));
                return(continueEditing ? RedirectToAction("Edit", new { id = campaign.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            model.AllowedTokens = FormatTokens(_messageTokenProvider.GetListOfCampaignAllowedTokens());
            //stores
            PrepareStoresModel(model);
            //customer roles
            PrepareCustomerRolesModel(model);
            //email accounts
            PrepareEmailAccountsModel(model);

            return(View(model));
        }
Esempio n. 13
0
        public virtual Campaign UpdateCampaignModel(Campaign campaign, CampaignModel model)
        {
            campaign = model.ToEntity(campaign);
            campaign.CustomerRoles.Clear();
            foreach (var item in model.CustomerRoles)
            {
                campaign.CustomerRoles.Add(item);
            }
            campaign.CustomerTags.Clear();
            foreach (var item in model.CustomerTags)
            {
                campaign.CustomerTags.Add(item);
            }
            campaign.NewsletterCategories.Clear();
            foreach (var item in model.NewsletterCategories)
            {
                campaign.NewsletterCategories.Add(item);
            }
            _campaignService.UpdateCampaign(campaign);

            return(campaign);
        }
        public virtual async Task <IActionResult> Edit(CampaignModel model, bool continueEditing)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageCampaigns))
            {
                return(AccessDeniedView());
            }

            //try to get a campaign with the specified id
            var campaign = await _campaignService.GetCampaignByIdAsync(model.Id);

            if (campaign == null)
            {
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                campaign = model.ToEntity(campaign);

                campaign.DontSendBeforeDateUtc = model.DontSendBeforeDate.HasValue ?
                                                 (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.DontSendBeforeDate.Value) : null;

                await _campaignService.UpdateCampaignAsync(campaign);

                //activity log
                await _customerActivityService.InsertActivityAsync("EditCampaign",
                                                                   string.Format(await _localizationService.GetResourceAsync("ActivityLog.EditCampaign"), campaign.Id), campaign);

                _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Promotions.Campaigns.Updated"));

                return(continueEditing ? RedirectToAction("Edit", new { id = campaign.Id }) : RedirectToAction("List"));
            }

            //prepare model
            model = await _campaignModelFactory.PrepareCampaignModelAsync(model, campaign, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
        public virtual async Task <Campaign> UpdateCampaignModel(Campaign campaign, CampaignModel model)
        {
            campaign = model.ToEntity(campaign);
            campaign.CustomerGroups.Clear();
            foreach (var item in model.CustomerGroups)
            {
                campaign.CustomerGroups.Add(item);
            }
            campaign.CustomerTags.Clear();
            foreach (var item in model.CustomerTags)
            {
                campaign.CustomerTags.Add(item);
            }
            campaign.NewsletterCategories.Clear();
            foreach (var item in model.NewsletterCategories)
            {
                campaign.NewsletterCategories.Add(item);
            }
            await _campaignService.UpdateCampaign(campaign);

            return(campaign);
        }
Esempio n. 16
0
        public ActionResult Create(CampaignModel model, bool continueEditing)
        {
            if (!Services.Permissions.Authorize(StandardPermissionProvider.ManageCampaigns))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var campaign = model.ToEntity();
                campaign.CreatedOnUtc = DateTime.UtcNow;
                _campaignService.InsertCampaign(campaign);

                SaveStoreMappings(campaign, model);

                NotifySuccess(T("Admin.Promotions.Campaigns.Added"));
                return(continueEditing ? RedirectToAction("Edit", new { id = campaign.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            PrepareCampaignModel(model, null, true);

            return(View(model));
        }