/// <summary> /// Gets the (count) last activity elements of the system. /// For non-positive values of count, get everything /// </summary> public async Task<List<AccountingElement>> GetLastActivityAsync(string deviceID, int count = 10) { await CheckDeviceRights(deviceID, DeviceRights.FULL); MySqlDataReader reader; //Allow getting all activities by havin non-positive count-parameter if (count < 1) { reader = this.Query("SELECT * FROM gk_accounting ORDER BY gk_accounting.date DESC"); } else { reader = this.Query("SELECT * FROM gk_accounting ORDER BY gk_accounting.date DESC LIMIT 0," + count); } List<AccountingElement> list = new List<AccountingElement>(); while (await reader.ReadAsync()) { AccountingElement item = new AccountingElement(); try { item.comment = reader.GetString("comment"); } catch { } try { item.device = reader.GetString("device"); } catch { } item.date = reader.GetString("date"); item.ID = reader.GetInt32("ID"); item.price = reader.GetDouble("price"); item.user = reader.GetString("user"); list.Add(item); } reader.Close(); this.Close(); return list; }
private async Task<List<AccountingElement>> GetAccountingForUserSince(string user) #endif { var users = await this.GetAllUsersAsync(); if (!users.Any((x) => x.username.Equals(user))) throw new Exception("Invalid username"); MySqlDataReader reader = this.Query("SELECT * FROM gk_accounting WHERE gk_accounting.user='******'"); List<AccountingElement> acc = new List<AccountingElement>(); while (await reader.ReadAsync()) { AccountingElement ae = new AccountingElement(); try { ae.comment = reader.GetString("comment"); } catch { } try { ae.device = reader.GetString("device"); } catch { } ae.date = reader.GetString("date"); ae.ID = reader.GetInt32("ID"); ae.price = reader.GetDouble("price"); ae.user = reader.GetString("user"); acc.Add(ae); } reader.Close(); this.Close(); return acc; }