/// <summary>
        /// Prepare message template model
        /// </summary>
        /// <param name="model">Message template model</param>
        /// <param name="messageTemplate">Message template</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Message template model</returns>
        public virtual MessageTemplateModel PrepareMessageTemplateModel(MessageTemplateModel model,
                                                                        MessageTemplate messageTemplate, bool excludeProperties = false)
        {
            Action <MessageTemplateLocalizedModel, int> localizedModelConfiguration = null;

            if (messageTemplate != null)
            {
                //fill in model values from the entity
                model ??= messageTemplate.ToModel <MessageTemplateModel>();

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.BccEmailAddresses = _localizationService.GetLocalized(messageTemplate, entity => entity.BccEmailAddresses, languageId, false, false);
                    locale.Subject           = _localizationService.GetLocalized(messageTemplate, entity => entity.Subject, languageId, false, false);
                    locale.Body           = _localizationService.GetLocalized(messageTemplate, entity => entity.Body, languageId, false, false);
                    locale.EmailAccountId = _localizationService.GetLocalized(messageTemplate, entity => entity.EmailAccountId, languageId, false, false);

                    //prepare available email accounts
                    _baseAdminModelFactory.PrepareEmailAccounts(locale.AvailableEmailAccounts,
                                                                defaultItemText: _localizationService.GetResource("Admin.ContentManagement.MessageTemplates.Fields.EmailAccount.Standard"));

                    //PrepareEmailAccounts only gets available accounts, we need to set the item as selected manually
                    if (locale.AvailableEmailAccounts?.FirstOrDefault(x => x.Value == locale.EmailAccountId.ToString()) is SelectListItem emailAccountListItem)
                    {
                        emailAccountListItem.Selected = true;
                    }
                };
            }

            model.SendImmediately     = !model.DelayBeforeSend.HasValue;
            model.HasAttachedDownload = model.AttachedDownloadId > 0;

            var allowedTokens = string.Join(", ", _messageTokenProvider.GetListOfAllowedTokens(_messageTokenProvider.GetTokenGroups(messageTemplate)));

            model.AllowedTokens = $"{allowedTokens}{Environment.NewLine}{Environment.NewLine}" +
                                  $"{_localizationService.GetResource("Admin.ContentManagement.MessageTemplates.Tokens.ConditionalStatement")}{Environment.NewLine}";

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            //prepare available email accounts
            _baseAdminModelFactory.PrepareEmailAccounts(model.AvailableEmailAccounts);

            //prepare available stores
            _storeMappingSupportedModelFactory.PrepareModelStores(model, messageTemplate, excludeProperties);

            return(model);
        }
        public async Task <IActionResult> Create()
        {
            var model = new MessageTemplateModel();

            //Stores
            model.AllowedTokens = _messageTokenProvider.GetListOfAllowedTokens();
            //available email accounts
            foreach (var ea in await _emailAccountService.GetAllEmailAccounts())
            {
                model.AvailableEmailAccounts.Add(ea.ToModel());
            }

            return(View(model));
        }
Example #3
0
        public IActionResult Create()
        {
            var model = new MessageTemplateModel();

            //Stores
            model.PrepareStoresMappingModel(null, false, _storeService);
            model.AllowedTokens = _messageTokenProvider.GetListOfAllowedTokens();
            //available email accounts
            foreach (var ea in _emailAccountService.GetAllEmailAccounts())
            {
                model.AvailableEmailAccounts.Add(ea.ToModel());
            }

            return(View(model));
        }
Example #4
0
        /// <summary>
        /// Prepare message template model
        /// </summary>
        /// <param name="model">Message template model</param>
        /// <param name="messageTemplate">Message template</param>
        /// <returns>Message template model</returns>
        public virtual MessageTemplateModel PrepareMessageTemplateModel(MessageTemplateModel model,
                                                                        MessageTemplate messageTemplate)
        {
            if (messageTemplate != null)
            {
                //fill in model values from the entity
                model = model ?? messageTemplate.ToModel <MessageTemplateModel>();
            }

            var allowedTokens = string.Join(", ", _messageTokenProvider.GetListOfAllowedTokens(_messageTokenProvider.GetTokenGroups(messageTemplate)));

            model.AllowedTokens = $"{allowedTokens}{Environment.NewLine}{Environment.NewLine}For conditional expressions use the token %if (your conditions) ... endif%{Environment.NewLine}";

            return(model);
        }
Example #5
0
        public ActionResult Edit(int id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageMessageTemplates))
                return AccessDeniedView();

            var messageTemplate = _messageTemplateService.GetMessageTemplateById(id);
            if (messageTemplate == null)
                //No message template found with the specified id
                return RedirectToAction("List");
            
            var model = messageTemplate.ToModel();
            model.SendImmediately = !model.DelayBeforeSend.HasValue;
            model.HasAttachedDownload = model.AttachedDownloadId > 0;
            model.AllowedTokens = FormatTokens(_messageTokenProvider.GetListOfAllowedTokens());
            //available email accounts
            foreach (var ea in _emailAccountService.GetAllEmailAccounts())
                model.AvailableEmailAccounts.Add(new SelectListItem { Text = ea.DisplayName, Value = ea.Id.ToString() });
            //Store
            PrepareStoresMappingModel(model, messageTemplate, false);
            //locales
            AddLocales(_languageService, model.Locales, (locale, languageId) =>
            {
                locale.BccEmailAddresses = messageTemplate.GetLocalized(x => x.BccEmailAddresses, languageId, false, false);
                locale.Subject = messageTemplate.GetLocalized(x => x.Subject, languageId, false, false);
                locale.Body = messageTemplate.GetLocalized(x => x.Body, languageId, false, false);

                locale.EmailAccountId = messageTemplate.GetLocalized(x => x.EmailAccountId, languageId, false, false);
                //available email accounts (we add "Standard" value for localizable field)
                locale.AvailableEmailAccounts.Add(new SelectListItem
                {
                    Text = _localizationService.GetResource("Admin.ContentManagement.MessageTemplates.Fields.EmailAccount.Standard"),
                    Value = "0"
                });
                foreach (var ea in _emailAccountService.GetAllEmailAccounts())
                    locale.AvailableEmailAccounts.Add(new SelectListItem
                    {
                        Text = ea.DisplayName,
                        Value = ea.Id.ToString(),
                        Selected =  ea.Id == locale.EmailAccountId
                    });
            });

            return View(model);
        }
Example #6
0
        public ActionResult Edit(int id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageMessageTemplates))
            {
                return(AccessDeniedView());
            }

            var messageTemplate = _messageTemplateService.GetMessageTemplateById(id);

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

            var model = messageTemplate.ToModel();

            FillTokensTree(model.TokensTree, _messageTokenProvider.GetListOfAllowedTokens());

            // available email accounts
            foreach (var ea in _emailAccountService.GetAllEmailAccounts())
            {
                model.AvailableEmailAccounts.Add(ea.ToModel());
            }

            // Store
            PrepareStoresMappingModel(model, messageTemplate, false);

            // locales
            AddLocales(_languageService, model.Locales, (locale, languageId) =>
            {
                locale.BccEmailAddresses = messageTemplate.GetLocalized(x => x.BccEmailAddresses, languageId, false, false);
                locale.Subject           = messageTemplate.GetLocalized(x => x.Subject, languageId, false, false);
                locale.Body = messageTemplate.GetLocalized(x => x.Body, languageId, false, false);
                locale.Attachment1FileId = messageTemplate.GetLocalized(x => x.Attachment1FileId, languageId, false, false);
                locale.Attachment2FileId = messageTemplate.GetLocalized(x => x.Attachment2FileId, languageId, false, false);
                locale.Attachment3FileId = messageTemplate.GetLocalized(x => x.Attachment3FileId, languageId, false, false);

                var emailAccountId    = messageTemplate.GetLocalized(x => x.EmailAccountId, languageId, false, false);
                locale.EmailAccountId = emailAccountId > 0 ? emailAccountId : _emailAccountSettings.DefaultEmailAccountId;
            });

            return(View(model));
        }
Example #7
0
        public IActionResult Create()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageMessageTemplates))
            {
                return(AccessDeniedView());
            }

            var model = new MessageTemplateModel();

            //Stores
            PrepareStoresMappingModel(model, null, false);
            model.AllowedTokens = FormatTokens(_messageTokenProvider.GetListOfAllowedTokens());
            //available email accounts
            foreach (var ea in _emailAccountService.GetAllEmailAccounts())
            {
                model.AvailableEmailAccounts.Add(ea.ToModel());
            }

            return(View(model));
        }
        public ActionResult Edit(int id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageMessageTemplates))
            {
                return(AccessDeniedView());
            }

            var messageTemplate = _messageTemplateService.GetMessageTemplateById(id);

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

            var model = messageTemplate.ToModel();

            model.SendImmediately     = !model.DelayBeforeSend.HasValue;
            model.HasAttachedDownload = model.AttachedDownloadId > 0;
            model.AllowedTokens       = FormatTokens(_messageTokenProvider.GetListOfAllowedTokens());
            //available email accounts
            foreach (var ea in _emailAccountService.GetAllEmailAccounts())
            {
                model.AvailableEmailAccounts.Add(ea.ToModel());
            }
            //Store
            PrepareStoresMappingModel(model, messageTemplate, false);
            //locales
            AddLocales(_languageService, model.Locales, (locale, languageId) =>
            {
                locale.BccEmailAddresses = messageTemplate.GetLocalized(x => x.BccEmailAddresses, languageId, false, false);
                locale.Subject           = messageTemplate.GetLocalized(x => x.Subject, languageId, false, false);
                locale.Body = messageTemplate.GetLocalized(x => x.Body, languageId, false, false);

                var emailAccountId    = messageTemplate.GetLocalized(x => x.EmailAccountId, languageId, false, false);
                locale.EmailAccountId = emailAccountId > 0 ? emailAccountId : _emailAccountSettings.DefaultEmailAccountId;
            });

            return(View(model));
        }
Example #9
0
        /// <summary>
        /// Prepare SendinBlueModel
        /// </summary>
        /// <param name="model">Model</param>
        protected void PrepareModel(ConfigurationModel model)
        {
            //load settings for active store scope
            var storeId            = _storeContext.ActiveStoreScopeConfiguration;
            var sendInBlueSettings = _settingService.LoadSetting <SendinBlueSettings>(storeId);

            //whether plugin is configured
            if (string.IsNullOrEmpty(sendInBlueSettings.ApiKey))
            {
                return;
            }

            //prepare common properties
            model.ActiveStoreScopeConfiguration = storeId;
            model.ApiKey                 = sendInBlueSettings.ApiKey;
            model.ListId                 = sendInBlueSettings.ListId;
            model.SmtpKey                = sendInBlueSettings.SmtpKey;
            model.SenderId               = sendInBlueSettings.SenderId;
            model.UseSmsNotifications    = sendInBlueSettings.UseSmsNotifications;
            model.SmsSenderName          = sendInBlueSettings.SmsSenderName;
            model.StoreOwnerPhoneNumber  = sendInBlueSettings.StoreOwnerPhoneNumber;
            model.UseMarketingAutomation = sendInBlueSettings.UseMarketingAutomation;
            model.TrackingScript         = sendInBlueSettings.TrackingScript;

            //check whether email account exists
            if (sendInBlueSettings.UseSmtp && _emailAccountService.GetEmailAccountById(sendInBlueSettings.EmailAccountId) != null)
            {
                model.UseSmtp = sendInBlueSettings.UseSmtp;
            }

            //get account info
            var(accountInfo, marketingAutomationEnabled, MAkey, accountErrors) = _sendInBlueEmailManager.GetAccountInfo();
            model.AccountInfo                 = accountInfo;
            model.MarketingAutomationKey      = MAkey;
            model.MarketingAutomationDisabled = !marketingAutomationEnabled;
            if (!string.IsNullOrEmpty(accountErrors))
            {
                ErrorNotification(SendinBlueDefaults.NotificationMessage + accountErrors);
            }

            //prepare overridable settings
            if (storeId > 0)
            {
                model.ListId_OverrideForStore                 = _settingService.SettingExists(sendInBlueSettings, x => x.ListId, storeId);
                model.UseSmtp_OverrideForStore                = _settingService.SettingExists(sendInBlueSettings, x => x.UseSmtp, storeId);
                model.SenderId_OverrideForStore               = _settingService.SettingExists(sendInBlueSettings, x => x.SenderId, storeId);
                model.UseSmsNotifications_OverrideForStore    = _settingService.SettingExists(sendInBlueSettings, x => x.UseSmsNotifications, storeId);
                model.SmsSenderName_OverrideForStore          = _settingService.SettingExists(sendInBlueSettings, x => x.SmsSenderName, storeId);
                model.UseMarketingAutomation_OverrideForStore = _settingService.SettingExists(sendInBlueSettings, x => x.UseMarketingAutomation, storeId);
            }

            //check SMTP status
            var(smtpEnabled, smtpErrors) = _sendInBlueEmailManager.SmtpIsEnabled();
            if (!string.IsNullOrEmpty(smtpErrors))
            {
                ErrorNotification(SendinBlueDefaults.NotificationMessage + smtpErrors);
            }

            //get available contact lists to synchronize
            var(lists, listsErrors) = _sendInBlueEmailManager.GetLists();
            model.AvailableLists    = lists.Select(list => new SelectListItem(list.Name, list.Id)).ToList();
            model.AvailableLists.Insert(0, new SelectListItem("Select list", "0"));
            if (!string.IsNullOrEmpty(listsErrors))
            {
                ErrorNotification(SendinBlueDefaults.NotificationMessage + listsErrors);
            }

            //get available senders of emails from account
            var(senders, sendersErrors) = _sendInBlueEmailManager.GetSenders();
            model.AvailableSenders      = senders.Select(list => new SelectListItem(list.Name, list.Id)).ToList();
            model.AvailableSenders.Insert(0, new SelectListItem("Select sender", "0"));
            if (!string.IsNullOrEmpty(sendersErrors))
            {
                ErrorNotification(SendinBlueDefaults.NotificationMessage + sendersErrors);
            }

            //get message templates
            model.AvailableMessageTemplates = _messageTemplateService.GetAllMessageTemplates(storeId).Select(messageTemplate =>
            {
                var name = messageTemplate.Name;
                if (storeId == 0 && messageTemplate.LimitedToStores)
                {
                    var storeIds   = _storeMappingService.GetStoresIdsWithAccess(messageTemplate);
                    var storeNames = _storeService.GetAllStores().Where(store => storeIds.Contains(store.Id)).Select(store => store.Name);
                    name           = $"{name} ({string.Join(',', storeNames)})";
                }

                return(new SelectListItem(name, messageTemplate.Id.ToString()));
            }).ToList();

            //get allowed tokens
            model.AllowedTokens = string.Join(", ", _messageTokenProvider.GetListOfAllowedTokens());

            //create attributes in account
            var attributesErrors = _sendInBlueEmailManager.PrepareAttributes();

            if (!string.IsNullOrEmpty(attributesErrors))
            {
                ErrorNotification(SendinBlueDefaults.NotificationMessage + attributesErrors);
            }

            //try to set account partner
            if (!sendInBlueSettings.PartnerValueSet)
            {
                var partnerSet = _sendInBlueEmailManager.SetPartner();
                if (partnerSet)
                {
                    sendInBlueSettings.PartnerValueSet = true;
                    _settingService.SaveSetting(sendInBlueSettings, x => x.PartnerValueSet, clearCache: false);
                    _settingService.ClearCache();
                }
            }
        }
        /// <summary>
        /// Prepare SendinBlueModel
        /// </summary>
        /// <param name="model">Model</param>
        private void PrepareModel(ConfigurationModel model)
        {
            //load settings for active store scope
            var storeId            = _storeContext.ActiveStoreScopeConfiguration;
            var sendinBlueSettings = _settingService.LoadSetting <SendinBlueSettings>(storeId);

            //whether plugin is configured
            if (string.IsNullOrEmpty(sendinBlueSettings.ApiKey))
            {
                return;
            }

            //prepare common properties
            model.ActiveStoreScopeConfiguration = storeId;
            model.ApiKey                 = sendinBlueSettings.ApiKey;
            model.ListId                 = sendinBlueSettings.ListId;
            model.SmtpKey                = sendinBlueSettings.SmtpKey;
            model.SenderId               = sendinBlueSettings.SenderId;
            model.UseSmsNotifications    = sendinBlueSettings.UseSmsNotifications;
            model.SmsSenderName          = sendinBlueSettings.SmsSenderName;
            model.StoreOwnerPhoneNumber  = sendinBlueSettings.StoreOwnerPhoneNumber;
            model.UseMarketingAutomation = sendinBlueSettings.UseMarketingAutomation;
            model.TrackingScript         = sendinBlueSettings.TrackingScript;

            model.HideGeneralBlock             = _genericAttributeService.GetAttribute <bool>(_workContext.CurrentCustomer, SendinBlueDefaults.HideGeneralBlock);
            model.HideSynchronizationBlock     = _genericAttributeService.GetAttribute <bool>(_workContext.CurrentCustomer, SendinBlueDefaults.HideSynchronizationBlock);
            model.HideTransactionalBlock       = _genericAttributeService.GetAttribute <bool>(_workContext.CurrentCustomer, SendinBlueDefaults.HideTransactionalBlock);
            model.HideSmsBlock                 = _genericAttributeService.GetAttribute <bool>(_workContext.CurrentCustomer, SendinBlueDefaults.HideSmsBlock);
            model.HideMarketingAutomationBlock = _genericAttributeService.GetAttribute <bool>(_workContext.CurrentCustomer, SendinBlueDefaults.HideMarketingAutomationBlock);

            //prepare nested search models
            model.MessageTemplateSearchModel.SetGridPageSize();
            model.SmsSearchModel.SetGridPageSize();

            //prepare add SMS model
            model.AddSms.AvailablePhoneTypes.Add(new SelectListItem(_localizationService.GetResource("Plugins.Misc.SendinBlue.MyPhone"), "0"));
            model.AddSms.AvailablePhoneTypes.Add(new SelectListItem(_localizationService.GetResource("Plugins.Misc.SendinBlue.CustomerPhone"), "1"));
            model.AddSms.AvailablePhoneTypes.Add(new SelectListItem(_localizationService.GetResource("Plugins.Misc.SendinBlue.BillingAddressPhone"), "2"));
            model.AddSms.DefaultSelectedPhoneTypeId = model.AddSms.AvailablePhoneTypes.First().Value;

            model.AddSms.AvailableMessages = _messageTemplateService.GetAllMessageTemplates(storeId).Select(messageTemplate =>
            {
                var name = messageTemplate.Name;
                if (storeId == 0 && messageTemplate.LimitedToStores)
                {
                    var storeIds   = _storeMappingService.GetStoresIdsWithAccess(messageTemplate);
                    var storeNames = _storeService.GetAllStores().Where(store => storeIds.Contains(store.Id)).Select(store => store.Name);
                    name           = $"{name} ({string.Join(',', storeNames)})";
                }

                return(new SelectListItem(name, messageTemplate.Id.ToString()));
            }).ToList();
            var defaultSelectedMessage = model.AddSms.AvailableMessages.FirstOrDefault();

            model.AddSms.DefaultSelectedMessageId = defaultSelectedMessage?.Value ?? "0";

            //check whether email account exists
            if (sendinBlueSettings.UseSmtp && _emailAccountService.GetEmailAccountById(sendinBlueSettings.EmailAccountId) != null)
            {
                model.UseSmtp = sendinBlueSettings.UseSmtp;
            }

            //get account info
            var(accountInfo, marketingAutomationEnabled, maKey, accountErrors) = _sendinBlueEmailManager.GetAccountInfo();
            model.AccountInfo                 = accountInfo;
            model.MarketingAutomationKey      = maKey;
            model.MarketingAutomationDisabled = !marketingAutomationEnabled;
            if (!string.IsNullOrEmpty(accountErrors))
            {
                _notificationService.ErrorNotification($"{SendinBlueDefaults.NotificationMessage} {accountErrors}");
            }

            //prepare overridable settings
            if (storeId > 0)
            {
                model.ListId_OverrideForStore                 = _settingService.SettingExists(sendinBlueSettings, settings => settings.ListId, storeId);
                model.UseSmtp_OverrideForStore                = _settingService.SettingExists(sendinBlueSettings, settings => settings.UseSmtp, storeId);
                model.SenderId_OverrideForStore               = _settingService.SettingExists(sendinBlueSettings, settings => settings.SenderId, storeId);
                model.UseSmsNotifications_OverrideForStore    = _settingService.SettingExists(sendinBlueSettings, settings => settings.UseSmsNotifications, storeId);
                model.SmsSenderName_OverrideForStore          = _settingService.SettingExists(sendinBlueSettings, settings => settings.SmsSenderName, storeId);
                model.UseMarketingAutomation_OverrideForStore = _settingService.SettingExists(sendinBlueSettings, settings => settings.UseMarketingAutomation, storeId);
            }

            //check SMTP status
            var(smtpEnabled, smtpErrors) = _sendinBlueEmailManager.SmtpIsEnabled();
            if (!string.IsNullOrEmpty(smtpErrors))
            {
                _notificationService.ErrorNotification($"{SendinBlueDefaults.NotificationMessage} {smtpErrors}");
            }

            //get available contact lists to synchronize
            var(lists, listsErrors) = _sendinBlueEmailManager.GetLists();
            model.AvailableLists    = lists.Select(list => new SelectListItem(list.Name, list.Id)).ToList();
            model.AvailableLists.Insert(0, new SelectListItem("Select list", "0"));
            if (!string.IsNullOrEmpty(listsErrors))
            {
                _notificationService.ErrorNotification($"{SendinBlueDefaults.NotificationMessage} {listsErrors}");
            }

            //get available senders of emails from account
            var(senders, sendersErrors) = _sendinBlueEmailManager.GetSenders();
            model.AvailableSenders      = senders.Select(list => new SelectListItem(list.Name, list.Id)).ToList();
            model.AvailableSenders.Insert(0, new SelectListItem("Select sender", "0"));
            if (!string.IsNullOrEmpty(sendersErrors))
            {
                _notificationService.ErrorNotification($"{SendinBlueDefaults.NotificationMessage} {sendersErrors}");
            }

            //get allowed tokens
            model.AllowedTokens = string.Join(", ", _messageTokenProvider.GetListOfAllowedTokens());

            //create attributes in account
            var attributesErrors = _sendinBlueEmailManager.PrepareAttributes();

            if (!string.IsNullOrEmpty(attributesErrors))
            {
                _notificationService.ErrorNotification($"{SendinBlueDefaults.NotificationMessage} {attributesErrors}");
            }

            //try to set account partner
            if (!sendinBlueSettings.PartnerValueSet)
            {
                var partnerSet = _sendinBlueEmailManager.SetPartner();
                if (partnerSet)
                {
                    sendinBlueSettings.PartnerValueSet = true;
                    _settingService.SaveSetting(sendinBlueSettings, settings => settings.PartnerValueSet, clearCache: false);
                    _settingService.ClearCache();
                }
            }
        }
        /// <summary>
        /// Prepare SendInBlueModel
        /// </summary>
        /// <param name="model">Model</param>
        protected void PrepareModel(SendInBlueModel model)
        {
            var storeId            = GetActiveStoreScopeConfiguration(_storeService, _workContext);
            var sendInBlueSettings = _settingService.LoadSetting <SendInBlueSettings>(storeId);

            model.ActiveStoreScopeConfiguration = storeId;

            if (string.IsNullOrEmpty(sendInBlueSettings.ApiKey))
            {
                return;
            }

            //synchronization task
            var task = FindScheduledTask();

            if (task != null)
            {
                model.AutoSyncEachMinutes = task.Seconds / 60;
                model.AutoSync            = task.Enabled;
            }

            //settings to model
            model.ApiKey        = sendInBlueSettings.ApiKey;
            model.ListId        = sendInBlueSettings.ListId;
            model.SMTPSenderId  = sendInBlueSettings.SMTPSenderId;
            model.UseSMS        = sendInBlueSettings.UseSMS;
            model.SMSFrom       = sendInBlueSettings.SMSFrom;
            model.MyPhoneNumber = sendInBlueSettings.MyPhoneNumber;

            //check whether email account exist
            if (sendInBlueSettings.UseSendInBlueSMTP && _emailAccountService.GetEmailAccountById(sendInBlueSettings.SendInBlueEmailAccountId) != null)
            {
                model.UseSendInBlueSMTP = sendInBlueSettings.UseSendInBlueSMTP;
            }

            //overridable settings
            if (storeId > 0)
            {
                model.ListId_OverrideForStore            = _settingService.SettingExists(sendInBlueSettings, x => x.ListId, storeId);
                model.UseSendInBlueSMTP_OverrideForStore = _settingService.SettingExists(sendInBlueSettings, x => x.UseSendInBlueSMTP, storeId);
                model.SMTPSenderId_OverrideForStore      = _settingService.SettingExists(sendInBlueSettings, x => x.SMTPSenderId, storeId);
                model.UseSMS_OverrideForStore            = _settingService.SettingExists(sendInBlueSettings, x => x.UseSMS, storeId);
                model.SMSFrom_OverrideForStore           = _settingService.SettingExists(sendInBlueSettings, x => x.SMSFrom, storeId);
            }

            //get SendInBlue account info
            var errors      = string.Empty;
            var accountInfo = _sendInBlueEmailManager.GetAccountInfo(ref errors);

            if (string.IsNullOrEmpty(errors))
            {
                model.AccountInfo = accountInfo;
            }
            else
            {
                ErrorNotification(errors);
            }

            //check SMTP status
            if (!_sendInBlueEmailManager.SmtpIsEnabled(ref errors))
            {
                ErrorNotification(errors);
            }

            //get available lists of subscriptions for the synchronization from SendInBlue account
            model.AvailableLists = _sendInBlueEmailManager.GetLists();

            //get available senders of emails from SendInBlue account
            model.AvailableSenders = _sendInBlueEmailManager.GetSenders();

            //get message templates
            model.AvailableMessageTemplates = _messageTemplateService.GetAllMessageTemplates(storeId).Select(x => new SelectListItem
            {
                Value = x.Id.ToString(),
                Text  = storeId > 0 ? x.Name : string.Format("{0} {1}", x.Name, !x.LimitedToStores ? string.Empty :
                                                             _storeService.GetAllStores().Where(s => _storeMappingService.GetStoresIdsWithAccess(x).Contains(s.Id))
                                                             .Aggregate("-", (current, next) => string.Format("{0} {1}, ", current, next.Name)).TrimEnd(','))
            }).ToList();

            //get string of allowed tokens
            model.AllowedTokens = _messageTokenProvider.GetListOfAllowedTokens()
                                  .Aggregate(string.Empty, (current, next) => string.Format("{0}, {1}", current, next)).Trim(',');
        }
Example #12
0
        public virtual ActionResult Edit(int id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageMessageTemplates))
            {
                return(AccessDeniedView());
            }

            var messageTemplate = _messageTemplateService.GetMessageTemplateById(id);

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

            #region Extensions by QuanNH

            if (!_storeMappingService.TableEdit(messageTemplate.Id, "MessageTemplate"))
            {
                return(RedirectToAction("List"));
            }

            #endregion

            var model = messageTemplate.ToModel();
            model.SendImmediately     = !model.DelayBeforeSend.HasValue;
            model.HasAttachedDownload = model.AttachedDownloadId > 0;
            var allowedTokens = string.Join(", ", _messageTokenProvider.GetListOfAllowedTokens(messageTemplate.GetTokenGroups()));
            model.AllowedTokens = string.Format("{0}{1}{1}{2}{1}", allowedTokens, Environment.NewLine,
                                                _localizationService.GetResource("Admin.ContentManagement.MessageTemplates.Tokens.ConditionalStatement"));
            //available email accounts
            foreach (var ea in _emailAccountService.GetAllEmailAccounts())
            {
                model.AvailableEmailAccounts.Add(new SelectListItem {
                    Text = ea.DisplayName, Value = ea.Id.ToString()
                });
            }
            //Store
            PrepareStoresMappingModel(model, messageTemplate, false);
            //locales
            AddLocales(_languageService, model.Locales, (locale, languageId) =>
            {
                locale.BccEmailAddresses = messageTemplate.GetLocalized(x => x.BccEmailAddresses, languageId, false, false);
                locale.Subject           = messageTemplate.GetLocalized(x => x.Subject, languageId, false, false);
                locale.Body = messageTemplate.GetLocalized(x => x.Body, languageId, false, false);

                locale.EmailAccountId = messageTemplate.GetLocalized(x => x.EmailAccountId, languageId, false, false);
                //available email accounts (we add "Standard" value for localizable field)
                locale.AvailableEmailAccounts.Add(new SelectListItem
                {
                    Text  = _localizationService.GetResource("Admin.ContentManagement.MessageTemplates.Fields.EmailAccount.Standard"),
                    Value = "0"
                });
                foreach (var ea in _emailAccountService.GetAllEmailAccounts())
                {
                    locale.AvailableEmailAccounts.Add(new SelectListItem
                    {
                        Text     = ea.DisplayName,
                        Value    = ea.Id.ToString(),
                        Selected = ea.Id == locale.EmailAccountId
                    });
                }
            });

            return(View(model));
        }