public async Task <bool> LoadAsync(DbContext db) { Uptime uptime = await db.SelectOneAsync <Uptime>(Table, (reader) => { return(new Uptime() { Id = reader.GetInt64("id"), Started = reader.GetDateTime("date_started"), Ended = reader.GetDateTimeNullable("date_ended"), LastLog = reader.GetString("last_log"), Reason = reader.GetString("reason") }); }, new Dictionary <string, object>() { { "id", Id } }); if (uptime == null) { return(false); } Id = uptime.Id; Started = uptime.Started; Ended = uptime.Ended; LastLog = uptime.LastLog; Reason = uptime.Reason; return(true); }
/// <summary> /// Gets the history of the uptime /// </summary> /// <param name="context"></param> /// <param name="count"></param> /// <returns></returns> public static async Task <List <Uptime> > GetHistoryAsync(DbContext context, int count = 10) { return(await context.ExecuteAsync <Uptime>("SELECT * FROM !uptime ORDER BY id DESC LIMIT " + count, (reader) => { Uptime uptime = new Uptime(); uptime.Id = reader.GetInt64("id"); uptime.Started = reader.GetDateTime("date_started"); uptime.Ended = reader.GetDateTimeNullable("date_ended"); uptime.Reason = reader.GetString("reason"); uptime.LastLog = reader.GetString("last_log"); return uptime; })); }