public static async Task <AttachmentSettings> GetByRoleIdsAsync(this IAttachmentSettingsStore <AttachmentSettings> store, int[] roleIds)
        {
            if (roleIds == null)
            {
                throw new ArgumentNullException(nameof(roleIds));
            }

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

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

            return(new AttachmentSettings()
            {
                Settings = output
            });
        }
Exemple #2
0
 public AdminViewProvider(
     IAttachmentSettingsStore <AttachmentSettings> attachmentSettingsStore,
     ILogger <AdminViewProvider> logger,
     IOptions <PlatoOptions> platoOptions,
     IShellSettings shellSettings,
     IPlatoHost platoHost)
 {
     _attachmentSettingsStore = attachmentSettingsStore;
     _platoOptions            = platoOptions.Value;
     _shellSettings           = shellSettings;
     _platoHost = platoHost;
     _logger    = logger;
 }
        public static async Task <AttachmentSettings> SaveAsync(this IAttachmentSettingsStore <AttachmentSettings> store, AttachmentSetting model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

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

            var output   = new List <AttachmentSetting>();
            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 AttachmentSettings()
            {
                Settings = output
            }));
        }
Exemple #4
0
 public AttachmentSettingsViewProvider(
     IAttachmentSettingsStore <AttachmentSettings> attachmentSettingsStore,
     IHttpContextAccessor httpContextAccessor,
     IPlatoRoleStore platoRoleStore,
     ILogger <AttachmentSettingsViewProvider> logger,
     IShellSettings shellSettings,
     IPlatoHost platoHost)
 {
     _request = httpContextAccessor.HttpContext.Request;
     _attachmentSettingsStore = attachmentSettingsStore;
     _platoRoleStore          = platoRoleStore;
     _shellSettings           = shellSettings;
     _platoHost = platoHost;
     _logger    = logger;
 }
        public static async Task <AttachmentSetting> GetByRoleIdAsync(this IAttachmentSettingsStore <AttachmentSettings> store, int roleId)
        {
            if (roleId <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(roleId));
            }

            var settings = await store.GetAsync();

            if (settings?.Settings != null)
            {
                foreach (var setting in settings.Settings)
                {
                    if (setting.RoleId == roleId)
                    {
                        return(setting);
                    }
                }
            }

            return(null);
        }
Exemple #6
0
 public AttachmentSettingsConfiguration(IAttachmentSettingsStore <AttachmentSettings> attachmentSettingsStore)
 {
     _attachmentSettingsStore = attachmentSettingsStore;
 }