public override async Task <IViewProviderResult> BuildUpdateAsync(FileSetting settings, IViewProviderContext context) { var model = new EditFileSettingsViewModel(); // Validate model if (!await context.Updater.TryUpdateModelAsync(model)) { return(await BuildEditAsync(settings, context)); } // Update settings if (context.Updater.ModelState.IsValid) { var role = await _platoRoleStore.GetByIdAsync(model.RoleId); settings = new FileSetting() { RoleId = role.Id, MaxFileSize = model.MaxFileSize, AvailableSpace = model.AvailableSpace, AllowedExtensions = GetPostedExtensions() }; var result = await _attachmentSettingsStore.SaveAsync(settings); if (result != null) { // Recycle shell context to ensure changes take effect _platoHost.RecycleShell(_shellSettings); } } return(await BuildEditAsync(settings, context)); }
public async Task <IActionResult> EditSettingsPost(EditFileSettingsViewModel viewModel) { // Ensure we have permission if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageFileSettings)) { return(Unauthorized()); } // Get role var role = await _platoRoleStore.GetByIdAsync(viewModel.RoleId); if (role == null) { return(NotFound()); } // Add view model to context this.HttpContext.Items[typeof(Role)] = role; // Execute view providers ProvideUpdateAsync method await _settingsViewProvider.ProvideUpdateAsync(new FileSetting(), this); // Add alert _alerter.Success(T["Settings Updated Successfully!"]); return(RedirectToAction(nameof(EditSettings), new RouteValueDictionary() { ["id"] = viewModel.RoleId.ToString() })); }
public override async Task <IViewProviderResult> BuildEditAsync(FileSetting setting, IViewProviderContext context) { var role = context.Controller.HttpContext.Items[typeof(Role)] as Role; if (role == null) { throw new Exception($"A view model of type {typeof(Role).ToString()} has not been registered on the HttpContext!"); } // Defaults var maxFileSize = DefaultFileOptions.MaxFileSize; long availableSpace = DefaultFileOptions.AvailableSpace; var allowedExtensions = DefaultFileOptions.AllowedExtensions; // Populate settings var settings = await _attachmentSettingsStore.GetByRoleIdAsync(role.Id); if (settings != null) { maxFileSize = settings.MaxFileSize; availableSpace = settings.AvailableSpace; allowedExtensions = settings.AllowedExtensions; } // Build model var viewModel = new EditFileSettingsViewModel() { RoleId = role.Id, Role = role, MaxFileSize = maxFileSize, AvailableSpace = availableSpace, AvailableSpaces = GetAvailableSpaces(), DefaultExtensions = DefaultExtensions.Extensions, ExtensionHtmlName = ExtensionHtmlName, AllowedExtensions = allowedExtensions }; // Build view return(Views( View <EditFileSettingsViewModel>("Admin.EditSettings.Header", model => viewModel).Zone("header").Order(1), View <EditFileSettingsViewModel>("Admin.EditSettings.Tools", model => viewModel).Zone("header-right").Order(1), View <EditFileSettingsViewModel>("Admin.EditSettings.Content", model => viewModel).Zone("content").Order(1) )); }