示例#1
0
        static async Task <bool> EnsureExistsAsync(ulong userId)
        {
            if (!await DB.Users.EnsureExistsAsync(userId))
            {
                return(false);
            }

            await using var context = new RiftContext();
            if (await context.Cooldowns
                .AsQueryable()
                .AnyAsync(x => x.UserId == userId))
            {
                return(true);
            }

            try
            {
                var entry = new RiftCooldowns
                {
                    UserId = userId,
                };

                await context.Cooldowns.AddAsync(entry);

                await context.SaveChangesAsync();

                return(true);
            }
            catch (Exception ex)
            {
                RiftBot.Log.Error(ex, $"Failed to check {nameof(EnsureExistsAsync)} for user {userId.ToString()}.");
                return(false);
            }
        }
示例#2
0
        public async Task SetLastRoleStoreTimeAsync(ulong userId, DateTime time)
        {
            if (!await EnsureExistsAsync(userId))
            {
                throw new DatabaseException(nameof(SetLastRoleStoreTimeAsync));
            }

            var cd = new RiftCooldowns
            {
                UserId            = userId,
                LastRoleStoreTime = time,
            };

            await using var context = new RiftContext();
            context.Attach(cd).Property(x => x.LastRoleStoreTime).IsModified = true;
            await context.SaveChangesAsync();
        }