Beispiel #1
0
        public async Task UpdatePercentAsync(ulong userId, uint percent)
        {
            await EnsureExistsAsync(userId);

            var oldToxicity = await GetAsync(userId);

            await using var context = new RiftContext();
            var toxicity = new RiftToxicity
            {
                UserId  = userId,
                Percent = percent
            };

            context.Entry(toxicity).Property(x => x.Percent).IsModified = true;

            if (percent > oldToxicity.Percent)
            {
                toxicity.LastIncreased = DateTime.UtcNow;
                context.Entry(toxicity).Property(x => x.LastIncreased).IsModified = true;
            }
            else if (percent < oldToxicity.Percent)
            {
                toxicity.LastDecreased = DateTime.UtcNow;
                context.Entry(toxicity).Property(x => x.LastDecreased).IsModified = true;
            }

            await context.SaveChangesAsync();
        }
Beispiel #2
0
        public async Task <bool> TryUpdateAsync(RiftReward reward)
        {
            await using var context = new RiftContext();
            var data = await GetAsync(reward.Id);

            if (data is null)
            {
                return(false); // nothing to update
            }
            var entry = context.Entry(data);

            if (!reward.Description.Equals(data.Description))
            {
                entry.Property(x => x.Description).IsModified = true;
            }

            if (!reward.ItemsData.Equals(data.ItemsData))
            {
                entry.Property(x => x.ItemsData).IsModified = true;
            }

            if (!reward.RoleData.Equals(data.RoleData))
            {
                entry.Property(x => x.RoleData).IsModified = true;
            }

            await context.SaveChangesAsync();

            return(true);
        }
Beispiel #3
0
        public async Task UpdateAsync(RiftRole role)
        {
            await using var context = new RiftContext();
            var entry = context.Entry(role);

            entry.Property(x => x.Name).IsModified   = true;
            entry.Property(x => x.RoleId).IsModified = true;

            await context.SaveChangesAsync();
        }
Beispiel #4
0
        public async Task SetBackgroundAsync(ulong userId, int backgroundId)
        {
            var dbUser = new RiftUser
            {
                UserId            = userId,
                ProfileBackground = backgroundId
            };

            await using var context = new RiftContext();
            context.Entry(dbUser).Property(x => x.ProfileBackground).IsModified = true;
            await context.SaveChangesAsync();
        }
Beispiel #5
0
        public async Task UpdateAsync(string name, DateTime lastUpdated)
        {
            var timer = await GetAsync(name);

            if (timer is null)
            {
                RiftBot.Log.Error($"Timer \"{name}\" does not exist!");
                return;
            }

            await using var context = new RiftContext();
            timer.LastInvoked       = lastUpdated;
            context.Entry(timer).Property(x => x.LastInvoked).IsModified = true;
            await context.SaveChangesAsync();
        }
Beispiel #6
0
        public async Task AddOrUpdateAsync(RiftGiveaway giveaway)
        {
            await using var context = new RiftContext();
            var dbGiveaway = await GetAsync(giveaway.Name);

            if (dbGiveaway is null)
            {
                await context.Giveaways.AddAsync(giveaway);
            }
            else
            {
                var entry = context.Entry(giveaway);

                if (!dbGiveaway.Description.Equals(giveaway.Description))
                {
                    entry.Property(x => x.Description).IsModified = true;
                }

                if (!dbGiveaway.WinnersAmount.Equals(giveaway.WinnersAmount))
                {
                    entry.Property(x => x.WinnersAmount).IsModified = true;
                }

                if (!dbGiveaway.RewardId.Equals(giveaway.RewardId))
                {
                    entry.Property(x => x.RewardId).IsModified = true;
                }

                if (!dbGiveaway.Duration.Equals(giveaway.Duration))
                {
                    entry.Property(x => x.Duration).IsModified = true;
                }

                if (!dbGiveaway.CreatedAt.Equals(giveaway.CreatedAt))
                {
                    entry.Property(x => x.CreatedAt).IsModified = true;
                }

                if (!dbGiveaway.CreatedBy.Equals(giveaway.CreatedBy))
                {
                    entry.Property(x => x.CreatedBy).IsModified = true;
                }
            }

            await context.SaveChangesAsync();
        }
Beispiel #7
0
        public async Task SetAsync(int id, string data)
        {
            await using var context = new RiftContext();
            var settings = new RiftSettings
            {
                Id   = id,
                Data = data
            };

            if (await context.Settings.AnyAsync(x => x.Id == id))
            {
                context.Entry(settings).Property(x => x.Data).IsModified = true;
            }
            else
            {
                await context.Settings.AddAsync(settings);
            }

            await context.SaveChangesAsync();
        }