| | | 1 | | using System.ComponentModel.DataAnnotations; |
| | | 2 | | using System.Data; |
| | | 3 | | using Common.Core.Classes; |
| | | 4 | | |
| | | 5 | | namespace Common.Core.Models; |
| | | 6 | | |
| | | 7 | | /// <summary>ISO-3166 Country details.</summary> |
| | | 8 | | public class ISOCountry : ModelData |
| | | 9 | | { |
| | | 10 | | #region Properties |
| | | 11 | | |
| | | 12 | | /// <inheritdoc/> |
| | 1 | 13 | | public override int Id { get; set; } |
| | | 14 | | |
| | | 15 | | /// <summary>2-digit ISO-3166 code.</summary> |
| | | 16 | | [Required] |
| | | 17 | | [MaxLength( 2 )] |
| | 56 | 18 | | public string Alpha2 { get; set; } = string.Empty; |
| | | 19 | | |
| | | 20 | | /// <summary>3-digit ISO-3166 code.</summary> |
| | | 21 | | [Required] |
| | | 22 | | [MaxLength( 3 )] |
| | 80 | 23 | | public string Alpha3 { get; set; } = string.Empty; |
| | | 24 | | |
| | | 25 | | /// <summary>Country name.</summary> |
| | | 26 | | [Required] |
| | | 27 | | [MaxLength( 50 )] |
| | 110 | 28 | | public string Name { get; set; } = string.Empty; |
| | | 29 | | |
| | | 30 | | #endregion |
| | | 31 | | |
| | | 32 | | #region Public Methods |
| | | 33 | | |
| | | 34 | | /// <summary>Builds an ISOCountry object from a database table row.</summary> |
| | | 35 | | /// <param name="row">Database row containing the ISOCountry columns.</param> |
| | | 36 | | /// <returns>ISOCountry object containing the database values.</returns> |
| | | 37 | | /// <remarks>This method assumes that the table column names are the same as the property names.</remarks> |
| | | 38 | | public static ISOCountry Read( DataRow row ) |
| | 1 | 39 | | { |
| | 1 | 40 | | return new ISOCountry() |
| | 1 | 41 | | { |
| | 1 | 42 | | Id = row.Field<int>( nameof( Id ) ), |
| | 1 | 43 | | Alpha2 = row.Field<string>( nameof( Alpha2 ) )!, |
| | 1 | 44 | | Alpha3 = row.Field<string>( nameof( Alpha3 ) )!, |
| | 1 | 45 | | Name = row.Field<string>( nameof( Name ) )! |
| | 1 | 46 | | }; |
| | 1 | 47 | | } |
| | | 48 | | |
| | | 49 | | #endregion |
| | | 50 | | } |