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(); }
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(); }
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 }) })); }
public IEnumerable <User> GetUsers() { var dbContext = new UsersDbContext(_options); return(dbContext.Users.ToList()); }
public async Task <IEnumerable <User> > GetUsersAsync() { var dbContext = new UsersDbContext(_options); return(await dbContext.Users.ToListAsync()); }