public override async Task <IViewProviderResult> BuildUpdateAsync(AttachmentSetting settings, IViewProviderContext context) { var model = new EditAttachmentSettingsViewModel(); // 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 AttachmentSetting() { RoleId = role.Id, AvailableSpace = model.AvailableSpace, AllowedExtensions = GetPostedExtensions() }; var result = await _attachmentSettingsStore.SaveAsync(settings); if (result != null) { // Recycle shell context to ensure changes take effect _platoHost.RecycleShellContext(_shellSettings); } } return(await BuildEditAsync(settings, context)); }
public async Task <IActionResult> EditSettingsPost(EditAttachmentSettingsViewModel viewModel) { // Ensure we have permission if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageAttachmentSettings)) { 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 AttachmentSetting(), 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(AttachmentSetting 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 long availableSpace = DefaultAttachmentSettings.AvailableSpace; var allowedExtensions = DefaultAttachmentSettings.AllowedExtensions; // Populate settings var settings = await _attachmentSettingsStore.GetByRoleIdAsync(role.Id); if (settings != null) { availableSpace = settings.AvailableSpace; allowedExtensions = settings.AllowedExtensions; } // Build model var viewModel = new EditAttachmentSettingsViewModel() { RoleId = role.Id, Role = role, AvailableSpace = availableSpace, AvailableSpaces = GetAvailableSpaces(), DefaultExtensions = DefaultExtensions.Extensions, ExtensionHtmlName = ExtensionHtmlName, AllowedExtensions = allowedExtensions }; // Build view return(Views( View <EditAttachmentSettingsViewModel>("Admin.EditSettings.Header", model => viewModel).Zone("header").Order(1), View <EditAttachmentSettingsViewModel>("Admin.EditSettings.Tools", model => viewModel).Zone("tools").Order(1), View <EditAttachmentSettingsViewModel>("Admin.EditSettings.Content", model => viewModel).Zone("content").Order(1) )); }