Ejemplo n.º 1
0
        public override async Task <IViewProviderResult> BuildUpdateAsync(PlatoSlackSettings settings, IViewProviderContext context)
        {
            var model = new SlackSettingsViewModel();

            // Validate model
            if (!await context.Updater.TryUpdateModelAsync(model))
            {
                return(await BuildEditAsync(settings, context));
            }

            // Update settings
            if (context.Updater.ModelState.IsValid)
            {
                // Encrypt the secret
                var webHookUrl        = string.Empty;
                var accessTokenSecret = string.Empty;

                if (!string.IsNullOrWhiteSpace(model.WebHookUrl))
                {
                    try
                    {
                        webHookUrl = _encrypter.Encrypt(model.WebHookUrl);
                    }
                    catch (Exception e)
                    {
                        if (_logger.IsEnabled(LogLevel.Error))
                        {
                            _logger.LogError(e, $"There was a problem encrypting the Slack Web Hook URL. {e.Message}");
                        }
                    }
                }

                // Create the model
                settings = new PlatoSlackSettings()
                {
                    WebHookUrl = webHookUrl
                };

                // Persist the settings
                var result = await _TwitterSettingsStore.SaveAsync(settings);

                if (result != null)
                {
                    // Recycle shell context to ensure changes take effect
                    _platoHost.RecycleShellContext(_shellSettings);
                }
            }

            return(await BuildEditAsync(settings, context));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> IndexPost(SlackSettingsViewModel viewModel)
        {
            // Ensure we have permission
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditSlackSettings))
            {
                return(Unauthorized());
            }

            // Execute view providers ProvideUpdateAsync method
            await _viewProvider.ProvideUpdateAsync(new SlackSettings(), this);

            // Add alert
            _alerter.Success(T["Settings Updated Successfully!"]);

            return(RedirectToAction(nameof(Index)));
        }