| | 1 | | using System.ComponentModel.DataAnnotations; |
| | 2 | | using System.Data; |
| | 3 | | using Common.Core.Classes; |
| | 4 | |
|
| | 5 | | namespace Common.Core.Models; |
| | 6 | |
|
| | 7 | | /// <summary>Post code details.</summary> |
| | 8 | | public class Postcode : ModelData |
| | 9 | | { |
| | 10 | | /// <inheritdoc/> |
| 1 | 11 | | public override int Id { get; set; } |
| | 12 | |
|
| | 13 | | /// <summary>Gets or sets the Postal Service code.</summary> |
| | 14 | | [Required] |
| | 15 | | [MaxLength( 10 )] |
| 48 | 16 | | public string Code { get; set; } = string.Empty; |
| | 17 | |
|
| | 18 | | /// <summary>Gets or sets the Province code.</summary> |
| | 19 | | [Required] |
| | 20 | | [MaxLength( 10 )] |
| 46 | 21 | | public string Province { get; set; } = string.Empty; |
| | 22 | |
|
| | 23 | | /// <summary>Gets or sets the County name.</summary> |
| | 24 | | [MaxLength( 50 )] |
| 23 | 25 | | public string? County { get; set; } |
| | 26 | |
|
| | 27 | | /// <summary>Gets or sets the City name.</summary> |
| | 28 | | [MaxLength( 50 )] |
| 23 | 29 | | public string? City { get; set; } |
| | 30 | |
|
| | 31 | | /// <summary>Builds a Postcode object from a database table row.</summary> |
| | 32 | | /// <param name="row">Database row containing the Postcode columns.</param> |
| | 33 | | /// <returns>Postcode object containing the database values.</returns> |
| | 34 | | /// <remarks>This method assumes that the table column names are the same as the property names.</remarks> |
| | 35 | | public static Postcode Read( DataRow row ) |
| 1 | 36 | | { |
| 1 | 37 | | return new Postcode() |
| 1 | 38 | | { |
| 1 | 39 | | Id = row.Field<int>( nameof( Id ) ), |
| 1 | 40 | | Code = row.Field<string>( nameof( Code ) )!, |
| 1 | 41 | | Province = row.Field<string>( nameof( Province ) )!, |
| 1 | 42 | | County = row.Field<string>( nameof( County ) )!, |
| 1 | 43 | | City = row.Field<string>( nameof( City ) )! |
| 1 | 44 | | }; |
| 1 | 45 | | } |
| | 46 | | } |