Example #1
0
        public static async Task BanAsync(this User user, DbContext context)
        {
            MarriageRepository repository = new MarriageRepository(context);

            User u = await context.Set <User>().FindAsync(user.Id);

            await repository.DivorceAllMarriagesAsync(user.Id);

            await repository.DeclineAllProposalsAsync(user.Id);

            context.Set <CommandUsage>().RemoveRange(
                await context.Set <CommandUsage>().Where(x => x.UserId == user.Id).ToListAsync()
                );

            context.Set <Achievement>().RemoveRange(
                await context.Set <Achievement>().Where(x => x.UserId == user.Id).ToListAsync()
                );

            context.Set <LocalExperience>().RemoveRange(
                await context.Set <LocalExperience>().Where(x => x.UserId == user.Id).ToListAsync()
                );

            MikiApp.Instance.GetService <EventSystem>().MessageFilter.Get <UserFilter>().Users.Add(user.Id.FromDbLong());

            u.Banned           = true;
            u.Total_Commands   = 0;
            u.Total_Experience = 0;
            u.MarriageSlots    = 0;
            u.Currency         = 0;
            u.Reputation       = 0;

            await context.SaveChangesAsync();
        }
Example #2
0
        public static async Task BanAsync(this User user)
        {
            using (var context = new MikiContext())
            {
                MarriageRepository repository = new MarriageRepository(context);

                User u = await context.Users.FindAsync(user.Id);

                await repository.DivorceAllMarriagesAsync(user.Id);

                await repository.DeclineAllProposalsAsync(user.Id);

                context.CommandUsages.RemoveRange(
                    await context.CommandUsages.Where(x => x.UserId == user.Id).ToListAsync()
                    );

                context.Achievements.RemoveRange(
                    await context.Achievements.Where(x => x.Id == user.Id).ToListAsync()
                    );

                context.LocalExperience.RemoveRange(
                    await context.LocalExperience.Where(x => x.UserId == user.Id).ToListAsync()
                    );

                Miki.Framework.Bot.Instance.GetAttachedObject <EventSystem>().MessageFilter.Get <UserFilter>().Users.Add(user.Id.FromDbLong());

                u.Banned           = true;
                u.Total_Commands   = 0;
                u.Total_Experience = 0;
                u.MarriageSlots    = 0;
                u.Currency         = 0;
                u.Reputation       = 0;

                await context.SaveChangesAsync();
            }
        }