public ActionResult Create() { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCampaigns)) return AccessDeniedView(); var model = new CampaignModel(); PrepareCampaignModel(model, null, false); return View(model); }
private void PrepareCampaignModel(CampaignModel model, Campaign campaign, bool excludeProperties) { model.AvailableStores = _storeService.GetAllStores().Select(s => s.ToModel()).ToList(); model.AllowedTokens = string.Join(", ", _messageTokenProvider.GetListOfCampaignAllowedTokens()); if (!excludeProperties) { if (campaign != null) model.SelectedStoreIds = _storeMappingService.GetStoresIdsWithAccess(campaign); else model.SelectedStoreIds = new int[0]; } if (campaign != null) { model.CreatedOn = _dateTimeHelper.ConvertToUserTime(campaign.CreatedOnUtc, DateTimeKind.Utc); } }
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); _storeMappingService.SaveStoreMappings<Campaign>(campaign, model.SelectedStoreIds); NotifySuccess(_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 PrepareCampaignModel(model, null, true); return View(model); }
public ActionResult SendMassEmail(CampaignModel model) { 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"); model.AllowedTokens = FormatTokens(_messageTokenProvider.GetListOfCampaignAllowedTokens()); try { var emailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId); if (emailAccount == null) throw new SmartException("Email account could not be loaded"); var subscriptions = _newsLetterSubscriptionService.GetAllNewsLetterSubscriptions(null, 0 ,int.MaxValue, false); var totalEmailsSent = _campaignService.SendCampaign(campaign, emailAccount, subscriptions); NotifySuccess(string.Format(_localizationService.GetResource("Admin.Promotions.Campaigns.MassEmailSentToCustomers"), totalEmailsSent), false); return View(model); } catch (Exception exc) { NotifyError(exc, false); } //If we got this far, something failed, redisplay form return View(model); }
public ActionResult SendTestEmail(CampaignModel model) { 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"); model.AllowedTokens = FormatTokens(_messageTokenProvider.GetListOfCampaignAllowedTokens()); try { var emailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId); if (emailAccount == null) throw new SmartException("Email account could not be loaded"); var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmail(model.TestEmail); if (subscription != null) { //there's a subscription. let's use it var subscriptions = new List<NewsLetterSubscription>(); subscriptions.Add(subscription); _campaignService.SendCampaign(campaign, emailAccount, subscriptions); } else { //no subscription found _campaignService.SendCampaign(campaign, emailAccount, model.TestEmail); } NotifySuccess(_localizationService.GetResource("Admin.Promotions.Campaigns.TestEmailSentToCustomers"), false); return View(model); } catch (Exception exc) { NotifyError(exc, false); } //If we got this far, something failed, redisplay form return View(model); }
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); 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 model.AllowedTokens = FormatTokens(_messageTokenProvider.GetListOfCampaignAllowedTokens()); return View(model); }
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); NotifySuccess(_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()); return View(model); }
public ActionResult Create() { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCampaigns)) return AccessDeniedView(); var model = new CampaignModel(); model.AllowedTokens = FormatTokens(_messageTokenProvider.GetListOfCampaignAllowedTokens()); return View(model); }
public ActionResult SendTestEmail(CampaignModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCampaigns)) return AccessDeniedView(); var campaign = _campaignService.GetCampaignById(model.Id); if (campaign == null) return RedirectToAction("List"); PrepareCampaignModel(model, campaign, false); try { var emailAccount = _emailAccountService.GetDefaultEmailAccount(); if (emailAccount == null) throw new SmartException(T("Common.Error.NoEmailAccount")); var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmail(model.TestEmail); if (subscription != null) { // there's a subscription. let's use it var subscriptions = new List<NewsLetterSubscription>(); subscriptions.Add(subscription); _campaignService.SendCampaign(campaign, emailAccount, subscriptions); } else { //no subscription found _campaignService.SendCampaign(campaign, emailAccount, model.TestEmail); } NotifySuccess(T("Admin.Promotions.Campaigns.TestEmailSentToCustomers"), false); return View(model); } catch (Exception exc) { NotifyError(exc, false); } //If we got this far, something failed, redisplay form return View(model); }
public ActionResult SendMassEmail(CampaignModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCampaigns)) return AccessDeniedView(); var campaign = _campaignService.GetCampaignById(model.Id); if (campaign == null) return RedirectToAction("List"); PrepareCampaignModel(model, campaign, false); try { var emailAccount = _emailAccountService.GetDefaultEmailAccount(); if (emailAccount == null) throw new SmartException(T("Common.Error.NoEmailAccount")); var subscriptions = _newsLetterSubscriptionService.GetAllNewsLetterSubscriptions(null, 0 , int.MaxValue, false); var totalEmailsSent = _campaignService.SendCampaign(campaign, emailAccount, subscriptions); NotifySuccess(string.Format(_localizationService.GetResource("Admin.Promotions.Campaigns.MassEmailSentToCustomers"), totalEmailsSent), false); return View(model); } catch (Exception exc) { NotifyError(exc, false); } //If we got this far, something failed, redisplay form return View(model); }