コード例 #1
0
        public void SaveData(IEnumerable <UserOnlineInfo> infos)
        {
            var dbContext = new UsersDbContext(_options);

            dbContext.UserOnlineInfos.AddRange(infos.Select(info => new UserOnlineInfoModel
            {
                OnlineInfo = info.OnlineInfo,
                DateTime   = info.DateTime,
                UserId     = info.Id
            }));
            dbContext.SaveChanges();
        }
コード例 #2
0
        public async Task SaveDataAsync(IEnumerable <UserOnlineInfo> infos)
        {
            var dbContext = new UsersDbContext(_options);
            await dbContext.UserOnlineInfos.AddRangeAsync(infos.Select(info => new UserOnlineInfoModel
            {
                OnlineInfo = info.OnlineInfo,
                DateTime   = info.DateTime,
                UserId     = info.Id
            }));

            await dbContext.SaveChangesAsync();
        }
コード例 #3
0
        public Task <UserOnlineData> ReadDataAsync(long id, DateTime from, DateTime to)
        {
            var dbContext = new UsersDbContext(_options);

            return(Task.FromResult(new UserOnlineData
            {
                Id = id,
                OnlineInfos = dbContext.UserOnlineInfos
                              .Where(info => info.UserId == id && info.DateTime >= from && info.DateTime <= to)
                              .Select(info => new DateOnline
                {
                    OnlineInfo = info.OnlineInfo,
                    Date = info.DateTime
                })
            }));
        }
コード例 #4
0
        public IEnumerable <User> GetUsers()
        {
            var dbContext = new UsersDbContext(_options);

            return(dbContext.Users.ToList());
        }
コード例 #5
0
        public async Task <IEnumerable <User> > GetUsersAsync()
        {
            var dbContext = new UsersDbContext(_options);

            return(await dbContext.Users.ToListAsync());
        }