diff --git a/src/Contacts/Address.cs b/src/Contacts/Address.cs
index 40561da..477248e 100644
--- a/src/Contacts/Address.cs
+++ b/src/Contacts/Address.cs
@@ -16,6 +16,7 @@
namespace Talegen.Common.Models.Contacts
{
+ using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
@@ -67,6 +68,11 @@ public enum CommerceAddressTypes
///
public class Address
{
+ ///
+ /// Contains the formatted address text.
+ ///
+ private string formattedText;
+
///
/// Gets or sets the primary address street.
///
@@ -120,5 +126,74 @@ public class Address
///
/// true if primary; otherwise, false.
public bool Primary { get; set; }
+
+ ///
+ /// Converts to stringformatted.
+ ///
+ ///
+ public string ToStringFormatted()
+ {
+ if (string.IsNullOrWhiteSpace(this.formattedText))
+ {
+ // build formatted text out
+ if (!string.IsNullOrWhiteSpace(this.Street1))
+ {
+ this.formattedText = this.Street1 + Environment.NewLine;
+ }
+
+ if (!string.IsNullOrWhiteSpace(this.Street2))
+ {
+ this.formattedText += this.Street2 + Environment.NewLine;
+ }
+
+ string localityRegionPostal = string.Empty;
+
+ if (!string.IsNullOrWhiteSpace(this.City))
+ {
+ localityRegionPostal = this.City;
+ }
+
+ if (!string.IsNullOrWhiteSpace(this.RegionState))
+ {
+ localityRegionPostal += ", " + this.RegionState;
+ }
+
+ if (!string.IsNullOrWhiteSpace(this.PostalCode))
+ {
+ localityRegionPostal += " " + this.PostalCode;
+ }
+
+ this.formattedText += localityRegionPostal + Environment.NewLine;
+
+ if (!string.IsNullOrWhiteSpace(this.Country))
+ {
+ this.formattedText += this.Country + Environment.NewLine;
+ }
+ }
+
+ return this.formattedText;
+ }
+
+ ///
+ /// Gets or sets the formatted.
+ ///
+ ///
+ /// Gets or sets the Full mailing address, formatted for display or use on a mailing label.This field MAY contain multiple lines, separated by
+ /// newlines.Newlines can be represented either as a carriage return/line feed pair ("\r\n") or as a single line feed character("\n").
+ ///
+ public string Formatted
+ {
+ get
+ {
+ this.formattedText = this.ToStringFormatted();
+ return this.formattedText;
+ }
+
+ set
+ {
+ // set the formatted text.
+ this.formattedText = value;
+ }
+ }
}
}
\ No newline at end of file
diff --git a/src/Extensions/ContactExtensions.cs b/src/Extensions/ContactExtensions.cs
new file mode 100644
index 0000000..45ffdc8
--- /dev/null
+++ b/src/Extensions/ContactExtensions.cs
@@ -0,0 +1,75 @@
+/*
+ *
+ * (c) Copyright Talegen, LLC.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+*/
+
+namespace Talegen.Common.Models.Extensions
+{
+ using System;
+ using System.Security.Claims;
+ using Newtonsoft.Json;
+ using Talegen.Common.Models.Contacts;
+ using Talegen.Common.Models.Extensions.Internal;
+
+ ///
+ /// This extensions class contains extension methods to enhance the use of the Contact models.
+ ///
+ public static class ContactExtensions
+ {
+ ///
+ /// The JWT address claim type.
+ ///
+ public const string JwtAddressClaimType = "address";
+
+ ///
+ /// This extension method converts a JWT address claim to a model object.
+ ///
+ /// The claim containing the address information.
+ ///
+ /// Exception is thrown if is null.
+ public static Address ToAddress(this Claim claim)
+ {
+ Address result = null;
+
+ if (claim == null)
+ {
+ throw new ArgumentNullException(nameof(claim));
+ }
+
+ // is a JWT address claim
+ if (claim.Type == JwtAddressClaimType && !string.IsNullOrWhiteSpace(claim.Value))
+ {
+ JwtAddressModel jwtModel = JsonConvert.DeserializeObject(claim.Value);
+
+ if (jwtModel != null)
+ {
+ string[] streetLines = jwtModel.StreetAddress.Split('\n');
+
+ result = new Address
+ {
+ Street1 = streetLines != null ? streetLines[0].Replace("\r", string.Empty).Replace("\n", string.Empty) : string.Empty,
+ Street2 = streetLines != null && streetLines.Length > 1 ? streetLines[1].Replace("\r", string.Empty).Replace("\n", string.Empty) : string.Empty,
+ City = jwtModel.Locality,
+ Country = jwtModel.Country,
+ PostalCode = jwtModel.PostalCode,
+ RegionState = jwtModel.Region,
+ Formatted = jwtModel.Formatted
+ };
+ }
+ }
+
+ return result;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Extensions/Internal/JwtAddressModel.cs b/src/Extensions/Internal/JwtAddressModel.cs
new file mode 100644
index 0000000..e203b2c
--- /dev/null
+++ b/src/Extensions/Internal/JwtAddressModel.cs
@@ -0,0 +1,124 @@
+/*
+ *
+ * (c) Copyright Talegen, LLC.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+*/
+
+namespace Talegen.Common.Models.Extensions.Internal
+{
+ using System;
+ using Newtonsoft.Json;
+ using Talegen.Common.Models.Contacts;
+
+ ///
+ /// This class represents a JWT address model for use in translation to a model.
+ ///
+ internal class JwtAddressModel
+ {
+ private string formattedText;
+
+ ///
+ /// Gets or sets the formatted.
+ ///
+ ///
+ /// Gets or sets the Full mailing address, formatted for display or use on a mailing label.This field MAY contain multiple lines, separated by
+ /// newlines.Newlines can be represented either as a carriage return/line feed pair ("\r\n") or as a single line feed character("\n").
+ ///
+ [JsonProperty("formatted")]
+ public string Formatted
+ {
+ get
+ {
+ if (string.IsNullOrWhiteSpace(this.formattedText))
+ {
+ // build formatted text out
+ if (!string.IsNullOrWhiteSpace(this.StreetAddress))
+ {
+ this.formattedText = this.StreetAddress + Environment.NewLine;
+ }
+
+ string localityRegionPostal = string.Empty;
+
+ if (!string.IsNullOrWhiteSpace(this.Locality))
+ {
+ localityRegionPostal = this.Locality;
+ }
+
+ if (!string.IsNullOrWhiteSpace(this.Region))
+ {
+ localityRegionPostal += ", " + this.Region;
+ }
+
+ if (!string.IsNullOrWhiteSpace(this.PostalCode))
+ {
+ localityRegionPostal += " " + this.PostalCode;
+ }
+
+ this.formattedText += localityRegionPostal + Environment.NewLine;
+
+ if (!string.IsNullOrWhiteSpace(this.Country))
+ {
+ this.formattedText += this.Country + Environment.NewLine;
+ }
+ }
+
+ return this.formattedText;
+ }
+
+ set
+ {
+ // set the formatted text.
+ this.formattedText = value;
+ }
+ }
+
+ ///
+ /// Gets or sets the street address.
+ ///
+ ///
+ /// Full street address component, which MAY include house number, street name, Post Office Box, and multi-line extended street address information.This
+ /// field MAY contain multiple lines, separated by newlines.Newlines can be represented either as a carriage return/line feed pair ("\r\n") or as a
+ /// single line feed character("\n").
+ ///
+ [JsonProperty("street_address")]
+ public string StreetAddress { get; set; }
+
+ ///
+ /// Gets or sets the locality.
+ ///
+ /// The City or locality component.
+ [JsonProperty("locality")]
+ public string Locality { get; set; }
+
+ ///
+ /// Gets or sets the region.
+ ///
+ /// The State, province, prefecture, or region component.
+ [JsonProperty("region")]
+ public string Region { get; set; }
+
+ ///
+ /// Gets or sets the postal code.
+ ///
+ /// The Zip code or postal code component.
+ [JsonProperty("postal_code")]
+ public string PostalCode { get; set; }
+
+ ///
+ /// Gets or sets the country.
+ ///
+ /// The country name component.
+ [JsonProperty("country")]
+ public string Country { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/src/Talegen.Common.Models.csproj b/src/Talegen.Common.Models.csproj
index aceaeb0..7f78ecb 100644
--- a/src/Talegen.Common.Models.csproj
+++ b/src/Talegen.Common.Models.csproj
@@ -13,10 +13,10 @@
https://github.com/Talegen/Talegen.Common.Models
git
Models
- Fixed Paginated Query to use Common.Core SortDirection enumeration.
+ Added additional modelling and extensions for address models.
Assets\logo.ico
false
- 1.0.2.0
+ 1.0.3.0
en
diff --git a/src/Talegen.Common.Models.xml b/src/Talegen.Common.Models.xml
index 05ad95f..a9c3844 100644
--- a/src/Talegen.Common.Models.xml
+++ b/src/Talegen.Common.Models.xml
@@ -69,6 +69,11 @@
This class represents the basic postal address for an entity.
+
+
+ Contains the formatted address text.
+
+
Gets or sets the primary address street.
@@ -123,6 +128,21 @@
true if primary; otherwise, false.
+
+
+ Converts to stringformatted.
+
+
+
+
+
+ Gets or sets the formatted.
+
+
+ Gets or sets the Full mailing address, formatted for display or use on a mailing label.This field MAY contain multiple lines, separated by
+ newlines.Newlines can be represented either as a carriage return/line feed pair ("\r\n") or as a single line feed character("\n").
+
+
This class represents a contact record.
@@ -569,6 +589,72 @@
The type.
+
+
+ This extensions class contains extension methods to enhance the use of the Contact models.
+
+
+
+
+ The JWT address claim type.
+
+
+
+
+ This extension method converts a JWT address claim to a model object.
+
+ The claim containing the address information.
+
+ Exception is thrown if is null.
+
+
+
+ This class represents a JWT address model for use in translation to a model.
+
+
+
+
+ Gets or sets the formatted.
+
+
+ Gets or sets the Full mailing address, formatted for display or use on a mailing label.This field MAY contain multiple lines, separated by
+ newlines.Newlines can be represented either as a carriage return/line feed pair ("\r\n") or as a single line feed character("\n").
+
+
+
+
+ Gets or sets the street address.
+
+
+ Full street address component, which MAY include house number, street name, Post Office Box, and multi-line extended street address information.This
+ field MAY contain multiple lines, separated by newlines.Newlines can be represented either as a carriage return/line feed pair ("\r\n") or as a
+ single line feed character("\n").
+
+
+
+
+ Gets or sets the locality.
+
+ The City or locality component.
+
+
+
+ Gets or sets the region.
+
+ The State, province, prefecture, or region component.
+
+
+
+ Gets or sets the postal code.
+
+ The Zip code or postal code component.
+
+
+
+ Gets or sets the country.
+
+ The country name component.
+
Contains a minimal definition of a category.