public static async Task <Zone[]> GetZonesAsync(ZoneType zoneType) { // Returns all zones of the given type. // If the zone type is invalid (null or has an invalid id), returns all zones. return((await GetZonesAsync()) .Where(x => zoneType is null || zoneType.Id == ZoneType.NullZoneTypeId || x.ZoneTypeId == zoneType.Id) .ToArray()); }
public static bool ZoneTypeIsValid(ZoneType zoneType) { if (zoneType is null || zoneType.Id == ZoneType.NullZoneTypeId) { return(false); } return(true); }
public static async Task AddZoneTypeAsync(ZoneType type) { using (SQLiteCommand cmd = new SQLiteCommand("INSERT OR REPLACE INTO ZoneTypes(name, icon, color, description) VALUES($name, $icon, $color, $description)")) { cmd.Parameters.AddWithValue("$name", type.Name.ToLower()); cmd.Parameters.AddWithValue("$icon", type.Icon); cmd.Parameters.AddWithValue("$color", ColorTranslator.ToHtml(type.Color).ToLower()); cmd.Parameters.AddWithValue("$description", type.Description); await Database.ExecuteNonQuery(cmd); } }
public static ZoneType ZoneTypeFromDataRow(DataRow row) { ZoneType result = new ZoneType { Id = row.Field <long>("id"), Name = row.Field <string>("name"), Description = row.Field <string>("description"), Icon = row.Field <string>("icon") }; string color_string = row.Field <string>("color"); try { result.Color = ColorTranslator.FromHtml(color_string); } catch (Exception) { } return(result); }