Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        public static async Task <FileSettings> SaveAsync(this IFileSettingsStore <FileSettings> store, FileSetting model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            if (model.RoleId <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(model.RoleId));
            }

            var output   = new List <FileSetting>();
            var settings = await store.GetAsync();

            if (settings?.Settings != null)
            {
                if (settings.Contains(model))
                {
                    foreach (var setting in settings.Settings)
                    {
                        if (setting.RoleId == model.RoleId)
                        {
                            output.Add(model);
                        }
                        else
                        {
                            output.Add(setting);
                        }
                    }
                }
                else
                {
                    foreach (var setting in settings.Settings)
                    {
                        output.Add(setting);
                    }
                    output.Add(model);
                }
            }
            else
            {
                output.Add(model);
            }

            return(await store.SaveAsync(new FileSettings()
            {
                Settings = output
            }));
        }