Example #1
0
        public IActionResult Edit(InteractiveFormModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageBanners))
            {
                return(AccessDeniedView());
            }

            var form = _interactiveFormService.GetFormById(model.Id);

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

            if (ModelState.IsValid)
            {
                form         = model.ToEntity(form);
                form.Locales = UpdateLocales(form, model);
                _interactiveFormService.UpdateForm(form);

                _customerActivityService.InsertActivity("InteractiveFormEdit", form.Id, _localizationService.GetResource("ActivityLog.InteractiveFormUpdate"), form.Name);

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

            AddLocales(_languageService, model.Locales, (locale, languageId) =>
            {
                locale.Name = form.GetLocalized(x => x.Name, languageId, false, false);
                locale.Body = form.GetLocalized(x => x.Body, languageId, false, false);
            });
            //available email accounts
            foreach (var ea in _emailAccountService.GetAllEmailAccounts())
            {
                model.AvailableEmailAccounts.Add(ea.ToModel());
            }

            //available tokens
            model.AvailableTokens = FormatTokens(form.FormAttributes.Select(x => "%" + x.SystemName + "%").ToArray());

            return(View(model));
        }
        public async Task <IActionResult> Edit(InteractiveFormModel model, bool continueEditing)
        {
            var form = await _interactiveFormService.GetFormById(model.Id);

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

            if (ModelState.IsValid)
            {
                form = model.ToEntity(form);
                await _interactiveFormService.UpdateForm(form);

                await _customerActivityService.InsertActivity("InteractiveFormEdit", form.Id, _translationService.GetResource("ActivityLog.InteractiveFormUpdate"), form.Name);

                Success(_translationService.GetResource("admin.marketing.InteractiveForms.Updated"));
                return(continueEditing ? RedirectToAction("Edit", new { id = form.Id }) : RedirectToAction("List"));
            }

            await AddLocales(_languageService, model.Locales, (locale, languageId) =>
            {
                locale.Name = form.GetTranslation(x => x.Name, languageId, false);
                locale.Body = form.GetTranslation(x => x.Body, languageId, false);
            });

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

            //available tokens
            model.AvailableTokens = FormatTokens(form.FormAttributes.Select(x => "%" + x.SystemName + "%").ToArray());

            return(View(model));
        }