Exemplo n.º 1
0
        public static async Task <WheelMode> GetMode(long guildId, DiscordContext context = null)
        {
            var dispose = context == null;

            if (context == null)
            {
#pragma warning disable IDE0068 // Use recommended dispose pattern
                context = new DiscordContext();
#pragma warning restore IDE0068 // Use recommended dispose pattern
            }

            WheelSetting wheelSetting = await context.WheelSetting.FindAsync(guildId);

            if (dispose)
            {
                context.Dispose();
            }

            return(wheelSetting == null ? WheelMode.Default : (WheelMode)wheelSetting.Mode);
        }
Exemplo n.º 2
0
        public static async Task SetMode(WheelMode newMode, long guildId, DiscordContext context = null, bool save = true)
        {
            var dispose = context == null;

            if (context == null)
            {
#pragma warning disable IDE0068 // Use recommended dispose pattern
                context = new DiscordContext();
#pragma warning restore IDE0068 // Use recommended dispose pattern
            }

            WheelSetting wheelSetting = await context.WheelSetting.FindAsync(guildId);

            if (wheelSetting == null)
            {
                wheelSetting = new WheelSetting()
                {
                    GuildId = guildId,
                    Mode    = (int)newMode
                };

                context.WheelSetting.Add(wheelSetting);
            }
            else
            {
                wheelSetting.Mode = (int)newMode;
            }

            if (save)
            {
                await context.SaveChangesAsync();
            }

            if (dispose)
            {
                context.Dispose();
            }
        }