public static void ManageRecord(HtmlFormPost f, string xml) { int i; var exists = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); var count = int.Parse(f.Values["phonecnt"]); for (i = 1; i <= count; i++) { exists.Add(f.Values[$"phone_{i}"], f.Values[$"phoneKey_{i}"]); f.Remove($"phoneKey_{i}", $"phone_{i}", $"cntPhoneType_{i}", $"primaryPhone_{i}"); } i = 0; var xml2 = XDocument.Parse($"<r>{xml}</r>"); var typeOptions = f.Selects[$"cntPhoneType_0"].ToDictionary(x => x.Value, x => x.Key); foreach (var item in xml2.Descendants("n")) { i++; var(phone, phoneType, primaryIndicator) = (item.Attributes("pn").FirstOrDefault()?.Value, item.Attributes("pt").FirstOrDefault()?.Value, item.Attributes("pi").FirstOrDefault()?.Value == "Y"); if (exists.TryGetValue(phone, out var exist)) { exists.Remove(phone); f.Add($"phoneKey_{i}", "hidden", exist); } f.Add($"phone_{i}", "text", phone); f.Add($"cntPhoneType_{i}", "select", typeOptions.TryGetValue(phoneType, out var option) ? option : null); f.Add($"primaryPhone_{i}", "checkbox", "true", primaryIndicator); } f.Values["phonecnt"] = $"{i}"; }
public static void ManageRecord(HtmlFormPost f, string xml) { int i; var exists = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); var count = int.Parse(f.Values["addresscnt"]); for (i = 1; i <= count; i++) { exists.Add(f.Values[$"street_{i}"], f.Values[$"streetKey_{i}"]); f.Remove($"streetKey_{i}", $"street_{i}", $"city_{i}", $"state_province_{i}", $"postal_code_{i}", $"country_{i}", $"cntAddressType_{i}", $"primaryAddress_{i}"); } i = 0; var xml2 = XDocument.Parse($"<r>{xml}</r>"); var typeOptions = f.Selects[$"cntAddressType_0"].ToDictionary(x => x.Value, x => x.Key); foreach (var item in xml2.Descendants("a")) { i++; var(street, city, state_province, postal_code, country, addressType, primaryIndicator) = ( item.Attributes("sa").FirstOrDefault()?.Value, item.Attributes("c").FirstOrDefault()?.Value, item.Attributes("sp").FirstOrDefault()?.Value, item.Attributes("pc").FirstOrDefault()?.Value, item.Attributes("c").FirstOrDefault()?.Value, item.Attributes("at").FirstOrDefault()?.Value, item.Attributes("pi").FirstOrDefault()?.Value == "Y"); if (exists.TryGetValue(street, out var exist)) { exists.Remove(street); f.Add($"streetKey_{i}", "hidden", exist); } f.Add($"street_{i}", "text", street); f.Add($"city_{i}", "text", city); f.Add($"state_province_{i}", "text", state_province); f.Add($"postal_code_{i}", "text", postal_code); f.Add($"country_{i}", "text", country); f.Add($"cntAddressType_{i}", "select", typeOptions.TryGetValue(addressType, out var option) ? option : null); f.Add($"primaryAddress_{i}", "checkbox", "true", primaryIndicator); } f.Values["addresscnt"] = $"{i}"; }