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
            });
        }
Ejemplo n.º 2
0
        public void Configure(AttachmentSettings options)
        {
            var settings = _attachmentSettingsStore
                           .GetAsync()
                           .GetAwaiter()
                           .GetResult();

            if (settings != null)
            {
                options.Settings = settings.Settings;
            }
        }
        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
            }));
        }
Ejemplo n.º 4
0
        async Task <AttachmentSettingsViewModel> GetModel()
        {
            var settings = await _attachmentSettingsStore.GetAsync();

            return(new AttachmentSettingsViewModel());


            //if (settings != null)
            //{
            //    return new EmailSettingsViewModel()
            //    {
            //        SmtpSettings = new SmtpSettingsViewModel()
            //        {
            //            DefaultFrom = _platoOptions.DemoMode
            //                ? "*****@*****.**"
            //                : settings.SmtpSettings.DefaultFrom,
            //            Host = _platoOptions.DemoMode
            //                ? "smtp.example.com"
            //                : settings.SmtpSettings.Host,
            //            Port = settings.SmtpSettings.Port,
            //            UserName = _platoOptions.DemoMode
            //                ? "*****@*****.**"
            //                : settings.SmtpSettings.UserName,
            //            Password = _platoOptions.DemoMode
            //                ? ""
            //                : settings.SmtpSettings.Password,
            //            RequireCredentials = settings.SmtpSettings.RequireCredentials,
            //            EnableSsl = settings.SmtpSettings.EnableSsl,
            //            PollInterval = settings.SmtpSettings.PollingInterval,
            //            BatchSize = settings.SmtpSettings.BatchSize,
            //            SendAttempts = settings.SmtpSettings.SendAttempts,
            //            EnablePolling = settings.SmtpSettings.EnablePolling
            //        }
            //    };
            //}

            //// return default settings
            //return new EmailSettingsViewModel()
            //{
            //    SmtpSettings = new SmtpSettingsViewModel()
            //};
        }
        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);
        }