61 lines
1.4 KiB
C#
61 lines
1.4 KiB
C#
using Svrnty.GeoManagement.Abstractions.Abstractions;
|
|
|
|
namespace Svrnty.GeoManagement.Abstractions.Models;
|
|
|
|
public record GeoPoint(double Latitude, double Longitude);
|
|
|
|
public record Address(
|
|
string Line1,
|
|
string? Line2,
|
|
string City,
|
|
string Subdivision,
|
|
string PostalCode,
|
|
string Country,
|
|
GeoPoint? Location,
|
|
string? Note,
|
|
bool IsNormalized = false
|
|
) : IAddress
|
|
{
|
|
public string GetFormattedAddress(
|
|
FormattedAddressType formatType = FormattedAddressType.Full
|
|
)
|
|
{
|
|
return formatType switch
|
|
{
|
|
FormattedAddressType.Full => FormatFullOneLine(),
|
|
FormattedAddressType.Compact => FormatCompactOneLine(),
|
|
FormattedAddressType.MultiLine => FormatMultiLine(),
|
|
_ => FormatFullOneLine()
|
|
};
|
|
}
|
|
|
|
private string FormatFullOneLine()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(Line2))
|
|
{
|
|
return $"{Line1}, {City}, {Subdivision} {PostalCode}, {Country}";
|
|
}
|
|
|
|
return $"{Line2}, {Line1}, {City}, {Subdivision} {PostalCode}, {Country}";
|
|
}
|
|
|
|
private string FormatCompactOneLine()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(Line2))
|
|
{
|
|
return $"{Line1}, {City}, {Subdivision}";
|
|
}
|
|
|
|
return $"{Line2}, {Line1}, {City}, {Subdivision}";
|
|
}
|
|
|
|
private string FormatMultiLine()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(Line2))
|
|
{
|
|
return $"{Line1}\n{City}, {Subdivision} {PostalCode}\n{Country}";
|
|
}
|
|
|
|
return $"{Line2}\n{Line1}\n{City}, {Subdivision} {PostalCode}\n{Country}";
|
|
}
|
|
} |