public async Task AddZoneField(string zoneName, string fieldName, string fieldValue) { IZone zone = await this.GetZoneOrReplyAsync(zoneName); if (zone.IsValid()) { IZoneField existingField = zone.Fields .Where(field => field.Name.Equals(fieldName, StringComparison.OrdinalIgnoreCase)) .FirstOrDefault(); if (existingField != null) { existingField.Value = fieldValue; await Db.UpdateZoneAsync(zone); await ReplySuccessAsync($"The value for field {existingField.GetName().ToBold()} was successfully updated."); } else { IZoneField field = new ZoneField(fieldName, fieldValue); zone.Fields.Add(field); await Db.UpdateZoneAsync(zone); await ReplySuccessAsync($"Field {field.GetName().ToBold()} was successfully added to {zone.GetFullName().ToBold()}."); } } }
public static string GetName(this IZoneField field) { string result = field.Name.ToTitle(); result = Regex.Replace(result, @"\b(?:ph)\b", "pH", RegexOptions.IgnoreCase); return(result); }
public static string GetValue(this IZoneField field) { string result = field.Value.ToLowerInvariant(); result = Regex.Replace(result, @"°[cf]", m => m.Value.ToUpperInvariant(), RegexOptions.IgnoreCase); return(result); }
public async Task RemoveZoneField(string zoneName, string fieldName) { IZone zone = await this.GetZoneOrReplyAsync(zoneName); if (zone.IsValid()) { IZoneField existingField = zone.Fields .Where(field => field.Name.Equals(fieldName, StringComparison.OrdinalIgnoreCase)) .FirstOrDefault(); if (existingField != null) { zone.Fields.Remove(existingField); await Db.UpdateZoneAsync(zone); await ReplySuccessAsync($"The field {fieldName.ToTitle().ToBold()} was successfully removed from {zone.GetFullName().ToBold()}."); } else { await ReplyWarningAsync($"No field named {fieldName.ToTitle()} exists."); } } }