Пример #1
0
        public ActionResult Index(NopCommerceC5ConnectorSettingsModel model)
        {
            string saveResult = "";
            if (ModelState.IsValid)
            {
                _settings.DefaultListId = model.DefaultListId;
                _settings.ApiKey = model.ApiKey;
                _settings.WebHookKey = model.WebHookKey;

                _settingService.SaveSetting(_settings);
            }

            // Update the task
            var task = FindScheduledTask();
            if (task != null)
            {
                task.Enabled = model.AutoSync;
                task.Seconds = model.AutoSyncEachMinutes * 60;
                _scheduleTaskService.UpdateTask(task);
                saveResult = _localizationService.GetResource("Plugin.Misc.MailChimp.AutoSyncRestart");
            }

            model = PrepareModel();
            //set result text
            model.SaveResult = saveResult;

            return View(VIEW_PATH, model);
        }
Пример #2
0
        private void MapListOptions(NopCommerceC5ConnectorSettingsModel model)
        {
            //NameValueCollection listOptions = _mailChimpApiService.RetrieveLists();
            NameValueCollection listOptions = new NameValueCollection();

            //Ensure there will not be duplicates
            model.ListOptions.Clear();

            foreach (string key in listOptions.AllKeys)
            {
                model.ListOptions.Add(new SelectListItem { Text = key, Value = listOptions[key] });
            }
        }
Пример #3
0
        private NopCommerceC5ConnectorSettingsModel PrepareModel()
        {
            var model = new NopCommerceC5ConnectorSettingsModel();

            //Set the properties
            model.ApiKey = _settings.ApiKey;
            model.DefaultListId = _settings.DefaultListId;
            model.WebHookKey = _settings.WebHookKey;
            ScheduleTask task = FindScheduledTask();
            if (task != null)
            {
                model.AutoSyncEachMinutes = task.Seconds / 60;
                model.AutoSync = task.Enabled;
            }

            //Maps the list options
            MapListOptions(model);

            return model;
        }
Пример #4
0
        public ActionResult Sync(NopCommerceC5ConnectorSettingsModel model, HttpPostedFileBase file)
        {
            //var model = PrepareModel();
            try
            {
                var sb = new StringBuilder();
                IImportService importService = _importFabric.GetImportService(model.ImportType);
                importService.Import(file);
                /*var result = _mailChimpApiService.Synchronize();
                //subscribe
                sb.Append("Subscribe results: ");
                sb.Append(result.SubscribeResult);
                sb.Append("<br />");
                for (int i = 0; i < result.SubscribeErrors.Count; i++)
                {
                    sb.Append(result.SubscribeErrors[i]);
                    if (i != result.SubscribeErrors.Count - 1)
                        sb.Append("<br />");
                }

                //unsubscribe
                sb.Append("<br />");
                sb.Append("Unsubscribe results: ");
                sb.Append(result.UnsubscribeResult);
                sb.Append("<br />");
                for (int i = 0; i < result.UnsubscribeErrors.Count; i++)
                {
                    sb.Append(result.UnsubscribeErrors[i]);
                    if (i != result.UnsubscribeErrors.Count - 1)
                        sb.Append("<br />");
                }
                //set result text
                model.SyncResult = sb.ToString();*/
                model.SyncResult = "Success";
            }
            catch (Exception exc)
            {
                //set result text
                model.SyncResult = exc.ToString();
            }

            return View(VIEW_PATH, model);
        }